Skip to content
Permalink
Browse files

Remove RouteCollection::addExtensions().

RouteCollection::extensions() can now be used to add/set extensions.
  • Loading branch information...
ADmad committed Sep 7, 2014
1 parent 264ac85 commit de7cbdc15474a029e896347f22c391c467e4ef8a
Showing with 22 additions and 18 deletions.
  1. +19 −15 src/Routing/RouteCollection.php
  2. +3 −3 tests/TestCase/Routing/RouteCollectionTest.php
@@ -99,7 +99,7 @@ public function add(Route $route, $options = []) {
$extensions = $route->extensions();
if ($extensions) {
$this->addExtensions($extensions);
$this->extensions($extensions);
}
}
@@ -274,27 +274,31 @@ public function named() {
return $this->_named;
}
/**
* Add one or more extensions.
*
* @param array $extensions The extensions to add.
* @return void
*/
public function addExtensions(array $extensions) {
$this->_extensions = array_unique(array_merge($this->_extensions, $extensions));
}
/**
* Get/set the extensions that the route collection could handle.
*
* @param null|string|array $extensions Either the list of extensions to set, or null to get.
* @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
* @return array The valid extensions.
*/
public function extensions($extensions = null) {
public function extensions($extensions = null, array $options = []) {
if ($extensions === null) {
return array_unique($this->_extensions);
return $this->_extensions;
}
$options += ['merge' => true];
$extensions = (array)$extensions;
if ($options['merge']) {
$extensions = array_unique(array_merge(
$this->_extensions,
$extensions
));
}
$this->_extensions = (array)$extensions;
return $this->_extensions = $extensions;
}
}
@@ -305,10 +305,10 @@ public function testExtensions() {
$this->assertEquals(['json'], $this->collection->extensions());
$this->collection->extensions(['rss', 'xml']);
$this->assertEquals(['rss', 'xml'], $this->collection->extensions());
$this->assertEquals(['json', 'rss', 'xml'], $this->collection->extensions());
$this->collection->addExtensions(['json']);
$this->assertEquals(['rss', 'xml', 'json'], $this->collection->extensions());
$this->collection->extensions(['csv'], ['merge' => false]);
$this->assertEquals(['csv'], $this->collection->extensions());
}
}

0 comments on commit de7cbdc

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