Conversation
PR Summary
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #196 +/- ##
=============================================
- Coverage 100.00% 99.83% -0.17%
- Complexity 129 186 +57
=============================================
Files 13 23 +10
Lines 400 589 +189
=============================================
+ Hits 400 588 +188
- Misses 0 1 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
MatchingResult
# Conflicts: # .phpstorm.meta.php/Group.php # .phpstorm.meta.php/Route.php # src/Group.php # src/MatchingResult.php # src/Middleware/Router.php # src/Route.php # tests/GroupTest.php # tests/RouteCollectionTest.php # tests/RouteTest.php
MatchingResult|
Waiting #225 |
# Conflicts: # composer.json # src/Group.php # src/Route.php # tests/RouteCollectionTest.php # tests/RouteTest.php
…route provider handling; increase MSI
…eware callable in GroupTest
There was a problem hiding this comment.
Pull request overview
This PR introduces route declaration via PHP attributes and adds a provider abstraction for supplying routes from different sources (arrays and PHP files/directories). It also refactors Route and Group into more DTO-like objects with public constructors and additional validation, and extends the test suite accordingly.
Changes:
- Add PHP attribute classes (
Get,Post, etc.) to model routes as native PHP attributes. - Add
RoutesProviderInterfaceplusArrayRoutesProviderandFileRoutesProvider, and extendRouteCollectorto accept providers. - Refactor
RouteandGroupconstructors (public, validation, caching tweaks) and add/adjust tests + fixtures.
Reviewed changes
Copilot reviewed 39 out of 40 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Support/resources/test.php | Adds a simple test fixture file. |
| tests/Support/resources/scope/scope_routes.php | Adds scoped route fixture to test providing routes with extracted variables. |
| tests/Support/resources/routes.php | Adds routes fixture used by provider tests. |
| tests/Support/resources/mixed_dir/valid_routes.php | Adds valid PHP routes fixture for directory scanning tests. |
| tests/Support/resources/mixed_dir/not_routes.txt | Adds non-PHP fixture to verify directory scanning ignores it. |
| tests/Support/resources/foo.php | Adds fixture returning non-routes to validate provider filtering. |
| tests/Support/TestController.php | Adds attribute usage examples with #[Group] and #[Get]. |
| tests/RouteTest.php | Adds/updates tests for new Route constructor behavior and validation. |
| tests/RouteCollectorTest.php | Adds tests for collecting routes from providers. |
| tests/RouteCollectionTest.php | Mostly formatting adjustments in chained calls. |
| tests/Provider/FileRoutesProviderTest.php | Adds tests for file/directory-based route provider behavior. |
| tests/Provider/ArrayRoutesProviderTest.php | Adds tests for array-based route provider behavior. |
| tests/GroupTest.php | Adds tests for Group constructor validation and caching behavior. |
| tests/Attribute/RouteTest.php | Adds tests for generic #[Route] attribute. |
| tests/Attribute/PutTest.php | Adds tests for #[Put] attribute. |
| tests/Attribute/PostTest.php | Adds tests for #[Post] attribute. |
| tests/Attribute/PatchTest.php | Adds tests for #[Patch] attribute. |
| tests/Attribute/OptionsTest.php | Adds tests for #[Options] attribute. |
| tests/Attribute/HeadTest.php | Adds tests for #[Head] attribute. |
| tests/Attribute/GetTest.php | Adds tests for #[Get] attribute. |
| tests/Attribute/DeleteTest.php | Adds tests for #[Delete] attribute. |
| src/RouteCollector.php | Adds route providers support in the collector. |
| src/RouteCollection.php | Small docblock wording adjustment. |
| src/Route.php | Makes constructor public, adds validation and defaults normalization, adjusts cache invalidation. |
| src/Provider/RoutesProviderInterface.php | Introduces the provider interface contract. |
| src/Provider/FileRoutesProvider.php | Implements loading routes from a file or directory. |
| src/Provider/ArrayRoutesProvider.php | Implements loading routes from an in-memory array. |
| src/MatchingResult.php | Adds a Psalm assertion for route() nullability. |
| src/Group.php | Makes constructor public, adds validation, and marks Group as a PHP attribute. |
| src/Attribute/RouteAttributeInterface.php | Introduces an interface for route attribute classes. |
| src/Attribute/Route.php | Adds a generic #[Route] attribute implementation. |
| src/Attribute/Put.php | Adds #[Put] attribute implementation. |
| src/Attribute/Post.php | Adds #[Post] attribute implementation. |
| src/Attribute/Patch.php | Adds #[Patch] attribute implementation. |
| src/Attribute/Options.php | Adds #[Options] attribute implementation. |
| src/Attribute/Head.php | Adds #[Head] attribute implementation. |
| src/Attribute/Get.php | Adds #[Get] attribute implementation. |
| src/Attribute/Delete.php | Adds #[Delete] attribute implementation. |
| README.md | Documents support for attribute-based route declaration. |
| CHANGELOG.md | Adds release notes for attributes/providers/DTO refactor. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| $files = new CallbackFilterIterator( | ||
| new FilesystemIterator( | ||
| $this->file, | ||
| /** @infection-ignore-all Bitwise flags; CallbackFilterIterator already filters by extension */ | ||
| FilesystemIterator::SKIP_DOTS | FilesystemIterator::FOLLOW_SYMLINKS, | ||
| ), | ||
| fn(SplFileInfo $fileInfo) => $fileInfo->isFile() && $fileInfo->getExtension() === 'php', | ||
| ); | ||
| /** @var SplFileInfo[] $files */ | ||
| foreach ($files as $file) { |
There was a problem hiding this comment.
When a directory is provided, iteration order of FilesystemIterator is filesystem-dependent. Because route order typically affects matching/precedence, the resulting route set can become non-deterministic across environments. Consider collecting filenames and sorting them (or otherwise enforcing a stable order) before requiring files.
| /** | ||
| * @param string[] $methods | ||
| * @param array|callable|string|null $action Action handler. It is a primary middleware definition that | ||
| * should be invoked last for a matched route. | ||
| * @param array[]|callable[]|string[] $middlewares Middleware definitions. | ||
| * @param array<string,scalar|Stringable|null> $defaults Parameter default values indexed by parameter names. | ||
| * @param bool $override Marks route as override. When added it will replace existing route with the same name. | ||
| * @param array $disabledMiddlewares Excludes middleware from being invoked when action is handled. |
There was a problem hiding this comment.
Docblocks/types for $defaults allow scalar|Stringable|null, but both the constructor and defaults() cast values via strval(), which turns null into '' and Stringable into its string representation. Either adjust the docs/psalm types to reflect array<string,string>, or preserve null/Stringable values instead of forcing strings.
…; improve handling of route providers and test cases
ℹ️ yiisoft/demo#589