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 StorageService
  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 StorageService
  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_StorageService_Factory extends Zend_Cloud_AbstractFactory
  30. {
  31. const STORAGE_ADAPTER_KEY = 'storage_adapter';
  32. /**
  33. * @var string Interface which adapter must implement to be considered valid
  34. */
  35. protected static $_adapterInterface = 'Zend_Cloud_StorageService_Adapter';
  36. /**
  37. * Constructor
  38. *
  39. * @return void
  40. */
  41. private function __construct()
  42. {
  43. // private ctor - should not be used
  44. }
  45. /**
  46. * Retrieve StorageService adapter
  47. *
  48. * @param array $options
  49. * @return Zend_Cloud_StorageService_Adapter
  50. */
  51. public static function getAdapter($options = array())
  52. {
  53. $adapter = parent::_getAdapter(self::STORAGE_ADAPTER_KEY, $options);
  54. if (!$adapter) {
  55. require_once 'Zend/Cloud/StorageService/Exception.php';
  56. throw new Zend_Cloud_StorageService_Exception('Class must be specified using the \'' .
  57. self::STORAGE_ADAPTER_KEY . '\' key');
  58. } elseif (!$adapter instanceof self::$_adapterInterface) {
  59. require_once 'Zend/Cloud/StorageService/Exception.php';
  60. throw new Zend_Cloud_StorageService_Exception(
  61. 'Adapter must implement \'' . self::$_adapterInterface . '\''
  62. );
  63. }
  64. return $adapter;
  65. }
  66. }