Closed dbojdo closed 2 years ago
Along with this change we might want to remove unnecessary check in the UrlMatcher (is_string)
Along with this change we might want to remove unnecessary check in the UrlMatcher (is_string)
we should enable phpstan, that would detect such mistakes...
Environment
PHP 8.1
Symfony packages
Symfony CMF packages
Subject
When ORM implementation of the Route entity is used, the "_route" attribute of the Request object is set to the numeric ID of the entity (e.g. "5"). What makes impossible to use this attribute along with the URL generator (cannot generate the URL from the ID, it must be the name).
After investigation I spotted it's due to the fact, that
Symfony\Cmf\Bundle\RoutingBundle\Model::getId()
always returnsstring
. Before there was no casting to string. The above with the if statement inSymfony\Cmf\Component\Routing\NestedMatcher::getAttributes
(is_string($route->getRouteKey())
) replaces the route name with it's numeric ID.Steps to reproduce
Read the "_route" attribute of Request object when ORM used.
Expected results
"_route" attribute should contain the route name
Actual results
"_route" attribute contains the numeric ID of the Route
Proposed solution is to override
getRouteKey
method ofSymfony\Cmf\Bundle\RoutingBundle\Doctrine\Orm\Route
to return the name rather than ID.