Problem/Motivation
In Drupal, Drupal\Core\Routing\Router::matchCollection() is declared as:
* @return array|null
* An array of parameters. NULL when there is no match.
*/
protected function matchCollection($pathinfo, RouteCollection $routes) {
In Symfony 6, the signature changes to
protected function matchCollection(string $pathinfo, RouteCollection $routes): array
ie. we can no longer return NULL when there is no match. The upstream docblock gives a clue as to a possible fix:
* @throws ResourceNotFoundException If the resource could not be found
Steps to reproduce
Proposed resolution
Convert the NULL return to an exception.
Remaining tasks
See what side effects this change has.
Figure out if this is only affects core or could affect contrib/custom code.
If needed, figure out how to warn downstream users of this change.
User interface changes
API changes
Router::matchCollection() will throw an exception instead of returning NULL when there is no match.
Data model changes
Release notes snippet
Comments
Comment #2
longwaveSo it turns out there is a throw statement already, we can just move it from
matchRequest()down tomatchCollection(). AsmatchCollection()is protected I think this is safe to do with no effect to downstream users - callers will be usingmatchRequest()and the end result will be the same.This patch also adds the return type to
matchCollection()as required by Symfony 6.Comment #3
catchNice easy one in the end.
Comment #4
andypostMaybe it needs to update docblock to point exceptions for another method ?
Comment #5
longwave@andypost docblocks are both @inheritdoc now, and the Symfony interfaces mention both exceptions, so I think we are OK.
Comment #7
catchBeen a few days since I RTBCed this so I think this can just go in.
Committed faa6580 and pushed to 10.0.x. Thanks!