|
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-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
20 * @version $Id: StrikeIron.php 20096 2010-01-06 02:05:09Z bkarwin $ |
|
21 */ |
|
22 |
|
23 |
|
24 /** |
|
25 * This class allows StrikeIron authentication credentials to be specified |
|
26 * in one place and provides a factory for returning instances of different |
|
27 * StrikeIron service classes. |
|
28 * |
|
29 * @category Zend |
|
30 * @package Zend_Service |
|
31 * @subpackage StrikeIron |
|
32 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
33 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
34 */ |
|
35 class Zend_Service_StrikeIron |
|
36 { |
|
37 /** |
|
38 * Options to pass to Zend_Service_StrikeIron_Base constructor |
|
39 * @param array |
|
40 */ |
|
41 protected $_options; |
|
42 |
|
43 /** |
|
44 * Class constructor |
|
45 * |
|
46 * @param array $options Options to pass to Zend_Service_StrikeIron_Base constructor |
|
47 */ |
|
48 public function __construct($options = array()) |
|
49 { |
|
50 $this->_options = $options; |
|
51 } |
|
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 |
|
66 if (strpos($class, '_') === false) { |
|
67 $class = "Zend_Service_StrikeIron_{$class}"; |
|
68 } |
|
69 |
|
70 try { |
|
71 if (!class_exists($class)) { |
|
72 require_once 'Zend/Loader.php'; |
|
73 @Zend_Loader::loadClass($class); |
|
74 } |
|
75 if (!class_exists($class, false)) { |
|
76 throw new Exception('Class file not found'); |
|
77 } |
|
78 } catch (Exception $e) { |
|
79 $msg = "Service '$class' could not be loaded: " . $e->getMessage(); |
|
80 /** |
|
81 * @see Zend_Service_StrikeIron_Exception |
|
82 */ |
|
83 require_once 'Zend/Service/StrikeIron/Exception.php'; |
|
84 throw new Zend_Service_StrikeIron_Exception($msg, $e->getCode(), $e); |
|
85 } |
|
86 |
|
87 // instantiate and return the service |
|
88 $service = new $class(array_merge($this->_options, $options)); |
|
89 return $service; |
|
90 } |
|
91 |
|
92 } |