Browse Source

Merge pull request #8139 from ADmad/fix-nested-prefix-controller

Fix loading of controller with nested prefix.

This fixes a regression introduced in 3.2.0 and 3.1.9
Mark Story 10 years ago
parent
commit
f64f1b0071

+ 1 - 1
src/Routing/Filter/ControllerFactoryFilter.php

@@ -69,7 +69,7 @@ class ControllerFactoryFilter extends DispatcherFilter
             $controller = $request->params['controller'];
         }
         if (!empty($request->params['prefix'])) {
-            if (strpos('/', $request->params['prefix']) === false) {
+            if (strpos($request->params['prefix'], '/') === false) {
                 $namespace .= '/' . Inflector::camelize($request->params['prefix']);
             } else {
                 $prefixes = array_map(

+ 9 - 0
tests/TestCase/Routing/Filter/ControllerFactoryFilterTest.php

@@ -48,5 +48,14 @@ class ControllerFactoryFilterTest extends TestCase
             'TestApp\Controller\Admin\PostsController',
             get_class($event->data['controller'])
         );
+
+        $request->addParams(['prefix' => 'admin/sub', 'controller' => 'Posts', 'action' => 'index']);
+        $event = new Event(__CLASS__, $this, compact('request', 'response'));
+        $filter->beforeDispatch($event);
+
+        $this->assertEquals(
+            'TestApp\Controller\Admin\Sub\PostsController',
+            get_class($event->data['controller'])
+        );
     }
 }

+ 43 - 0
tests/test_app/TestApp/Controller/Admin/Sub/PostsController.php

@@ -0,0 +1,43 @@
+<?php
+/**
+ * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
+ * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
+ *
+ * Licensed under The MIT License
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
+ * @link          http://cakephp.org CakePHP(tm) Project
+ * @since         3.2.1
+ * @license       http://www.opensource.org/licenses/mit-license.php MIT License
+ */
+namespace TestApp\Controller\Admin\Sub;
+
+use Cake\Controller\Controller;
+
+/**
+ * Posts Controller class.
+ *
+ * For testing nested prefix routing / controller loading.
+ */
+class PostsController extends Controller
+{
+
+    /**
+     * index action
+     *
+     * @return void
+     */
+    public function index()
+    {
+    }
+
+    /**
+     * index action
+     *
+     * @return void
+     */
+    public function add()
+    {
+    }
+}