FriendsOfSymfony / FOSJsRoutingBundle

A pretty nice way to expose your Symfony routing to client applications.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exception when a route name is a parsable number

sorrx opened this issue · comments

commented

For Symfony 6.2 a valid Route could be #[Route(path: '/{_locale}/404', name: '404')]
When using the string '404' as array key in the route-collection internally PHP converts that to an integer. So the annotated return type of the route collection "array<string, Route>" is no longer true due to PHP working in such way.
In Extractor/ExposedRouteExtractor.php the

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

then fails with an Exception, because it expects a string and not an integer as second parameter.

compare symfony/symfony#48722

Easy fix for the FOSJsRoutingBundle would be a typecast

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

which I understand is kind of annoying, given the annotated return-type