-
Notifications
You must be signed in to change notification settings - Fork 7
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
ServerMiddlewareInterface::process
leads to lesser strict type-hinting
#43
Comments
ServerMiddleware::process
leads to lesser strict type-hintingServerMiddlewareInterface::process
leads to lesser strict type-hinting
They can accept whatever they like and that's not the PSR's problem. Specifying The spec says their backend should provide a The PSR is only interested in making sure that any PSR-15 compliant middleware can be dropped into any PSR-15 delegate and work as expected, it is not interested in the mechanism by which that middleware is dropped in. Nor does it care if a framework wants to support its own middleware alongside PSR-15 middleware. |
Sorry, I should have mentioned the README.md:
In practice, and I hope I showed that above, it would lead to type-hinting against |
It's not at all fair to compare frameworks that are using the double-pass approach and then claim that this makes current type hinting situation worse. |
I don't understand. What is the difference? I believe the same applies to the single-pass approach. |
None of them are based on PSR-15. It's comparing apples or oranges, or at least oranges to tangerines. |
That is not fair either, PSR-15 targets all of these frameworks. But, okay if you need PSR-15 example: class Dispatcher implements MiddlewareInterface
{
//…
/**
* @var mixed[] unresolved middleware stack
*/
private $stack;
/**
* @param (callable|MiddlewareInterface|mixed)[] $stack middleware stack (with at least one middleware component)
* …
*/
public function __construct($stack, callable $resolver = null) Even your Even with splat: // not possible:
public function __construct(callable $resolver, callable ...$stack) |
|
I'm a member of https://github.com/middlewares, I would be proud to rewrite them – furthermore we must already change the namespace sooner or later 😁 |
I tripped over this, because I was working on my GreenOnion stack to support PSR-15+Generators and many things got really messy just because I have to type-check everything. The current version is not perfect, and I do not claim that with Why don't I write one of my beloved adapters? 😉 |
For my
– Thus, at least for my project it would be tremendous. EDIT/Clarification: results above are regarding to these interfaces ( interface ServerMiddlewareInterface
{
public function __invoke(ServerRequestInterface $request, DelegateInterface $delegate);
}
interface DelegateInterface
{
public function __invoke(ServerRequestInterface $request);
} |
For what it's worth, I agree with @atanvarno69 and @shadowhand — it is up to the middleware framework to decide whether or not it accepts callable middleware. We've got code in the develop branch of both Stratigility and Expressive now that accepts callables and then wraps them in an http-middleware proxy. (They also then wrap the Your argument about the cyclomatic complexity makes no sense to me; it would make more sense if you could provide a diff demonstrating the code changes from implementation via So, what it comes down to is quite simply this: I'm really not sure why you are pushing so hard for using |
I can very well imagine that.
Sorry @weierophinney could not resist, you made that too easy. I hope you have had good reasons to introduce that complexity, but I believe we do not agree about the point when software becomes a big ball of mud.
Of course, it is a design decision to use
Of course, it is about my personal preference! I love clean code; I love reusable code; I love KISS! To state it simple: I would love Middlewares wich are usable by their own! (E.g see #39 (comment))
Do not get confused with
public function process(RequestInterface $request, DelegateInterface $delegate)
{
$response = $delegate->process($request);
// vs.
$response = $delegate($request);
} I've already explained at #24 (comment) and again at #35 (comment):
In the meantime, I've understood that point of view and I've stopped promoting that middleware frameworks MUST accept |
Making delegates callable without making middleware callable would allow people to implement both middleware and delegate interfaces in the same class, which is definitely not correct. From where I sit, it looks like you are picking and choosing details (many already explained and refuted in the META document) that support your argument and ignoring all the others, @schnittstabil. If you still feel strongly and can present your argument concisely, you have the opportunity to do so during the review stage. |
As far as I can see, this issue thread is only about
Yes, I still feel strongly about it and I've done my best to present my arguments concisely – refuting my arguments because they are not concisely enough or because I pick and choose those details which underpin my arguments would be just irrational. These arguments will neither become false nor vanish in thin air through that. |
At this point I'm only skimming the discussions, as I've pretty arrived at the conclusion that you can argue more or less equally for/against both approaches - because they're both right, and both wrong, in different ways. The only way this debate could ever be settled to the satisfaction of those who argue in favor of one or the other, is if PHP had certain missing language features - such as type-hinted callables or generics. In absence of the right language features to express the actual constraints, whatever we end up with will have pros and cons. I personally would lean more towards accepting the limitations of the language and use the closest thing available - rather than trying to shoehorn in type-safety, which comes at a cost of complexity, and largely ends up being run-time type-checks anyhow, but I can see it both ways. I essentially don't really care anymore - the implications in terms of added complexity and overhead largely affect middleware-stacks only, and I'm of the mind that that's not the most important thing; the most important thing is implementation of middleware, and I can't see that working equally well either way. My main interest is to see the PSR finalized soon, so I can finalize the projects I'm working on. I'm mostly happy with the important parts :-) |
And before you claim again, I would ignore arguments:
The inheritance hierarchy and Preventing cooperation by the same name on purpose is just a irrational hack. EDIT: Moreover, I gave a realistic example of middlewares which can act as delegates as well at #41 (comment). Nobody, argued against it – not even you, @shadowhand. |
Same holds for me. But I also see too much unnecessarily work (e.g. #39 (comment)), less acceptance and less innovative frameworks (#37 (comment)) in the future with |
A small micro-framework survey:
All of them support anonymous functions. With
ServerMiddlewareInterface::__invoke
they may want to type-hint againstcallable
at someday – withServerMiddlewareInterface::process
they will never be able to do – thus they must type-hint tomixed
😒Moreover, the same applies to every single future framework/container, which wants to support anonymous functions as well.
The text was updated successfully, but these errors were encountered: