Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider callable factories for custom overrides? #280

Open
pmjones opened this issue Mar 10, 2024 · 1 comment
Open

Consider callable factories for custom overrides? #280

pmjones opened this issue Mar 10, 2024 · 1 comment

Comments

@pmjones
Copy link

pmjones commented Mar 10, 2024

Currently, the FastRoute class uses strings to indicate custom or override classes, then uses that string with a new call to create the override object. This means that the custom or override class cannot use an alternative constructor, which in turn limits additional or alternative functionality.

Allowing for the custom or override class to be specified as a string or callable, means that a callable can be invoked to return a fully-constructed object. This would let consumers add custom functionality to the custom or override class via a custom constructor. Cf. the as-yet-released CastRouteCollector which adds to the constructor parameters.

You could go further with this, and delegate object construction to a PSR-11 ContainerInterface, but that adds a dependency, and might over-complicate setup work.

@pmjones
Copy link
Author

pmjones commented Mar 12, 2024

Thinking on this some more: enabling something more like "real" dependency injection might be preferable. As a proof-of-concept, see these three sequential PRs:

All tests pass, but I have not run the other QA tooling.

I understand that this rearrangement may not fit your vision for the project, so use/modify/discard as you see fit.

(p.s. I can see now that even RouteCollector might do well to get a with($routeParser) method, making it more like the other injectable objects.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant