Skip to content

Commit

Permalink
Revert array $options argument to boolean $merge in routing classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Sep 7, 2014
1 parent ce3042f commit f52bf79
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 38 deletions.
10 changes: 4 additions & 6 deletions src/Routing/RouteCollection.php
Expand Up @@ -279,19 +279,17 @@ public function named() {
*
* @param null|string|array $extensions Either the list of extensions to set,
* or null to get.
* @param array $options Valid options:
* - `merge` - Default true will merge extensions. Set to false to override
* current extensions
* @param bool $merge Whether to merge with or override existing extensions.
* Defaults to `true`.
* @return array The valid extensions.
*/
public function extensions($extensions = null, array $options = []) {
public function extensions($extensions = null, $merge = true) {
if ($extensions === null) {
return $this->_extensions;
}

$options += ['merge' => true];
$extensions = (array)$extensions;
if ($options['merge']) {
if ($merge) {
$extensions = array_unique(array_merge(
$this->_extensions,
$extensions
Expand Down
12 changes: 5 additions & 7 deletions src/Routing/Router.php
Expand Up @@ -722,7 +722,7 @@ public static function parseExtensions($extensions = null, $merge = true) {
'Router::parseExtensions() is deprecated should use Router::extensions() instead.',
E_USER_DEPRECATED
);
return static::extensions($extensions, compact('merge'));
return static::extensions($extensions, $merge);
}

/**
Expand All @@ -739,12 +739,11 @@ public static function parseExtensions($extensions = null, $merge = true) {
* If called without any parameters it will return current list of set extensions.
*
* @param array|string $extensions List of extensions to be added.
* @param array $options Valid options:
* - `merge` - Default true will merge extensions. Set to false to override
* current extensions
* @param bool $merge Whether to merge with or override existing extensions.
* Defaults to `true`.
* @return array Array of extensions Router is configured to parse.
*/
public static function extensions($extensions = null, array $options = []) {
public static function extensions($extensions = null, $merge = true) {
$collection = static::$_collection;
if ($extensions === null) {
if (!static::$initialized) {
Expand All @@ -753,8 +752,7 @@ public static function extensions($extensions = null, array $options = []) {
return $collection->extensions();
}

$options += ['merge' => true];
return $collection->extensions($extensions, $options);
return $collection->extensions($extensions, $merge);
}

/**
Expand Down
32 changes: 16 additions & 16 deletions tests/TestCase/Controller/Component/RequestHandlerComponentTest.php
Expand Up @@ -125,7 +125,7 @@ public function testInitializeCallback() {
public function testInitializeContentTypeSettingExt() {
$event = new Event('Controller.initialize', $this->Controller);
$_SERVER['HTTP_ACCEPT'] = 'application/json';
Router::extensions('json', ['merge' => false]);
Router::extensions('json', false);

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

Expand All @@ -143,7 +143,7 @@ public function testInitializeContentTypeWithjQueryAccept() {
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
$event = new Event('Controller.initialize', $this->Controller);
$this->assertNull($this->RequestHandler->ext);
Router::extensions('json', ['merge' => false]);
Router::extensions('json', false);

$this->RequestHandler->initialize($event);
$this->assertEquals('json', $this->RequestHandler->ext);
Expand All @@ -158,7 +158,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::extensions('csv', ['merge' => false]);
Router::extensions('csv', false);

$this->RequestHandler->initialize($event);
$this->assertNull($this->RequestHandler->ext);
Expand All @@ -174,7 +174,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::extensions(['rss', 'json'], ['merge' => false]);
Router::extensions(['rss', 'json'], false);

$this->RequestHandler->initialize($event);
$this->assertEquals('json', $this->RequestHandler->ext);
Expand All @@ -189,7 +189,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::extensions('json', ['merge' => false]);
Router::extensions('json', false);

$this->RequestHandler->initialize($event);
$this->assertNull($this->RequestHandler->ext);
Expand All @@ -207,13 +207,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::extensions(['xml', 'json'], ['merge' => false]);
Router::extensions(['xml', 'json'], false);

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

$this->RequestHandler->ext = null;
Router::extensions(array('json', 'xml'), ['merge' => false]);
Router::extensions(array('json', 'xml'), false);

$this->RequestHandler->initialize($event);
$this->assertEquals('json', $this->RequestHandler->ext);
Expand All @@ -228,7 +228,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::extensions(['xml', 'json'], ['merge' => false]);
Router::extensions(['xml', 'json'], false);

$this->RequestHandler->initialize($event);
$this->assertEquals('json', $this->RequestHandler->ext);
Expand All @@ -243,7 +243,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::extensions(['html', 'xml'], ['merge' => false]);
Router::extensions(['html', 'xml'], false);

$this->RequestHandler->initialize($event);
$this->assertNull($this->RequestHandler->ext);
Expand All @@ -256,7 +256,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::extensions(['xml', 'json'], ['merge' => false]);
Router::extensions(['xml', 'json'], false);

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

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

call_user_func_array(array('Cake\Routing\Router', 'extensions'), [$extensions, ['merge' => false]]);
call_user_func_array(array('Cake\Routing\Router', 'extensions'), [$extensions, false]);
}

/**
Expand Down Expand Up @@ -359,7 +359,7 @@ public function testAutoAjaxLayout() {
* @return void
*/
public function testJsonViewLoaded() {
Router::extensions(['json', 'xml', 'ajax'], ['merge' => false]);
Router::extensions(['json', 'xml', 'ajax'], false);
$this->Controller->request->params['_ext'] = 'json';
$event = new Event('Controller.startup', $this->Controller);
$this->RequestHandler->initialize($event);
Expand All @@ -376,7 +376,7 @@ public function testJsonViewLoaded() {
* @return void
*/
public function testXmlViewLoaded() {
Router::extensions(['json', 'xml', 'ajax'], ['merge' => false]);
Router::extensions(['json', 'xml', 'ajax'], false);
$this->Controller->request->params['_ext'] = 'xml';
$event = new Event('Controller.startup', $this->Controller);
$this->RequestHandler->initialize($event);
Expand All @@ -393,7 +393,7 @@ public function testXmlViewLoaded() {
* @return void
*/
public function testAjaxViewLoaded() {
Router::extensions(['json', 'xml', 'ajax'], ['merge' => false]);
Router::extensions(['json', 'xml', 'ajax'], false);
$this->Controller->request->params['_ext'] = 'ajax';
$event = new Event('Controller.startup', $this->Controller);
$this->RequestHandler->initialize($event);
Expand All @@ -409,7 +409,7 @@ public function testAjaxViewLoaded() {
* @return void
*/
public function testNoViewClassExtension() {
Router::extensions(['json', 'xml', 'ajax', 'csv'], ['merge' => false]);
Router::extensions(['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/RouteCollectionTest.php
Expand Up @@ -307,7 +307,7 @@ public function testExtensions() {
$this->collection->extensions(['rss', 'xml']);
$this->assertEquals(['json', 'rss', 'xml'], $this->collection->extensions());

$this->collection->extensions(['csv'], ['merge' => false]);
$this->collection->extensions(['csv'], false);
$this->assertEquals(['csv'], $this->collection->extensions());
}

Expand Down
16 changes: 8 additions & 8 deletions tests/TestCase/Routing/RouterTest.php
Expand Up @@ -277,7 +277,7 @@ public function testMapResourcesWithPrefix() {
* @return void
*/
public function testMapResourcesWithExtension() {
Router::extensions(['json', 'xml'], ['merge' => false]);
Router::extensions(['json', 'xml'], false);

Router::mapResources('Posts', ['_ext' => 'json']);
$_SERVER['REQUEST_METHOD'] = 'GET';
Expand Down Expand Up @@ -811,7 +811,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::extensions('rss', ['merge' => false]);
Router::extensions('rss', false);

$request = new Request();
$request->addParams(array(
Expand Down Expand Up @@ -1530,7 +1530,7 @@ public function parseReverseSymmetryData() {
* @return void
*/
public function testSetExtensions() {
Router::extensions('rss', ['merge' => false]);
Router::extensions('rss', false);
$this->assertContains('rss', Router::extensions());

$this->_connectDefaultRoutes();
Expand Down Expand Up @@ -1569,7 +1569,7 @@ public function testExtensionsWithScopedRoutes() {
* @return void
*/
public function testExtensionParsing() {
Router::extensions('rss', ['merge' => false]);
Router::extensions('rss', false);
$this->_connectDefaultRoutes();

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

Router::reload();
Router::extensions(['rss', 'xml'], ['merge' => false]);
Router::extensions(['rss', 'xml'], false);
$this->_connectDefaultRoutes();

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

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

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

$request = new Request('/posts/view/1.json');
$request->addParams(array(
Expand Down

0 comments on commit f52bf79

Please sign in to comment.