Browse Source

ZF-6502: resolve module directory -> class name per dispatcher conventions

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@15510 44c647ce-9c0f-0410-b52a-842ac1e357ba
matthew 16 năm trước cách đây
mục cha
commit
20d80ff588

+ 16 - 1
library/Zend/Application/Resource/Modules.php

@@ -67,7 +67,7 @@ class Zend_Application_Resource_Modules extends Zend_Application_Resource_Resour
                 continue;
             }
 
-            $bootstrapClass = ucfirst($module) . '_Bootstrap';
+            $bootstrapClass = $this->_formatModuleName($module) . '_Bootstrap';
             if (!class_exists($bootstrapClass)) {
                 $bootstrapPath  = $front->getModuleDirectory($module) . '/Bootstrap.php';
                 if (file_exists($bootstrapPath)) {
@@ -97,4 +97,19 @@ class Zend_Application_Resource_Modules extends Zend_Application_Resource_Resour
     {
         return $this->_bootstraps;
     }
+
+    /**
+     * Format a module name to the module class prefix
+     * 
+     * @param  string $name 
+     * @return string
+     */
+    protected function _formatModuleName($name)
+    {
+        $name = strtolower($name);
+        $name = str_replace(array('-', '.'), ' ', $name);
+        $name = ucwords($name);
+        $name = str_replace(' ', '', ucwords($name));
+        return $name;
+    }
 }

+ 2 - 2
tests/Zend/Application/Resource/ModulesTest.php

@@ -136,7 +136,7 @@ class Zend_Application_Resource_ModulesTest extends PHPUnit_Framework_TestCase
         $resource->init();
         $bootstraps = $resource->getExecutedBootstraps();
         $test       = array_keys((array) $bootstraps);
-        $expected   = array('bar', 'foo');
+        $expected   = array('bar', 'foo-bar', 'foo');
         $this->assertEquals($expected, $test);
     }
 
@@ -151,7 +151,7 @@ class Zend_Application_Resource_ModulesTest extends PHPUnit_Framework_TestCase
         $resource->setBootstrap($this->bootstrap);
         $bootstraps = $resource->init();
         $test       = array_keys((array) $bootstraps);
-        $expected   = array('bar', 'foo');
+        $expected   = array('bar', 'foo-bar', 'foo');
         $this->assertEquals($expected, $test);
     }
 }