Skip to content

Commit

Permalink
added an exception if a route with the same name is added twice
Browse files Browse the repository at this point in the history
this will for example detect cases of getAction() vs getArticleAction() inside a controller named ArticleController
  • Loading branch information
lsmith77 committed Aug 7, 2012
1 parent 91166b1 commit 1954c15
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Routing/Loader/Reader/RestActionReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ public function read(RestRouteCollection $collection, \ReflectionMethod $method,

// generated parameters
$routeName = $this->namePrefix.strtolower($routeName);
if ($collection->has($routeName)) {
throw new \InvalidArgumentException("There already is a method that resulted in defining a route '$routeName'");
}

$pattern = implode('/', $urlParts);
$defaults = array('_controller' => $method->getName());
$requirements = array('_method' => strtoupper($httpMethod));
Expand Down
13 changes: 13 additions & 0 deletions Routing/RestRouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ class RestRouteCollection extends RouteCollection
{
private $singularName;

/**
* Checks if there is already a route by the same name in the collection.
*
* @param string $name The route name
*
* @api
*/
public function has($name)
{
$routes = $this->all();
return isset($routes[$name]);
}

/**
* Set collection singular name.
*
Expand Down

0 comments on commit 1954c15

Please sign in to comment.