✨ Add NamespaceRouteLoader powered by Composer's PSR-4 map#41
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add
NamespaceRouteLoader, a Composer-powered route discoverer, and mark the directory-basedRouteLoader::__constructas@deprecated. The new loader resolves the filesystem location of routes from Composer's PSR-4 map and derives each candidate FQCN from its file path, so the custom token-stream parser becomes optional going forward.Why
RouteLoaderdiscovery currently relies onParser::findClassName, a hand-rolled tokenizer that has several known edge cases (anonymous classes hijacking detection, block-style namespaces missed, missing early-exit). Composer already knows the class-to-file mapping via PSR-4, so re-implementing that lookup withtoken_get_allduplicates work and introduces bugs.NamespaceRouteLoaderswaps the convention: users declare the namespace they want to expose, the loader asks Composer where that namespace lives on disk, walks the directory, and derives each FQCN from the path. No tokenizing, noParserinvocation.Usage
Or, with options and an injected ClassLoader (useful for tests or multi-autoloader setups):
Deprecation
RouteLoader::__constructcarries an @deprecated PHPDoc tag pointing at NamespaceRouteLoader. Behaviour is unchanged at runtime — existing code keeps working — but PHPStan and IDEs will flag direct instantiation. The class itself stays as the base class NamespaceRouteLoader inherits from.Backward compatibility
Non-breaking, minor bump. RouteLoader still discovers routes via the directory walker + Parser. Nothing was removed.