Skip to content
Open
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
10 changes: 5 additions & 5 deletions Extractor/ExposedRoutesExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ public function getRoutes(): RouteCollection
$expose = $route->getOption('expose');

if (false !== $expose && 'false' !== $expose) {
$routes->add($name, $route);
$routes->add((string)$name, $route);
}
continue;
}

preg_match('#^'.$this->pattern.'$#', $name, $matches);
preg_match('#^'.$this->pattern.'$#', (string)$name, $matches);

if (0 === count($matches)) {
continue;
Expand All @@ -77,7 +77,7 @@ public function getRoutes(): RouteCollection

$route = clone $route;
$route->setOption('expose', $domain);
$routes->add($name, $route);
$routes->add((string)$name, $route);
}

return $routes;
Expand Down Expand Up @@ -172,10 +172,10 @@ public function getResources(): array
/**
* {@inheritDoc}
*/
public function isRouteExposed(Route $route, $name): bool
public function isRouteExposed(Route $route, string $name): bool
{
if (false === $route->hasOption('expose')) {
return '' !== $this->pattern && preg_match('#^'.$this->pattern.'$#', $name);
return '' !== $this->pattern && preg_match('#^'.$this->pattern.'$#', (string)$name);
}

$status = $route->getOption('expose');
Expand Down
18 changes: 18 additions & 0 deletions Tests/Extractor/ExposedRoutesExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,25 @@ public function provideTestGetHostOverHttps(): array
'HTTPS Non-Standard' => ['127.0.0.1', 9876, '127.0.0.1:9876'],
];
}
public function testGetRoutesWithNumericNames(): void
{
$expected = new RouteCollection();
$expected->add('404', new Route('/404'));
$expected->add('500', new Route('/500'));
$expected->add('literal', new Route('/literal'));

$router = $this->getRouter($expected);
$extractor = new ExposedRoutesExtractor($router, ['.*'], $this->cacheDir, []);

$routes = $extractor->getRoutes();
$this->assertCount(3, $routes);

// Verify that numeric route names are handled correctly
$this->assertTrue($extractor->isRouteExposed($routes->get('404'), '404'));
$this->assertTrue($extractor->isRouteExposed($routes->get('500'), '500'));
// Test with integer key as well, since PHP may convert string keys to int
$this->assertTrue($extractor->isRouteExposed($routes->get('404'), '404'));
}
/**
* Get a mock object which represents a Router.
*/
Expand Down