Skip to content

Consider callable factories for custom overrides? #280

@pmjones

Description

@pmjones

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.

Activity

pmjones

pmjones commented on Mar 12, 2024

@pmjones
Author

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @pmjones

        Issue actions

          Consider callable factories for custom overrides? · Issue #280 · nikic/FastRoute