StrikeIron.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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_Service
  17. * @subpackage StrikeIron
  18. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Loader
  24. */
  25. require_once 'Zend/Loader.php';
  26. /**
  27. * This class allows StrikeIron authentication credentials to be specified
  28. * in one place and provides a factory for returning instances of different
  29. * StrikeIron service classes.
  30. *
  31. * @category Zend
  32. * @package Zend_Service
  33. * @subpackage StrikeIron
  34. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  35. * @license http://framework.zend.com/license/new-bsd New BSD License
  36. */
  37. class Zend_Service_StrikeIron
  38. {
  39. /**
  40. * Options to pass to Zend_Service_StrikeIron_Base constructor
  41. * @param array
  42. */
  43. protected $_options;
  44. /**
  45. * Class constructor
  46. *
  47. * @param array $options Options to pass to Zend_Service_StrikeIron_Base constructor
  48. */
  49. public function __construct($options = array())
  50. {
  51. $this->_options = $options;
  52. }
  53. /**
  54. * Factory method to return a preconfigured Zend_Service_StrikeIron_*
  55. * instance.
  56. *
  57. * @param null|string $options Service options
  58. * @return object Zend_Service_StrikeIron_* instance
  59. * @throws Zend_Service_StrikeIron_Exception
  60. */
  61. public function getService($options = array())
  62. {
  63. $class = isset($options['class']) ? $options['class'] : 'Base';
  64. unset($options['class']);
  65. if (strpos($class, '_') === false) {
  66. $class = "Zend_Service_StrikeIron_{$class}";
  67. }
  68. try {
  69. @Zend_Loader::loadClass($class);
  70. if (!class_exists($class, false)) {
  71. throw new Exception('Class file not found');
  72. }
  73. } catch (Exception $e) {
  74. $msg = "Service '$class' could not be loaded: " . $e->getMessage();
  75. /**
  76. * @see Zend_Service_StrikeIron_Exception
  77. */
  78. require_once 'Zend/Service/StrikeIron/Exception.php';
  79. throw new Zend_Service_StrikeIron_Exception($msg, $e->getCode());
  80. }
  81. // instantiate and return the service
  82. $service = new $class(array_merge($this->_options, $options));
  83. return $service;
  84. }
  85. }