Skip to content

Commit

Permalink
Router::parseExtensions() only works at the top of the routes.
Browse files Browse the repository at this point in the history
The global methods still mostly work like before, but with limitations.
Router::parseExtensions() now should only be used at the top of the
routes file. After that, extensions() should be set on the individual
scopes.
  • Loading branch information
markstory committed Jun 27, 2014
1 parent 42fb1a4 commit e05a967
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
7 changes: 5 additions & 2 deletions src/Routing/Router.php
Expand Up @@ -1085,10 +1085,14 @@ public static function parseNamedParams(Request $request, $options = []) {
* If you have no parameters, this argument can be a callable.
* @param callable $callback The callback to invoke with the scoped collection.
* @throws \InvalidArgumentException When an invalid callable is provided.
* @return \Cake\Routing\ScopedRouteCollection The scoped collection that
* @return null|\Cake\Routing\ScopedRouteCollection The scoped collection that
* was created/used.
*/
public static function scope($path, $params = [], $callback = null) {
if ($params === [] && $callback === null && isset(static::$_pathScopes[$path])) {
return static::$_pathScopes[$path];
}

if ($callback === null) {
$callback = $params;
$params = [];
Expand All @@ -1107,7 +1111,6 @@ public static function scope($path, $params = [], $callback = null) {
static::$_pathScopes[$path]->merge($collection);
}
static::$_named += $collection->named();
return static::$_pathScopes[$path];
}

/**
Expand Down
18 changes: 4 additions & 14 deletions tests/TestCase/Routing/RouterTest.php
Expand Up @@ -286,11 +286,12 @@ public function testMapResourcesWithPrefix() {
* @return void
*/
public function testMapResourcesWithExtension() {
Router::parseExtensions(['json', 'xml'], false);

$resources = Router::mapResources('Posts', ['_ext' => 'json']);
$this->assertEquals(['posts'], $resources);

$_SERVER['REQUEST_METHOD'] = 'GET';
Router::parseExtensions(['json', 'xml'], false);

$expected = array(
'plugin' => null,
Expand All @@ -317,15 +318,14 @@ public function testMapResourcesWithExtension() {
*/
public function testMapResourcesConnectOptions() {
Plugin::load('TestPlugin');
$collection = new RouteCollection();
Router::setRouteCollection($collection);
Router::mapResources('Posts', array(
'connectOptions' => array(
'routeClass' => 'TestPlugin.TestRoute',
'foo' => '^(bar)$',
),
));
$route = $collection->get(0);
$routes = Router::scope('/');
$route = $routes->routes()[0];
$this->assertInstanceOf('TestPlugin\Routing\Route\TestRoute', $route);
$this->assertEquals('^(bar)$', $route->options['foo']);
}
Expand Down Expand Up @@ -1632,7 +1632,6 @@ public function testParseExtensions() {
* @return void
*/
public function testSetExtensions() {
Router::extensions();
Router::parseExtensions('rss', false);
$this->assertContains('rss', Router::extensions());

Expand All @@ -1645,15 +1644,6 @@ public function testSetExtensions() {
$this->assertFalse(isset($result['_ext']));

Router::parseExtensions(array('xml'));
$result = Router::extensions();
$this->assertContains('rss', $result);
$this->assertContains('xml', $result);

$result = Router::parse('/posts.xml');
$this->assertEquals('xml', $result['_ext']);

$result = Router::parseExtensions(array('pdf'), false);
$this->assertEquals(array('pdf'), $result);
}

/**
Expand Down

0 comments on commit e05a967

Please sign in to comment.