Skip to content

Commit

Permalink
Merge pull request sonata-project#942 from pulzarraider/route_collect…
Browse files Browse the repository at this point in the history
…ion_remove_all

Route collection: new methods - removeAll and removeAllExcept
  • Loading branch information
rande committed Aug 20, 2012
2 parents 7fd6d26 + c4a434d commit 0c18ea1
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions Route/RouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,42 @@ public function remove($name)
return $this;
}

/**
* Remove all routes except routes in $routeList
*
* @param array $routeList
*
* @return \Sonata\AdminBundle\Route\RouteCollection
*/
public function removeAllExcept(array $routeList)
{
$routeCodeList = array();
foreach ($routeList as $name) {
$routeCodeList[] = $this->getCode($name);
}

$elements = $this->elements;
foreach ($elements as $key => $element) {
if (!in_array($key, $routeCodeList)) {
unset($this->elements[$key]);
}
}

return $this;
}

/**
* Remove all routes
*
* @return \Sonata\AdminBundle\Route\RouteCollection
*/
public function removeAll()
{
$this->elements = array();

return $this;
}

/**
* Convert a word in to the format for a symfony action action_name => actionName
*
Expand Down

0 comments on commit 0c18ea1

Please sign in to comment.