File indexing completed on 2025-01-26 05:25:31
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Service 0017 * @subpackage StrikeIron 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 * @version $Id$ 0021 */ 0022 0023 0024 /** 0025 * This class allows StrikeIron authentication credentials to be specified 0026 * in one place and provides a factory for returning instances of different 0027 * StrikeIron service classes. 0028 * 0029 * @category Zend 0030 * @package Zend_Service 0031 * @subpackage StrikeIron 0032 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0033 * @license http://framework.zend.com/license/new-bsd New BSD License 0034 */ 0035 class Zend_Service_StrikeIron 0036 { 0037 /** 0038 * Options to pass to Zend_Service_StrikeIron_Base constructor 0039 * @param array 0040 */ 0041 protected $_options; 0042 0043 /** 0044 * Class constructor 0045 * 0046 * @param array $options Options to pass to Zend_Service_StrikeIron_Base constructor 0047 */ 0048 public function __construct($options = array()) 0049 { 0050 $this->_options = $options; 0051 } 0052 0053 /** 0054 * Factory method to return a preconfigured Zend_Service_StrikeIron_* 0055 * instance. 0056 * 0057 * @param null|string $options Service options 0058 * @return object Zend_Service_StrikeIron_* instance 0059 * @throws Zend_Service_StrikeIron_Exception 0060 */ 0061 public function getService($options = array()) 0062 { 0063 $class = isset($options['class']) ? $options['class'] : 'Base'; 0064 unset($options['class']); 0065 0066 if (strpos($class, '_') === false) { 0067 $class = "Zend_Service_StrikeIron_{$class}"; 0068 } 0069 0070 try { 0071 if (!class_exists($class)) { 0072 // require_once 'Zend/Loader.php'; 0073 @Zend_Loader::loadClass($class); 0074 } 0075 if (!class_exists($class, false)) { 0076 throw new Exception('Class file not found'); 0077 } 0078 } catch (Exception $e) { 0079 $msg = "Service '$class' could not be loaded: " . $e->getMessage(); 0080 /** 0081 * @see Zend_Service_StrikeIron_Exception 0082 */ 0083 // require_once 'Zend/Service/StrikeIron/Exception.php'; 0084 throw new Zend_Service_StrikeIron_Exception($msg, $e->getCode(), $e); 0085 } 0086 0087 // instantiate and return the service 0088 $service = new $class(array_merge($this->_options, $options)); 0089 return $service; 0090 } 0091 0092 }