Skip to content
Permalink
Browse files

Stop inflecting prefix.

Inflecting prefix causes issues with reverse routing as prefixes are
always connected as snake_case versions. Inflecting on parse/match
causes match errors.

The ControllerFactory changes are required to make namespaces match
correctly.
  • Loading branch information...
markstory committed Jul 6, 2014
1 parent d0f2362 commit 0dcfaff52e295cc9171353bc8f1044f05a844adb
@@ -392,20 +392,11 @@ public function invokeAction() {
* @return bool
*/
protected function _isPrivateAction(\ReflectionMethod $method, Request $request) {
$privateAction = (
return (
$method->name[0] === '_' ||
!$method->isPublic() ||
!in_array($method->name, $this->methods)
);
$prefixes = Router::prefixes();
if (!$privateAction && !empty($prefixes)) {
if (empty($request->params['prefix']) && strpos($request->params['action'], '_') > 0) {
list($prefix) = explode('_', $request->params['action']);
$privateAction = in_array($prefix, $prefixes);
}
}
return $privateAction;
}
/**
@@ -17,6 +17,7 @@
use Cake\Core\App;
use Cake\Event\Event;
use Cake\Routing\DispatcherFilter;
use Cake\Utility\Inflector;
/**
* A dispatcher filter that builds the controller to dispatch
@@ -64,7 +65,7 @@ protected function _getController($request, $response) {
$controller = $request->params['controller'];
}
if (!empty($request->params['prefix'])) {
$namespace .= '/' . $request->params['prefix'];
$namespace .= '/' . Inflector::camelize($request->params['prefix']);
}
$className = false;
if ($pluginPath . $controller) {
@@ -41,9 +41,6 @@ public function parse($url) {
if (!empty($params['plugin'])) {
$params['plugin'] = Inflector::camelize($params['plugin']);
}
if (!empty($params['prefix'])) {
$params['prefix'] = Inflector::camelize($params['prefix']);
}
return $params;
}
@@ -64,9 +61,6 @@ public function match(array $url, array $context = array()) {
if (!empty($url['plugin'])) {
$url['plugin'] = Inflector::underscore($url['plugin']);
}
if (!empty($url['prefix'])) {
$url['prefix'] = Inflector::underscore($url['prefix']);
}
return parent::match($url, $context);
}
@@ -52,14 +52,6 @@ class Router {
*/
protected static $_fullBaseUrl;
/**
* List of action prefixes used in connected routes.
* Includes admin prefix
*
* @var array
*/
protected static $_prefixes = [];
/**
* List of valid extensions to parse from a URL. If null, any extension is allowed.
*
@@ -417,18 +409,6 @@ public static function mapResources($controller, $options = []) {
}
}
/**
* Returns the list of prefixes used in connected routes
*
* @return array A list of prefixes used in connected routes
*/
public static function prefixes() {
if (empty(static::$_prefixes)) {
return (array)Configure::read('Routing.prefixes');
}
return static::$_prefixes;
}
/**
* Parses given URL string. Returns 'routing' parameters for that URL.
*
@@ -27,25 +27,22 @@ use Cake\Utility\Debugger;
Add a matching route to <?= APP_DIR . DS . 'Config' . DS . 'routes.php' ?></p>

<h3>Connected Routes</h3>
<table cellspacing="0" cellpadding="0">
<tr><th>Template</th><th>Defaults</th><th>Options</th></tr>
<?php
foreach (Router::routes() as $scope):
printf('<h4>Scope: %s</h4>', $scope->path());
echo '<table cellspacing="0" cellpadding="0">';
echo '<tr><th>Template</th><th>Defaults</th><th>Options</th></tr>';
foreach ($scope->routes() as $route):
echo '<tr>';
printf(
'<th width="25%%">%s</th><th>%s</th><th width="20%%">%s</th>',
$route->template,
Debugger::exportVar($route->defaults),
Debugger::exportVar($route->options)
);
echo '</tr>';
endforeach;
echo '</table>';
foreach (Router::routes() as $route):
echo '<tr>';
printf(
'<th width="25%%">%s</th><th>%s</th><th width="20%%">%s</th>',
$route->template,
Debugger::exportVar($route->defaults),
Debugger::exportVar($route->options)
);
echo '</tr>';
endforeach;
?>
</table>

<p class="notice">
<strong>Notice: </strong>
<?= sprintf('If you want to customize this error message, create %s', APP_DIR . DS . 'Template' . DS . 'Error' . DS . 'missing_route.ctp'); ?>
@@ -858,9 +858,13 @@ public function testNoRedirectOn404() {
*/
public function testAdminRoute() {
$event = new Event('Controller.startup', $this->Controller);
Router::reload();
Router::prefix('admin', function($routes) {
$routes->fallbacks();
});
Router::scope('/', function($routes) {
$routes->fallbacks();
});
$url = '/admin/auth_test/add';
$this->Auth->request->addParams(Router::parse($url));
@@ -912,9 +916,13 @@ public function testAjaxLogin() {
*/
public function testLoginActionRedirect() {
$event = new Event('Controller.startup', $this->Controller);
Router::reload();
Router::prefix('admin', function($routes) {
$routes->fallbacks();
});
Router::scope('/', function($routes) {
$routes->fallbacks();
});
$url = '/admin/auth_test/login';
$request = $this->Auth->request;
@@ -1491,30 +1491,6 @@ public function parseReverseSymmetryData() {
);
}
/**
* Test that Routing.prefixes are used when a Router instance is created
* or reset
*
* @return void
*/
public function testRoutingPrefixesSetting() {
$restore = Configure::read('Routing');
Configure::write('Routing.prefixes', array('admin', 'member', 'super_user'));
Router::reload();
$result = Router::prefixes();
$expected = array('admin', 'member', 'super_user');
$this->assertEquals($expected, $result);
Configure::write('Routing.prefixes', array('admin', 'member'));
Router::reload();
$result = Router::prefixes();
$expected = array('admin', 'member');
$this->assertEquals($expected, $result);
Configure::write('Routing', $restore);
}
/**
* testParseExtensions method
*
@@ -2011,7 +1987,6 @@ public function testUrlPatternOnAction() {
* @return void
*/
public function testParsingWithLiteralPrefixes() {
Configure::write('Routing.prefixes', []);
Router::reload();
$adminParams = array('prefix' => 'admin');
Router::connect('/admin/:controller', $adminParams);
@@ -2040,10 +2015,6 @@ public function testParsingWithLiteralPrefixes() {
$expected = '/base/admin/posts';
$this->assertEquals($expected, $result);
$result = Router::prefixes();
$expected = [];
$this->assertEquals($expected, $result);
Router::reload();
$prefixParams = array('prefix' => 'members');
@@ -2080,15 +2051,13 @@ public function testUrlWritingWithPrefixes() {
Router::connect('/company/:controller/:action/*', array('prefix' => 'company'));
Router::connect('/:action', array('controller' => 'users'));
/*
$result = Router::url(array('controller' => 'users', 'action' => 'login', 'prefix' => 'company'));
$expected = '/company/users/login';
$this->assertEquals($expected, $result);
$result = Router::url(array('controller' => 'users', 'action' => 'login', 'prefix' => 'company'));
$expected = '/company/users/login';
$this->assertEquals($expected, $result);
*/
$request = new Request();
Router::setRequestInfo(

0 comments on commit 0dcfaff

Please sign in to comment.
You can’t perform that action at this time.