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.
16 * @package Zend_Application
17 * @subpackage Resource
18 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
20 * @version $Id: Modules.php 17730 2009-08-21 19:50:07Z matthew $
24 * Module bootstrapping resource
27 * @package Zend_Application
28 * @subpackage Resource
29 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
30 * @license http://framework.zend.com/license/new-bsd New BSD License
32 class Zend_Application_Resource_Modules
extends Zend_Application_Resource_ResourceAbstract
37 protected $_bootstraps;
42 * @param mixed $options
45 public function __construct($options = null)
47 $this->_bootstraps
= new ArrayObject(array(), ArrayObject
::ARRAY_AS_PROPS
);
48 parent
::__construct($options);
55 * @throws Zend_Application_Resource_Exception When bootstrap class was not found
57 public function init()
59 $bootstrap = $this->getBootstrap();
60 $bootstrap->bootstrap('FrontController');
61 $front = $bootstrap->getResource('FrontController');
63 $modules = $front->getControllerDirectory();
64 $default = $front->getDefaultModule();
65 $curBootstrapClass = get_class($bootstrap);
66 foreach ($modules as $module => $moduleDirectory) {
67 $bootstrapClass = $this->_formatModuleName($module) . '_Bootstrap';
68 if (!class_exists($bootstrapClass, false)) {
69 $bootstrapPath = dirname($moduleDirectory) . '/Bootstrap.php';
70 if (file_exists($bootstrapPath)) {
71 $eMsgTpl = 'Bootstrap file found for module "%s" but bootstrap class "%s" not found';
72 include_once $bootstrapPath;
73 if (($default != $module)
74 && !class_exists($bootstrapClass, false)
76 throw new Zend_Application_Resource_Exception(sprintf(
77 $eMsgTpl, $module, $bootstrapClass
79 } elseif ($default == $module) {
80 if (!class_exists($bootstrapClass, false)) {
81 $bootstrapClass = 'Bootstrap';
82 if (!class_exists($bootstrapClass, false)) {
83 throw new Zend_Application_Resource_Exception(sprintf(
84 $eMsgTpl, $module, $bootstrapClass
94 if ($bootstrapClass == $curBootstrapClass) {
95 // If the found bootstrap class matches the one calling this
96 // resource, don't re-execute.
100 $moduleBootstrap = new $bootstrapClass($bootstrap);
101 $moduleBootstrap->bootstrap();
102 $this->_bootstraps
[$module] = $moduleBootstrap;
105 return $this->_bootstraps
;
109 * Get bootstraps that have been run
111 * @return ArrayObject
113 public function getExecutedBootstraps()
115 return $this->_bootstraps
;
119 * Format a module name to the module class prefix
121 * @param string $name
124 protected function _formatModuleName($name)
126 $name = strtolower($name);
127 $name = str_replace(array('-', '.'), ' ', $name);
128 $name = ucwords($name);
129 $name = str_replace(' ', '', $name);