Browse Source

ZF-8222: format class name for class checks

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

+ 7 - 1
library/Zend/Controller/Dispatcher/Standard.php

@@ -206,7 +206,13 @@ class Zend_Controller_Dispatcher_Standard extends Zend_Controller_Dispatcher_Abs
             return false;
         }
 
-        if (class_exists($className, false)) {
+        $finalClass  = $className;
+        if (($this->_defaultModule != $this->_curModule)
+            || $this->getParam('prefixDefaultModule'))
+        {
+            $finalClass = $this->formatClassName($this->_curModule, $className);
+        }
+        if (class_exists($finalClass, false)) {
             return true;
         }
 

+ 24 - 0
tests/Zend/Controller/Dispatcher/StandardTest.php

@@ -136,6 +136,30 @@ class Zend_Controller_Dispatcher_StandardTest extends PHPUnit_Framework_TestCase
         $this->assertFalse($this->_dispatcher->isDispatchable($request), var_export($this->_dispatcher->getControllerDirectory(), 1));
     }
 
+    /**
+     * @group ZF-8222
+     */
+    public function testIsDispatchableManuallyIncludedController()
+    {
+        require_once dirname(__FILE__) . '/../_files/ManuallyIncludedControllers.php';
+        $request = new Zend_Controller_Request_Http();
+
+
+        $this->_dispatcher->setParam('prefixDefaultModule', true);
+
+        $request->setControllerName('included');
+        $this->assertFalse($this->_dispatcher->isDispatchable($request));
+
+        $request->setControllerName('included-prefix');
+        $this->assertTrue($this->_dispatcher->isDispatchable($request));
+
+        $this->_dispatcher->setParam('prefixDefaultModule', false);
+
+        $request->setModuleName('admin');
+        $request->setControllerName('included-admin');
+        $this->assertTrue($this->_dispatcher->isDispatchable($request));
+    }
+
     public function testSetGetResponse()
     {
         $response = new Zend_Controller_Response_Cli();

+ 57 - 0
tests/Zend/Controller/_files/ManuallyIncludedControllers.php

@@ -0,0 +1,57 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Controller
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id: ManuallyIncludedControllers.php $
+ */
+
+require_once 'PHPUnit/Util/Filter.php';
+PHPUnit_Util_Filter::addFileToFilter(__FILE__);
+
+require_once 'Zend/Controller/Action.php';
+
+/**
+ * Mock file for testbed
+ *
+ * @category   Zend
+ * @package    Zend_Controller
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class IncludedController extends Zend_Controller_Action
+{
+    public function indexAction()
+    {
+    }
+}
+
+class Default_IncludedPrefixController extends Zend_Controller_Action
+{
+    public function indexAction()
+    {
+    }
+}
+
+class Admin_IncludedAdminController extends Zend_Controller_Action
+{
+    public function indexAction()
+    {
+    }
+}
+