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

Use Closure instead of callable for various methods of Routing package. #13744

Closed
wants to merge 2 commits into from

Conversation

ADmad
Copy link
Member

@ADmad ADmad commented Oct 13, 2019

I don't think anyone would be using invokable classes for connecting routes. For various router/routerbuilder methods we allow passing callback for 2nd params/options argument which is an array so using Closures only for callback are better for type checks.

@ADmad ADmad added this to the 4.0.0 milestone Oct 13, 2019
@josegonzalez
Copy link
Member

Its funny because I'm pretty sure I demo'd this exact thing - invokable classes for connected routes - a few years back for a microframework...

@markstory
Copy link
Member

@josegonzalez Do you think we should retain compatibility for invokable classes to be used in route building? How does it help build a microframework app?

@josegonzalez
Copy link
Member

I think its a nice way to evolve your app into a more complex one from simple closures. Here is a list of what slimphp supports, one of which is an invokable class.

I personally enjoy working with invokable classes as they can be registered easily and don't require a convention around the framework, instead relying on generic php :)

@ADmad
Copy link
Member Author

ADmad commented Oct 14, 2019

While not clear from my comment my aim wasn't to prevent use of invokable but simply avoid callables as it covers a very wide range of values and callable checks can be expensive.

I can replace the \Closure typehint with object which would allow closures and invokable class instances. There are additional type checks already for type of $callback argument due the argument juggling in various methods so I will update the checks to allow invokables too.

@ADmad
Copy link
Member Author

ADmad commented Oct 14, 2019

But using object typehint (or as docblock type) will most likely make static analyzers unhappy when trying to invoke the objects. Omitting typehint and specifying type as callable only in docblocks would be misleading as users my think all valid callables can be used 😞.

I wish PHP have a specific type for invokable classes 🙂.

@markstory
Copy link
Member

Perhaps we should stick with callable given the awkward alternative typehints.

@ADmad
Copy link
Member Author

ADmad commented Oct 14, 2019

Yup, there might be some clean up I can salvage out of this so I will keep this open for now and update the PR or close later.

@ADmad ADmad closed this Oct 15, 2019
@ADmad ADmad deleted the 4.x-router-callable branch October 15, 2019 13:31
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

Successfully merging this pull request may close these issues.

None yet

3 participants