thephpleague / route

Fast PSR-7 based routing and dispatch component including PSR-15 middleware, built on top of FastRoute.
http://route.thephpleague.com
MIT License
651 stars 126 forks source link

#340 - [4.x] Container resolution error #341

Closed alanondra closed 4 weeks ago

alanondra commented 2 months ago

Issue

Issue #340 identified an issue in resolving classes in PHP 8. The error is caused by a breaking change in PHP 8.1 which disallows optional parameters before required parameters.

Changes

I've reordered the parameter list for Route::resolveClass and updated the two locations where it's been called.

Side Effects

Since this is within protected functionality it should only cause an issue for anyone who is customizing the Route class.

Testing

I set up a container with PHP 7.4.33 and ran the existing tests, since the current tests in RouteTest already handle Container resolution:

$ ./vendor/bin/phpcs
............................................... 47 / 47 (100%)

Time: 25ms; Memory: 8MB
$ ./vendor/bin/phpunit
PHPUnit 7.5.20 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.4.33 with Xdebug 3.1.6
Configuration: /workspaces/Route/phpunit.xml

................................................................  64 / 64 (100%)

Time: 187 ms, Memory: 10.00 MB

OK (64 tests, 257 assertions)

Generating code coverage report in Clover XML format ... done

Generating code coverage report in HTML format ... done

For posterity I attempted to test with 8.0+ but there were dependency issues outside the scope of this change.