Przeglądaj źródła

ZF-11440 Improve extensibility of Zend_App_Resource_Modules

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@24105 44c647ce-9c0f-0410-b52a-842ac1e357ba
freak 14 lat temu
rodzic
commit
1eb98b502a

+ 20 - 2
library/Zend/Application/Resource/Modules.php

@@ -62,6 +62,7 @@ class Zend_Application_Resource_Modules extends Zend_Application_Resource_Resour
      */
     public function init()
     {
+        $bootstraps = array();
         $bootstrap = $this->getBootstrap();
         $bootstrap->bootstrap('FrontController');
         $front = $bootstrap->getResource('FrontController');
@@ -102,13 +103,30 @@ class Zend_Application_Resource_Modules extends Zend_Application_Resource_Resour
                 // resource, don't re-execute.
                 continue;
             }
+            
+            $bootstraps[$module] = $bootstrapClass;
+        }
 
+        return $this->_bootstraps = $this->bootstrapBootstraps($bootstraps);
+    }
+    
+    /*
+     * Bootstraps the bootstraps found. Allows for easy extension.
+     * @param array $bootstraps Array containing the bootstraps to instantiate
+     */
+    protected function bootstrapBootstraps($bootstraps)
+    {
+        $bootstrap = $this->getBootstrap();
+        $out = array();
+        
+        foreach($bootstraps as $module => $bootstrapClass) {
             $moduleBootstrap = new $bootstrapClass($bootstrap);
             $moduleBootstrap->bootstrap();
             $this->_bootstraps[$module] = $moduleBootstrap;
+            $out[$module] = $moduleBootstrap;
         }
-
-        return $this->_bootstraps;
+        
+        return $out;
     }
 
     /**

+ 24 - 0
tests/Zend/Application/Resource/ModulesTest.php

@@ -169,6 +169,30 @@ class Zend_Application_Resource_ModulesTest extends PHPUnit_Framework_TestCase
         $this->assertArrayHasKey('foo',     (array)$bootstraps);
         $this->assertArrayHasKey('default', (array)$bootstraps);
     }
+    
+    public function testBootstrapBootstrapsIsOwnMethod()
+    {
+        require_once 'Zend/Application/Resource/Modules.php';
+
+        $this->bootstrap->registerPluginResource('Frontcontroller', array(
+            'moduleDirectory' => dirname(__FILE__) . '/../_files/modules',
+        ));
+        $resource = new ZendTest_Application_Resource_ModulesHalf(array());
+        $resource->setBootstrap($this->bootstrap);
+        $bootstraps = $resource->init();
+        $this->assertEquals(3, count((array)$bootstraps));
+    }
+}
+
+require_once 'Zend/Application/Resource/Modules.php';
+class ZendTest_Application_Resource_ModulesHalf
+    extends Zend_Application_Resource_Modules 
+{
+    protected function bootstrapBootstraps($bootstraps)
+    {
+        array_pop($bootstraps);
+        return parent::bootstrapBootstraps($bootstraps);
+    }
 }
 
 if (PHPUnit_MAIN_METHOD == 'Zend_Application_Resource_ModulesTest::main') {