Skip to content

Commit 67faeaf

Browse files
committed
Rename Router::setExtensions() to Router::parseExtensions().
Also renamed Route::setExtensions() to Route::parseExtensions() for consistency.
1 parent 48df5ba commit 67faeaf

File tree

7 files changed

+37
-38
lines changed

7 files changed

+37
-38
lines changed

src/Routing/Route/Route.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public function __construct($template, $defaults = [], array $options = []) {
128128
* @param array $extensions The extensions to set.
129129
* @return void
130130
*/
131-
public function setExtensions(array $extensions) {
131+
public function parseExtensions(array $extensions) {
132132
$this->_extensions = $extensions;
133133
}
134134

src/Routing/RouteCollection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,9 @@ public function setContext(Request $request) {
265265
* @param array $extensions The extensions for routes to use.
266266
* @return void
267267
*/
268-
public function setExtensions(array $extensions) {
268+
public function parseExtensions(array $extensions) {
269269
foreach ($this->_routes as $route) {
270-
$route->setExtensions($extensions);
270+
$route->parseExtensions($extensions);
271271
}
272272
}
273273

src/Routing/Router.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ public static function resourceMap($resourceMap = null) {
302302
* reverse routing lookups. If undefined a name will be generated for each
303303
* connected route.
304304
* - `_ext` is an array of filename extensions that will be parsed out of the url if present.
305-
* See {@link Route::setExtensions()}.
305+
* See {@link Route::parseExtensions()}.
306306
*
307307
* You can also add additional conditions for matching routes to the $defaults array.
308308
* The following conditions can be used:
@@ -961,23 +961,22 @@ public static function normalize($url = '/') {
961961
* current extensions
962962
* @return array
963963
*/
964-
public static function setExtensions($extensions = null, $merge = true) {
964+
public static function parseExtensions($extensions = null, $merge = true) {
965965
if ($extensions === null) {
966966
return static::$_validExtensions;
967967
}
968968
$extensions = (array)$extensions;
969969
if ($merge) {
970970
$extensions = array_merge(static::$_validExtensions, $extensions);
971971
}
972-
static::$_routes->setExtensions($extensions);
972+
static::$_routes->parseExtensions($extensions);
973973
return static::$_validExtensions = $extensions;
974974
}
975975

976976
/**
977977
* Get the list of extensions that can be parsed by Router.
978978
*
979-
* To initially set extensions use `Router::parseExtensions()`
980-
* To add more see `setExtensions()`
979+
* To add / update extensions use `Router::parseExtensions()`
981980
*
982981
* @return array Array of extensions Router is configured to parse.
983982
*/

tests/TestCase/Controller/Component/RequestHandlerComponentTest.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function tearDown() {
8383
if (!headers_sent()) {
8484
header('Content-type: text/html'); //reset content type.
8585
}
86-
call_user_func_array('Cake\Routing\Router::setExtensions', [$this->_extensions, false]);
86+
call_user_func_array('Cake\Routing\Router::parseExtensions', [$this->_extensions, false]);
8787
}
8888

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

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

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

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

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

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

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

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

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

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

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

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

257257
$event = new Event('Controller.initialize', $this->Controller);
258258
$this->RequestHandler->initialize($event);
@@ -268,7 +268,7 @@ public function testInitializeContentTypeAndExtensionMismatch() {
268268
$event = new Event('Controller.initialize', $this->Controller);
269269
$this->assertNull($this->RequestHandler->ext);
270270
$extensions = Router::extensions();
271-
Router::setExtensions('xml', false);
271+
Router::parseExtensions('xml', false);
272272

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

281-
call_user_func_array(array('Cake\Routing\Router', 'setExtensions'), [$extensions, false]);
281+
call_user_func_array(array('Cake\Routing\Router', 'parseExtensions'), [$extensions, false]);
282282
}
283283

284284
/**
@@ -353,7 +353,7 @@ public function testAutoAjaxLayout() {
353353
* test custom JsonView class is loaded and correct.
354354
*/
355355
public function testJsonViewLoaded() {
356-
Router::setExtensions(['json', 'xml', 'ajax'], false);
356+
Router::parseExtensions(['json', 'xml', 'ajax'], false);
357357
$this->Controller->request->params['_ext'] = 'json';
358358
$event = new Event('Controller.startup', $this->Controller);
359359
$this->RequestHandler->initialize($event);
@@ -368,7 +368,7 @@ public function testJsonViewLoaded() {
368368
* test custom XmlView class is loaded and correct.
369369
*/
370370
public function testXmlViewLoaded() {
371-
Router::setExtensions(['json', 'xml', 'ajax'], false);
371+
Router::parseExtensions(['json', 'xml', 'ajax'], false);
372372
$this->Controller->request->params['_ext'] = 'xml';
373373
$event = new Event('Controller.startup', $this->Controller);
374374
$this->RequestHandler->initialize($event);
@@ -383,7 +383,7 @@ public function testXmlViewLoaded() {
383383
* test custom AjaxView class is loaded and correct.
384384
*/
385385
public function testAjaxViewLoaded() {
386-
Router::setExtensions(['json', 'xml', 'ajax'], false);
386+
Router::parseExtensions(['json', 'xml', 'ajax'], false);
387387
$this->Controller->request->params['_ext'] = 'ajax';
388388
$event = new Event('Controller.startup', $this->Controller);
389389
$this->RequestHandler->initialize($event);
@@ -397,7 +397,7 @@ public function testAjaxViewLoaded() {
397397
* test configured extension but no view class set.
398398
*/
399399
public function testNoViewClassExtension() {
400-
Router::setExtensions(['json', 'xml', 'ajax', 'csv'], false);
400+
Router::parseExtensions(['json', 'xml', 'ajax', 'csv'], false);
401401
$this->Controller->request->params['_ext'] = 'csv';
402402
$event = new Event('Controller.startup', $this->Controller);
403403
$this->RequestHandler->initialize($event);

tests/TestCase/Routing/Route/RouteTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function testRouteParsingWithExtensions() {
105105
$result = $route->parse('/posts/index.pdf');
106106
$this->assertFalse(isset($result['_ext']));
107107

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

tests/TestCase/Routing/RouterTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ public function testMapResourcesWithExtension() {
292292
$this->assertEquals(['posts'], $resources);
293293

294294
$_SERVER['REQUEST_METHOD'] = 'GET';
295-
Router::setExtensions(['json', 'xml'], false);
295+
Router::parseExtensions(['json', 'xml'], false);
296296

297297
$expected = array(
298298
'plugin' => null,
@@ -839,7 +839,7 @@ public function testUrlGenerationWithPrefix() {
839839
Router::connect('/reset/*', array('admin' => true, 'controller' => 'users', 'action' => 'reset'));
840840
Router::connect('/tests', array('controller' => 'tests', 'action' => 'index'));
841841
Router::connect('/admin/:controller/:action/*', array('prefix' => 'admin'));
842-
Router::setExtensions('rss', false);
842+
Router::parseExtensions('rss', false);
843843

844844
$request = new Request();
845845
$request->addParams(array(
@@ -1630,7 +1630,7 @@ public function testPrefixRoutingAndPlugins() {
16301630
*/
16311631
public function testParseExtensions() {
16321632
Router::extensions();
1633-
Router::setExtensions('rss', false);
1633+
Router::parseExtensions('rss', false);
16341634
$this->assertContains('rss', Router::extensions());
16351635
}
16361636

@@ -1641,7 +1641,7 @@ public function testParseExtensions() {
16411641
*/
16421642
public function testSetExtensions() {
16431643
Router::extensions();
1644-
Router::setExtensions('rss', false);
1644+
Router::parseExtensions('rss', false);
16451645
$this->assertContains('rss', Router::extensions());
16461646

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

1655-
Router::setExtensions(array('xml'));
1655+
Router::parseExtensions(array('xml'));
16561656
$result = Router::extensions();
16571657
$this->assertContains('rss', $result);
16581658
$this->assertContains('xml', $result);
16591659

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

1663-
$result = Router::setExtensions(array('pdf'), false);
1663+
$result = Router::parseExtensions(array('pdf'), false);
16641664
$this->assertEquals(array('pdf'), $result);
16651665
}
16661666

@@ -1670,7 +1670,7 @@ public function testSetExtensions() {
16701670
* @return void
16711671
*/
16721672
public function testExtensionParsing() {
1673-
Router::setExtensions('rss', false);
1673+
Router::parseExtensions('rss', false);
16741674
require CAKE . 'Config/routes.php';
16751675

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

17001700
Router::reload();
1701-
Router::setExtensions(['rss', 'xml'], false);
1701+
Router::parseExtensions(['rss', 'xml'], false);
17021702
require CAKE . 'Config/routes.php';
17031703

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

17421742
Router::reload();
1743-
Router::setExtensions('rss', false);
1743+
Router::parseExtensions('rss', false);
17441744
Router::connect('/controller/action', array('controller' => 'controller', 'action' => 'action', '_ext' => 'rss'));
17451745
$result = Router::parse('/controller/action');
17461746
$expected = array(
@@ -2069,7 +2069,7 @@ public function testParsingWithTrailingPeriod() {
20692069
public function testParsingWithTrailingPeriodAndParseExtensions() {
20702070
Router::reload();
20712071
Router::connect('/:controller/:action/*');
2072-
Router::setExtensions('json', false);
2072+
Router::parseExtensions('json', false);
20732073

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

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

tests/test_app/TestApp/Config/routes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

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

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

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

0 commit comments

Comments
 (0)