2
0

StrikeIron.php 2.8 KB

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