Skip to content

Commit

Permalink
Remove RouteCollection::addExtensions().
Browse files Browse the repository at this point in the history
RouteCollection::extensions() can now be used to add/set extensions.
  • Loading branch information
ADmad committed Sep 7, 2014
1 parent 264ac85 commit de7cbdc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
34 changes: 19 additions & 15 deletions src/Routing/RouteCollection.php
Expand Up @@ -99,7 +99,7 @@ public function add(Route $route, $options = []) {

$extensions = $route->extensions();
if ($extensions) {
$this->addExtensions($extensions);
$this->extensions($extensions);
}
}

Expand Down Expand Up @@ -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;
}

}
6 changes: 3 additions & 3 deletions tests/TestCase/Routing/RouteCollectionTest.php
Expand Up @@ -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.