Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Rename Router::setExtensions() to Router::parseExtensions().
Also renamed Route::setExtensions() to Route::parseExtensions() for consistency.
  • Loading branch information
ADmad committed Apr 28, 2014
1 parent 48df5ba commit 67faeaf
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/Routing/Route/Route.php
Expand Up @@ -128,7 +128,7 @@ public function __construct($template, $defaults = [], array $options = []) {
* @param array $extensions The extensions to set.
* @return void
*/
public function setExtensions(array $extensions) {
public function parseExtensions(array $extensions) {
$this->_extensions = $extensions;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Routing/RouteCollection.php
Expand Up @@ -265,9 +265,9 @@ public function setContext(Request $request) {
* @param array $extensions The extensions for routes to use.
* @return void
*/
public function setExtensions(array $extensions) {
public function parseExtensions(array $extensions) {
foreach ($this->_routes as $route) {
$route->setExtensions($extensions);
$route->parseExtensions($extensions);
}
}

Expand Down
9 changes: 4 additions & 5 deletions src/Routing/Router.php
Expand Up @@ -302,7 +302,7 @@ public static function resourceMap($resourceMap = null) {
* reverse routing lookups. If undefined a name will be generated for each
* connected route.
* - `_ext` is an array of filename extensions that will be parsed out of the url if present.
* See {@link Route::setExtensions()}.
* See {@link Route::parseExtensions()}.
*
* You can also add additional conditions for matching routes to the $defaults array.
* The following conditions can be used:
Expand Down Expand Up @@ -961,23 +961,22 @@ public static function normalize($url = '/') {
* current extensions
* @return array
*/
public static function setExtensions($extensions = null, $merge = true) {
public static function parseExtensions($extensions = null, $merge = true) {
if ($extensions === null) {
return static::$_validExtensions;
}
$extensions = (array)$extensions;
if ($merge) {
$extensions = array_merge(static::$_validExtensions, $extensions);
}
static::$_routes->setExtensions($extensions);
static::$_routes->parseExtensions($extensions);
return static::$_validExtensions = $extensions;
}

/**
* Get the list of extensions that can be parsed by Router.
*
* To initially set extensions use `Router::parseExtensions()`
* To add more see `setExtensions()`
* To add / update extensions use `Router::parseExtensions()`
*
* @return array Array of extensions Router is configured to parse.
*/
Expand Down
34 changes: 17 additions & 17 deletions tests/TestCase/Controller/Component/RequestHandlerComponentTest.php
Expand Up @@ -83,7 +83,7 @@ public function tearDown() {
if (!headers_sent()) {
header('Content-type: text/html'); //reset content type.
}
call_user_func_array('Cake\Routing\Router::setExtensions', [$this->_extensions, false]);
call_user_func_array('Cake\Routing\Router::parseExtensions', [$this->_extensions, false]);
}

/**
Expand Down Expand Up @@ -122,7 +122,7 @@ public function testInitializeCallback() {
public function testInitializeContentTypeSettingExt() {
$event = new Event('Controller.initialize', $this->Controller);
$_SERVER['HTTP_ACCEPT'] = 'application/json';
Router::setExtensions('json', false);
Router::parseExtensions('json', false);

$this->assertNull($this->RequestHandler->ext);

Expand All @@ -139,7 +139,7 @@ public function testInitializeContentTypeWithjQueryAccept() {
$_SERVER['HTTP_ACCEPT'] = 'application/json, application/javascript, */*; q=0.01';
$event = new Event('Controller.initialize', $this->Controller);
$this->assertNull($this->RequestHandler->ext);
Router::setExtensions('json', false);
Router::parseExtensions('json', false);

$this->RequestHandler->initialize($event);
$this->assertEquals('json', $this->RequestHandler->ext);
Expand All @@ -154,7 +154,7 @@ public function testInitializeContentTypeWithjQueryTextPlainAccept() {
$_SERVER['HTTP_ACCEPT'] = 'text/plain, */*; q=0.01';
$event = new Event('Controller.initialize', $this->Controller);
$this->assertNull($this->RequestHandler->ext);
Router::setExtensions('csv', false);
Router::parseExtensions('csv', false);

$this->RequestHandler->initialize($event);
$this->assertNull($this->RequestHandler->ext);
Expand All @@ -170,7 +170,7 @@ public function testInitializeContentTypeWithjQueryAcceptAndMultiplesExtensions(
$_SERVER['HTTP_ACCEPT'] = 'application/json, application/javascript, */*; q=0.01';
$event = new Event('Controller.initialize', $this->Controller);
$this->assertNull($this->RequestHandler->ext);
Router::setExtensions(['rss', 'json'], false);
Router::parseExtensions(['rss', 'json'], false);

$this->RequestHandler->initialize($event);
$this->assertEquals('json', $this->RequestHandler->ext);
Expand All @@ -185,7 +185,7 @@ public function testInitializeNoContentTypeWithSingleAccept() {
$_SERVER['HTTP_ACCEPT'] = 'application/json, text/html, */*; q=0.01';
$event = new Event('Controller.initialize', $this->Controller);
$this->assertNull($this->RequestHandler->ext);
Router::setExtensions('json', false);
Router::parseExtensions('json', false);

$this->RequestHandler->initialize($event);
$this->assertNull($this->RequestHandler->ext);
Expand All @@ -203,13 +203,13 @@ public function testInitializeNoContentTypeWithMultipleAcceptedTypes() {
$_SERVER['HTTP_ACCEPT'] = 'application/json, application/javascript, application/xml, */*; q=0.01';
$event = new Event('Controller.initialize', $this->Controller);
$this->assertNull($this->RequestHandler->ext);
Router::setExtensions(['xml', 'json'], false);
Router::parseExtensions(['xml', 'json'], false);

$this->RequestHandler->initialize($event);
$this->assertEquals('xml', $this->RequestHandler->ext);

$this->RequestHandler->ext = null;
Router::setExtensions(array('json', 'xml'), false);
Router::parseExtensions(array('json', 'xml'), false);

$this->RequestHandler->initialize($event);
$this->assertEquals('json', $this->RequestHandler->ext);
Expand All @@ -224,7 +224,7 @@ public function testInitializeContentTypeWithMultipleAcceptedTypes() {
$_SERVER['HTTP_ACCEPT'] = 'text/csv;q=1.0, application/json;q=0.8, application/xml;q=0.7';
$event = new Event('Controller.initialize', $this->Controller);
$this->assertNull($this->RequestHandler->ext);
Router::setExtensions(['xml', 'json'], false);
Router::parseExtensions(['xml', 'json'], false);

$this->RequestHandler->initialize($event);
$this->assertEquals('json', $this->RequestHandler->ext);
Expand All @@ -239,7 +239,7 @@ public function testInitializeAmbiguousAndroidAccepts() {
$_SERVER['HTTP_ACCEPT'] = 'application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5';
$event = new Event('Controller.initialize', $this->Controller);
$this->assertNull($this->RequestHandler->ext);
Router::setExtensions(['html', 'xml'], false);
Router::parseExtensions(['html', 'xml'], false);

$this->RequestHandler->initialize($event);
$this->assertNull($this->RequestHandler->ext);
Expand All @@ -252,7 +252,7 @@ public function testInitializeAmbiguousAndroidAccepts() {
*/
public function testInititalizeFirefoxHeaderNotXml() {
$_SERVER['HTTP_ACCEPT'] = 'text/html,application/xhtml+xml,application/xml;image/png,image/jpeg,image/*;q=0.9,*/*;q=0.8';
Router::setExtensions(['xml', 'json'], false);
Router::parseExtensions(['xml', 'json'], false);

$event = new Event('Controller.initialize', $this->Controller);
$this->RequestHandler->initialize($event);
Expand All @@ -268,7 +268,7 @@ public function testInitializeContentTypeAndExtensionMismatch() {
$event = new Event('Controller.initialize', $this->Controller);
$this->assertNull($this->RequestHandler->ext);
$extensions = Router::extensions();
Router::setExtensions('xml', false);
Router::parseExtensions('xml', false);

$this->Controller->request = $this->getMock('Cake\Network\Request', ['accepts']);
$this->Controller->request->expects($this->any())
Expand All @@ -278,7 +278,7 @@ public function testInitializeContentTypeAndExtensionMismatch() {
$this->RequestHandler->initialize($event);
$this->assertNull($this->RequestHandler->ext);

call_user_func_array(array('Cake\Routing\Router', 'setExtensions'), [$extensions, false]);
call_user_func_array(array('Cake\Routing\Router', 'parseExtensions'), [$extensions, false]);
}

/**
Expand Down Expand Up @@ -353,7 +353,7 @@ public function testAutoAjaxLayout() {
* test custom JsonView class is loaded and correct.
*/
public function testJsonViewLoaded() {
Router::setExtensions(['json', 'xml', 'ajax'], false);
Router::parseExtensions(['json', 'xml', 'ajax'], false);
$this->Controller->request->params['_ext'] = 'json';
$event = new Event('Controller.startup', $this->Controller);
$this->RequestHandler->initialize($event);
Expand All @@ -368,7 +368,7 @@ public function testJsonViewLoaded() {
* test custom XmlView class is loaded and correct.
*/
public function testXmlViewLoaded() {
Router::setExtensions(['json', 'xml', 'ajax'], false);
Router::parseExtensions(['json', 'xml', 'ajax'], false);
$this->Controller->request->params['_ext'] = 'xml';
$event = new Event('Controller.startup', $this->Controller);
$this->RequestHandler->initialize($event);
Expand All @@ -383,7 +383,7 @@ public function testXmlViewLoaded() {
* test custom AjaxView class is loaded and correct.
*/
public function testAjaxViewLoaded() {
Router::setExtensions(['json', 'xml', 'ajax'], false);
Router::parseExtensions(['json', 'xml', 'ajax'], false);
$this->Controller->request->params['_ext'] = 'ajax';
$event = new Event('Controller.startup', $this->Controller);
$this->RequestHandler->initialize($event);
Expand All @@ -397,7 +397,7 @@ public function testAjaxViewLoaded() {
* test configured extension but no view class set.
*/
public function testNoViewClassExtension() {
Router::setExtensions(['json', 'xml', 'ajax', 'csv'], false);
Router::parseExtensions(['json', 'xml', 'ajax', 'csv'], false);
$this->Controller->request->params['_ext'] = 'csv';
$event = new Event('Controller.startup', $this->Controller);
$this->RequestHandler->initialize($event);
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Routing/Route/RouteTest.php
Expand Up @@ -105,7 +105,7 @@ public function testRouteParsingWithExtensions() {
$result = $route->parse('/posts/index.pdf');
$this->assertFalse(isset($result['_ext']));

$route->setExtensions(array('pdf', 'json', 'xml'));
$route->parseExtensions(array('pdf', 'json', 'xml'));
$result = $route->parse('/posts/index.pdf');
$this->assertEquals('pdf', $result['_ext']);

Expand Down
22 changes: 11 additions & 11 deletions tests/TestCase/Routing/RouterTest.php
Expand Up @@ -292,7 +292,7 @@ public function testMapResourcesWithExtension() {
$this->assertEquals(['posts'], $resources);

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

$expected = array(
'plugin' => null,
Expand Down Expand Up @@ -839,7 +839,7 @@ public function testUrlGenerationWithPrefix() {
Router::connect('/reset/*', array('admin' => true, 'controller' => 'users', 'action' => 'reset'));
Router::connect('/tests', array('controller' => 'tests', 'action' => 'index'));
Router::connect('/admin/:controller/:action/*', array('prefix' => 'admin'));
Router::setExtensions('rss', false);
Router::parseExtensions('rss', false);

$request = new Request();
$request->addParams(array(
Expand Down Expand Up @@ -1630,7 +1630,7 @@ public function testPrefixRoutingAndPlugins() {
*/
public function testParseExtensions() {
Router::extensions();
Router::setExtensions('rss', false);
Router::parseExtensions('rss', false);
$this->assertContains('rss', Router::extensions());
}

Expand All @@ -1641,7 +1641,7 @@ public function testParseExtensions() {
*/
public function testSetExtensions() {
Router::extensions();
Router::setExtensions('rss', false);
Router::parseExtensions('rss', false);
$this->assertContains('rss', Router::extensions());

require CAKE . 'Config/routes.php';
Expand All @@ -1652,15 +1652,15 @@ public function testSetExtensions() {
$result = Router::parse('/posts.xml');
$this->assertFalse(isset($result['_ext']));

Router::setExtensions(array('xml'));
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::setExtensions(array('pdf'), false);
$result = Router::parseExtensions(array('pdf'), false);
$this->assertEquals(array('pdf'), $result);
}

Expand All @@ -1670,7 +1670,7 @@ public function testSetExtensions() {
* @return void
*/
public function testExtensionParsing() {
Router::setExtensions('rss', false);
Router::parseExtensions('rss', false);
require CAKE . 'Config/routes.php';

$result = Router::parse('/posts.rss');
Expand Down Expand Up @@ -1698,7 +1698,7 @@ public function testExtensionParsing() {
$this->assertEquals($expected, $result);

Router::reload();
Router::setExtensions(['rss', 'xml'], false);
Router::parseExtensions(['rss', 'xml'], false);
require CAKE . 'Config/routes.php';

$result = Router::parse('/posts.xml');
Expand Down Expand Up @@ -1740,7 +1740,7 @@ public function testExtensionParsing() {
$this->assertEquals($expected, $result);

Router::reload();
Router::setExtensions('rss', false);
Router::parseExtensions('rss', false);
Router::connect('/controller/action', array('controller' => 'controller', 'action' => 'action', '_ext' => 'rss'));
$result = Router::parse('/controller/action');
$expected = array(
Expand Down Expand Up @@ -2069,7 +2069,7 @@ public function testParsingWithTrailingPeriod() {
public function testParsingWithTrailingPeriodAndParseExtensions() {
Router::reload();
Router::connect('/:controller/:action/*');
Router::setExtensions('json', false);
Router::parseExtensions('json', false);

$result = Router::parse('/posts/view/something.');
$this->assertEquals('something.', $result['pass'][0], 'Period was chopped off %s');
Expand Down Expand Up @@ -2486,7 +2486,7 @@ public function testReverse() {
*/
public function testReverseWithExtension() {
Router::connect('/:controller/:action/*');
Router::setExtensions('json', false);
Router::parseExtensions('json', false);

$request = new Request('/posts/view/1.json');
$request->addParams(array(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_app/TestApp/Config/routes.php
Expand Up @@ -22,7 +22,7 @@

// Configure::write('Routing.prefixes', array());

Router::setExtensions('json');
Router::parseExtensions('json');
Router::connect('/some_alias', array('controller' => 'tests_apps', 'action' => 'some_method'));

Router::connect('/', ['controller' => 'pages', 'action' => 'display', 'home']);
Expand Down

0 comments on commit 67faeaf

Please sign in to comment.