Skip to content

Commit

Permalink
Refactored to push module bootloading to initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Dec 5, 2008
1 parent 8d27bc6 commit c2ea0e1
Showing 1 changed file with 17 additions and 23 deletions.
40 changes: 17 additions & 23 deletions library/My/Plugin/Initialize.php
Expand Up @@ -13,11 +13,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
*
Expand Down Expand Up @@ -45,7 +40,8 @@ public function routeStartup(Zend_Controller_Request_Abstract $request)
->initLog()
->initCache()
->initDb()
->initView();
->initView()
->initModules();
}

/**
Expand All @@ -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;
}

/**
Expand Down

0 comments on commit c2ea0e1

Please sign in to comment.