8000 Add the Countable interface to RouteCollection. by Crell · Pull Request #4642 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Add the Countable interface to RouteCollection. #4642

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/Symfony/Component/Routing/RouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*
* @api
*/
class RouteCollection implements \IteratorAggregate
class RouteCollection implements \IteratorAggregate, \Countable
{
private $routes;
private $resources;
Expand Down Expand Up @@ -88,6 +88,16 @@ public function getIterator()
return new \ArrayIterator($this->routes);
}

/**
* Gets the number of Routes in this collection.
*
* @return int The number of routes in this collection, including nested collections
*/
public function count()
{
return count($this->routes->all());
}

/**
* Adds a route.
*
Expand Down
8000
12 changes: 12 additions & 0 deletions src/Symfony/Component/Routing/Tests/RouteCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ public function testIteratorWithOverridenRoutes()
$this->assertEquals('/foo1', $this->getFirstNamedRoute($collection, 'foo')->getPattern());
}

public function testCount()
{
$collection = new RouteCollection();
$collection->add('foo', new Route('/foo'));

$collection1 = new RouteCollection();
$collection->addCollection($collection1);
$collection1->add('foo', new Route('/foo1'));

$this->assertCount(2, $collection);
}

protected function getFirstNamedRoute(RouteCollection $routeCollection, $name)
{
foreach ($routeCollection as $key => $route) {
Expand Down
0