Skip to content

Commit feb9e87

Browse files
authored
Merge pull request #279 from andrew-demb/respect-iterable-provider
Fix handling non-array return from route provider
2 parents c85d366 + b4d3496 commit feb9e87

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

src/ChainRouteCollection.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function add(string $name, Route $route, int $priority = 0): void
5353
/**
5454
* Returns all routes in this collection.
5555
*
56-
* @return Route[] An array of routes
56+
* @return array<string, Route> An array of routes
5757
*/
5858
public function all(): array
5959
{

src/LazyRouteCollection.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,16 @@ public function count(): int
3535
/**
3636
* Returns all routes in this collection.
3737
*
38-
* @return Route[] An array of routes
38+
* @return array<string, Route> An array of routes
3939
*/
4040
public function all(): array
4141
{
42-
return $this->provider->getRoutesByNames(null);
42+
$routes = $this->provider->getRoutesByNames(null);
43+
if (\is_array($routes)) {
44+
return $routes;
45+
}
46+
47+
return \iterator_to_array($routes);
4348
}
4449

4550
public function get(string $name): ?Route

src/RouteProviderInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function getRouteByName(string $name): SymfonyRoute;
7777
* @param string[]|null $names The list of names to retrieve, In case of null,
7878
* the provider will determine what routes to return
7979
*
80-
* @return SymfonyRoute[] Iterable list with the keys being the names from the $names array
80+
* @return iterable<string, SymfonyRoute> Iterable list with the keys being the names from the $names array
8181
*/
8282
public function getRoutesByNames(?array $names = null): iterable;
8383
}

tests/Unit/Routing/LazyRouteCollectionTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function testGetIterator(): void
3636
$routeProvider->expects($this->exactly(2))
3737
->method('getRoutesByNames')
3838
->with(null)
39-
->willReturn($testRoutes);
39+
->willReturn(new \ArrayIterator($testRoutes));
4040
$lazyRouteCollection = new LazyRouteCollection($routeProvider);
4141
$this->assertEquals($testRoutes, iterator_to_array($lazyRouteCollection->getIterator()));
4242
$this->assertEquals($testRoutes, $lazyRouteCollection->all());

0 commit comments

Comments
 (0)