|
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_Application |
|
17 * @subpackage Module |
|
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
19 * @version $Id: Bootstrap.php 20096 2010-01-06 02:05:09Z bkarwin $ |
|
20 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
21 */ |
|
22 |
|
23 /** |
|
24 * @see Zend_Application_Bootstrap_Bootstrap |
|
25 */ |
|
26 require_once 'Zend/Application/Bootstrap/Bootstrap.php'; |
|
27 |
|
28 /** |
|
29 * Base bootstrap class for modules |
|
30 * |
|
31 * @uses Zend_Loader_Autoloader_Resource |
|
32 * @uses Zend_Application_Bootstrap_Bootstrap |
|
33 * @category Zend |
|
34 * @package Zend_Application |
|
35 * @subpackage Module |
|
36 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
37 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
38 */ |
|
39 abstract class Zend_Application_Module_Bootstrap |
|
40 extends Zend_Application_Bootstrap_Bootstrap |
|
41 { |
|
42 /** |
|
43 * Set this explicitly to reduce impact of determining module name |
|
44 * @var string |
|
45 */ |
|
46 protected $_moduleName; |
|
47 |
|
48 /** |
|
49 * Constructor |
|
50 * |
|
51 * @param Zend_Application|Zend_Application_Bootstrap_Bootstrapper $application |
|
52 * @return void |
|
53 */ |
|
54 public function __construct($application) |
|
55 { |
|
56 $this->setApplication($application); |
|
57 |
|
58 // Use same plugin loader as parent bootstrap |
|
59 if ($application instanceof Zend_Application_Bootstrap_ResourceBootstrapper) { |
|
60 $this->setPluginLoader($application->getPluginLoader()); |
|
61 } |
|
62 |
|
63 $key = strtolower($this->getModuleName()); |
|
64 if ($application->hasOption($key)) { |
|
65 // Don't run via setOptions() to prevent duplicate initialization |
|
66 $this->setOptions($application->getOption($key)); |
|
67 } |
|
68 |
|
69 if ($application->hasOption('resourceloader')) { |
|
70 $this->setOptions(array( |
|
71 'resourceloader' => $application->getOption('resourceloader') |
|
72 )); |
|
73 } |
|
74 $this->initResourceLoader(); |
|
75 |
|
76 // ZF-6545: ensure front controller resource is loaded |
|
77 if (!$this->hasPluginResource('FrontController')) { |
|
78 $this->registerPluginResource('FrontController'); |
|
79 } |
|
80 |
|
81 // ZF-6545: prevent recursive registration of modules |
|
82 if ($this->hasPluginResource('modules')) { |
|
83 $this->unregisterPluginResource('modules'); |
|
84 } |
|
85 } |
|
86 |
|
87 /** |
|
88 * Ensure resource loader is loaded |
|
89 * |
|
90 * @return void |
|
91 */ |
|
92 public function initResourceLoader() |
|
93 { |
|
94 $this->getResourceLoader(); |
|
95 } |
|
96 |
|
97 /** |
|
98 * Get default application namespace |
|
99 * |
|
100 * Proxies to {@link getModuleName()}, and returns the current module |
|
101 * name |
|
102 * |
|
103 * @return string |
|
104 */ |
|
105 public function getAppNamespace() |
|
106 { |
|
107 return $this->getModuleName(); |
|
108 } |
|
109 |
|
110 /** |
|
111 * Retrieve module name |
|
112 * |
|
113 * @return string |
|
114 */ |
|
115 public function getModuleName() |
|
116 { |
|
117 if (empty($this->_moduleName)) { |
|
118 $class = get_class($this); |
|
119 if (preg_match('/^([a-z][a-z0-9]*)_/i', $class, $matches)) { |
|
120 $prefix = $matches[1]; |
|
121 } else { |
|
122 $prefix = $class; |
|
123 } |
|
124 $this->_moduleName = $prefix; |
|
125 } |
|
126 return $this->_moduleName; |
|
127 } |
|
128 } |