Skip to content

Commit

Permalink
Merge pull request #7712 from ankr/routebuilder-extensions-merge
Browse files Browse the repository at this point in the history
Adding `RouteBuilder::addExtensions` method
  • Loading branch information
markstory committed Nov 20, 2015
2 parents 2707ecf + 6f84536 commit a154b01
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Routing/RouteBuilder.php
Expand Up @@ -159,6 +159,18 @@ public function extensions($extensions = null)
$this->_extensions = (array)$extensions;
}

/**
* Add additional extensions to what is already in current scope
*
* @param string|array $extensions One or more extensions to add
* @return void
*/
public function addExtensions($extensions)
{
$extensions = array_merge($this->_extensions, (array)$extensions);
$this->_extensions = array_unique($extensions);
}

/**
* Get the path this scope is for.
*
Expand Down
22 changes: 22 additions & 0 deletions tests/TestCase/Routing/RouteBuilderTest.php
Expand Up @@ -190,6 +190,28 @@ public function testConnectExtensions()
$this->assertEquals(['xml', 'json'], $new->options['_ext']);
}

/**
* Test adding additional extensions will be merged with current.
*
* @return void
*/
public function testConnectExtensionsAdd()
{
$routes = new RouteBuilder(
$this->collection,
'/l',
[],
['extensions' => ['json']]
);
$this->assertEquals(['json'], $routes->extensions());

$routes->addExtensions(['xml']);
$this->assertEquals(['json', 'xml'], $routes->extensions());

$routes->addExtensions('csv');
$this->assertEquals(['json', 'xml', 'csv'], $routes->extensions());
}

/**
* test that extensions() accepts a string.
*
Expand Down

0 comments on commit a154b01

Please sign in to comment.