Factory.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * @category Zend
  4. * @package Zend_Cloud
  5. * @subpackage Infrastructure
  6. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  7. * @license http://framework.zend.com/license/new-bsd New BSD License
  8. */
  9. require_once 'Zend/Cloud/AbstractFactory.php';
  10. /**
  11. * Factory for infrastructure adapters
  12. *
  13. * @package Zend_Cloud
  14. * @subpackage Infrastructure
  15. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  16. * @license http://framework.zend.com/license/new-bsd New BSD License
  17. */
  18. class Zend_Cloud_Infrastructure_Factory extends Zend_Cloud_AbstractFactory
  19. {
  20. const INFRASTRUCTURE_ADAPTER_KEY = 'infrastructure_adapter';
  21. /**
  22. * @var string Interface which adapter must implement to be considered valid
  23. */
  24. protected static $_adapterInterface = 'Zend_Cloud_Infrastructure_Adapter';
  25. /**
  26. * Constructor
  27. *
  28. * Private ctor - should not be used
  29. *
  30. * @return void
  31. */
  32. private function __construct()
  33. {
  34. }
  35. /**
  36. * Retrieve an adapter instance
  37. *
  38. * @param array $options
  39. * @return void
  40. */
  41. public static function getAdapter($options = array())
  42. {
  43. $adapter = parent::_getAdapter(self::INFRASTRUCTURE_ADAPTER_KEY, $options);
  44. if (!$adapter) {
  45. require_once 'Zend/Cloud/Infrastructure/Exception.php';
  46. throw new Zend_Cloud_Infrastructure_Exception(sprintf(
  47. 'Class must be specified using the "%s" key',
  48. self::INFRASTRUCTURE_ADAPTER_KEY
  49. ));
  50. } elseif (!$adapter instanceof self::$_adapterInterface) {
  51. require_once 'Zend/Cloud/Infrastructure/Exception.php';
  52. throw new Zend_Cloud_Infrastructure_Exception(sprintf(
  53. 'Adapter must implement "%s"', self::$_adapterInterface
  54. ));
  55. }
  56. return $adapter;
  57. }
  58. }