Skip to content

Commit

Permalink
Fix loading of controller with nested prefix.
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad authored and markstory committed Jan 31, 2016
1 parent 954c6fd commit ce29d38
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Routing/Filter/ControllerFactoryFilter.php
Expand Up @@ -69,7 +69,7 @@ protected function _getController($request, $response)
$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(
Expand Down
9 changes: 9 additions & 0 deletions tests/TestCase/Routing/Filter/ControllerFactoryFilterTest.php
Expand Up @@ -48,5 +48,14 @@ public function testBeforeDispatch()
'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 changes: 43 additions & 0 deletions 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()
{
}
}

0 comments on commit ce29d38

Please sign in to comment.