8000 Add the Countable interface to RouteCollection. · symfony/symfony@c350944 · GitHub
[go: up one dir, main page]

Skip to content

Commit c350944

Browse files
committed
Add the Countable interface to RouteCollection.
1 parent 0d4b02e commit c350944

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/Symfony/Component/Routing/RouteCollection.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*
2525
* @api
2626
*/
27-
class RouteCollection implements \IteratorAggregate
27+
class RouteCollection implements \IteratorAggregate, \Countable
2828
{
2929
private $routes;
3030
private $resources;
@@ -88,6 +88,16 @@ public function getIterator()
8888
return new \ArrayIterator($this->routes);
8989
}
9090

91+
/**
92+
* Gets the number of Routes in this collection.
93+
*
94+
* @return int The number of routes in this collection, including nested collections
95+
*/
96+
public function count()
97+
{
98+
return count($this->routes->all());
99+
}
100+
91101
/**
92102
* Adds a route.
93103
*

src/Symfony/Component/Routing/Tests/RouteCollectionTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ public function testIteratorWithOverridenRoutes()
7676
$this->assertEquals('/foo1', $this->getFirstNamedRoute($collection, 'foo')->getPattern());
7777
}
7878

79+
public function testCount()
80+
{
81+
$collection = new RouteCollection();
82+
$collection->add('foo', new Route('/foo'));
83+
84+
$collection1 = new RouteCollection();
85+
$collection->addCollection($collection1);
86+
$collection1->add('foo', new Route('/foo1'));
87+
88+
$this->assertCount(2, $collection);
89+
}
90+
7991
protected function getFirstNamedRoute(RouteCollection $routeCollection, $name)
8092
{
8193
foreach ($routeCollection as $key => $route) {

0 commit comments

Comments
 (0)
0