Factory.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Cloud
  17. * @subpackage QueueService
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. require_once 'Zend/Cloud/AbstractFactory.php';
  22. /**
  23. * @category Zend
  24. * @package Zend_Cloud
  25. * @subpackage QueueService
  26. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  27. * @license http://framework.zend.com/license/new-bsd New BSD License
  28. */
  29. class Zend_Cloud_QueueService_Factory extends Zend_Cloud_AbstractFactory
  30. {
  31. const QUEUE_ADAPTER_KEY = 'queue_adapter';
  32. /**
  33. * @var string Interface which adapter must implement to be considered valid
  34. */
  35. protected static $_adapterInterface = 'Zend_Cloud_QueueService_Adapter';
  36. /**
  37. * Constructor
  38. */
  39. private function __construct()
  40. {
  41. // private ctor - should not be used
  42. }
  43. /**
  44. * Retrieve QueueService adapter
  45. *
  46. * @param array $options
  47. * @return null|Zend_Cloud_DocumentService_Adapter|Zend_Cloud_QueueService_Adapter|Zend_Cloud_StorageService_Adapter
  48. * @throws Zend_Cloud_QueueService_Exception
  49. */
  50. public static function getAdapter($options = array())
  51. {
  52. $adapter = parent::_getAdapter(self::QUEUE_ADAPTER_KEY, $options);
  53. if (!$adapter) {
  54. require_once 'Zend/Cloud/QueueService/Exception.php';
  55. throw new Zend_Cloud_QueueService_Exception('Class must be specified using the \'' .
  56. self::QUEUE_ADAPTER_KEY . '\' key');
  57. } elseif (!$adapter instanceof self::$_adapterInterface) {
  58. require_once 'Zend/Cloud/QueueService/Exception.php';
  59. throw new Zend_Cloud_QueueService_Exception(
  60. 'Adapter must implement \'' . self::$_adapterInterface . '\''
  61. );
  62. }
  63. return $adapter;
  64. }
  65. }