Permalink
Browse files

Refactored to push module bootloading to initialization

  • Loading branch information...
1 parent 8d27bc6 commit c2ea0e1ced303323866066706ca4be966d932de5 @weierophinney committed Dec 5, 2008
Showing with 17 additions and 23 deletions.
  1. +17 −23 library/My/Plugin/Initialize.php
@@ -14,11 +14,6 @@
class My_Plugin_Initialize extends Zend_Controller_Plugin_Abstract
{
/**
- * @var array Array of module bootstrap classes that have been loaded
- */
- protected $_moduleBootstraps = array();
-
- /**
* Constructor
*
* @param string $basePath Base path of application
@@ -45,7 +40,8 @@ public function routeStartup(Zend_Controller_Request_Abstract $request)
->initLog()
->initCache()
->initDb()
- ->initView();
+ ->initView()
+ ->initModules();
}
/**
@@ -56,26 +52,24 @@ public function routeStartup(Zend_Controller_Request_Abstract $request)
* @param Zend_Controller_Request_Abstract $request
* @return void
*/
- public function preDispatch(Zend_Controller_Request_Abstract $request)
+ public function initModules()
{
- $module = $request->getModuleName();
- if (!empty($module)
- && ('default' != $module)
- && !array_key_exists($module, $this->_moduleBootstraps)
- ) {
- $bootstrapFile = $this->front->getModuleDirectory($module) . '/Bootstrap.php';
- if (@include $bootstrapFile) {
- $class = ucfirst($module) . '_Bootstrap';
- if (class_exists($class, false)) {
- $bootstrap = new $class;
- $bootstrap->setAppBootstrap($this);
- $bootstrap->bootstrap();
- $this->_moduleBootstraps[$module] = $bootstrap;
- }
- } else {
- $this->_moduleBootstraps[$module] = false;
+ $modules = $this->front->getControllerDirectory();
+ foreach ($modules as $module => $dir) {
+ if ('default' == $module) {
+ continue;
+ }
+ $bootstrapFile = dirname($dir) . '/Bootstrap.php';
+ $class = ucfirst($module) . '_Bootstrap';
+ if (Zend_Loader::loadFile('Bootstrap.php', dirname($dir))
+ && class_exists($class)
+ ) {
+ $bootstrap = new $class;
+ $bootstrap->setAppBootstrap($this);
+ $bootstrap->bootstrap();
}
}
+ return $this;
}
/**

0 comments on commit c2ea0e1

Please sign in to comment.