$kernel = new NotFoundMiddleware();$kernel = new RouterMiddleware(new Router(...), $kernel);$kernel = new CacheMiddleware($kernel);$kernel = new ErrorHandlerMiddleware();
return $this->container->get($id)->process($request);
--
You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to php-fig+u...@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/99e602d1-e871-4d19-829a-1330252b508c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/php-fig/B3jtdJA7-6w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to php-fig+unsubscribe@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to php-fig+unsubscribe@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/99e602d1-e871-4d19-829a-1330252b508c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/php-fig/B3jtdJA7-6w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to php-fig+unsubscribe@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/57FC4BBE-38F8-4B7D-B02D-1E003A0B7D21%40buffalo.edu.
To unsubscribe from this group and stop receiving emails from it, send an email to php-fig+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/CADqTB_imT06jv9v-3DN4_uv1vZmmqO%2B6at8Ny5DpocWNNPmZCg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/CADqTB_imT06jv9v-3DN4_uv1vZmmqO%2B6at8Ny5DpocWNNPmZCg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/php-fig/B3jtdJA7-6w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to php-fig+unsubscribe@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/88F5DE6C-20F1-4CCF-A84C-655FA32AC471%40buffalo.edu.
To unsubscribe from this group and stop receiving emails from it, send an email to php-fig+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/CADqTB_g-WC2Uk%3D%3D%2BcHutKapCAkg_gNuLbZERznO6J7SD4ObY2Q%40mail.gmail.com.
--
You received this message because you are subscribed to a topic in the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/php-fig/B3jtdJA7-6w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to php-fig+unsubscribe@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/4a693c4e-599e-45c3-b962-3397ee668df0%40googlegroups.com.
Rasmus,
I get where you are coming from here. On the one hand it makes a lot of sense and *appears* to greatly simplify things.
However, I'm not sure that it really does in the long term. Creating a dependency graph of middleware complicates things significantly at the injection level. We go from having a flat list of middleware to an arbitrarily (from execution standpoint) nested collection. This makes it nearly impossible to rely on reflection based injection, and it makes it harder to rearrange to order of middleware.
There's also the issue of constructor parameters... There is no guaranteed place in which the "next" will be placed. Since it is impossible to enforce constructors via interface this will mean inspecting each middleware to determine the correct parameter. Injection systems might be able to help here, but it will still be messy.
Overall I think going this route will make things more complicated, more coupled, and harder to explain.
Regards,
Woody
--
You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to php-fig+u...@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/d4483c85-4cea-41c2-b46b-9af86df9de63%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/php-fig/B3jtdJA7-6w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to php-fig+unsubscribe@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to php-fig+unsubscribe@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/d4483c85-4cea-41c2-b46b-9af86df9de63%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
--
You received this message because you are subscribed to a topic in the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/php-fig/B3jtdJA7-6w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to php-fig+unsubscribe@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/CAGOJM6%2BCFksT%3DndmbCqtskQLDfAawmP0R2XR9CtjMkPFibkB1w%40mail.gmail.com.
> This is Symfony's HttpKernelInterface and StackPHP and it has already been discussed at lengthSame principle, yes, but what I recall being discussed at length was the lambda-style vs double-pass aspect, which seems unrelated to this discussion.I found one or two older threads on this subject, here's one:The discussion quickly turns to the other, at the time dominant subject though.
> I'm not sure why we are starting it all again?Are you're saying all of the concerns I described here have been discussed and are all invalid?According to the PSR-15 meta:- "There are currently two common approaches to server middleware that use HTTP Messages", single-pass and double-pass.- There's no mention of the fact that HttpKernelInterface doesn't have the delegate in the interface.- The section on "Delegate Design" talks about the design of that interface, but doesn't say why it exists in the first place.I recall there being lengthy discussions about how to name and describe the delegate interface, but skimming back through the discussion threads that are listed in the meta, it seems that the discussions all start from the assumption that a middleware interface has the delegate argument.
--
You received this message because you are subscribed to a topic in the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/php-fig/B3jtdJA7-6w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to php-fig+unsubscribe@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/b8317921-172a-476c-9df7-5b47e1f089da%40googlegroups.com.
Hi Michael :-)> As a handler objects holds a reference to the next handler object, it is not reusable anymore.Well, the instance itself isn't "reusable" - but the code is, that's what matters, isn't it?
Callables in PHP are also objects, and a quick benchmark indicates literally no difference between a closure and an idempotent functional component - the creation overhead is more or less identical:
Middleware can be thought of as a function that takes a handler and wraps it in another handler to provide additional functionality.
interface RequestHandler {
function __invoke(ServerRequestInterface $request);
}
interface Middleware {
function __invoke(RequestHandler $handler) : RequestHandler;
}
--
You received this message because you are subscribed to a topic in the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/php-fig/B3jtdJA7-6w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to php-fig+unsubscribe@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/267f5a3d-2e5a-4db3-b41e-f90cdf149e37%40googlegroups.com.
- AFAIK it didn't work. And it was not tried in some weekend project: it was built on Symfony's interfaces, so pretty solid stuff and it got a good chance for success. On the other hand PSR-7 middlewares were incompatible with most of the existing architectures at the time (incompatible with Symfony for example) and without a standard interface (rather a "callable" convention) and it worked out! So to me that's a clear sign.
- it's harder to compose middlewares because they are all nested: the "pipe" pattern was a huge help IMO in spreading the concept
- it's harder to write reusable middlewares because you need to standardize the constructor (see the Stack "convention" about the constructor which is less than ideal)
- it's harder to wire in DI containers
- lazy middlewares are doable but not as easy
To unsubscribe from this group and all its topics, send an email to php-fig+u...@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To unsubscribe from this group and all its topics, send an email to php-fig+unsubscribe@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/b03dbdfc-8fb8-4e7a-9a5b-597fe22f0316%40googlegroups.com.
To unsubscribe from this group and all its topics, send an email to php-fig+unsubscribe@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/a1ec8661-2951-47f3-b377-d8a9c2d0557f%40googlegroups.com.
At the very least, we should standardize on a HandlerInterface, so that PSR-15 doesn't ship with an identical, incompatible interface for delegates.
At the very least, we should standardize on a HandlerInterface, so that PSR-15 doesn't ship with an identical, incompatible interface for delegates.I couldn’t agree more.
--
You received this message because you are subscribed to a topic in the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/php-fig/B3jtdJA7-6w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to php-fig+unsubscribe@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/bdefb246-cc43-4ae2-a703-25b8beb288f8%40googlegroups.com.
I've set aside friday to write a draft of the handler PSR. We'll see how FIG and the community responds and then work from there.
On Apr 25, 2017 22:44, "Michael Mayer" <mic...@schnittstabil.de> wrote:
--At the very least, we should standardize on a HandlerInterface, so that PSR-15 doesn't ship with an identical, incompatible interface for delegates.I couldn’t agree more.
You received this message because you are subscribed to a topic in the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/php-fig/B3jtdJA7-6w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to php-fig+u...@googlegroups.com.
To unsubscribe from this group and all its topics, send an email to php-fig+unsubscribe@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/95c1312a-138b-400c-b521-bae86931dc70%40googlegroups.com.
> How would the container know which $kernel to use in the constructor for the object at $id? This looks nice, API-wise, but it is ignoring how this object would actually be constructed.Of course this "skips the constructor part", that's what the DI container is for - if you're using one, that's where construction happens.
The current proposal doesn't deal with the creation of middleware either, only with the dispatch.So I'm not sure I follow.
> We used Stack Builder to help try and solve those problems. It still seemed messy and I was never very happy with it.That's pretty abstract, so can you point to (legacy) code or discussions, or illustrate with code examples maybe?
> email to php-fig+unsubscribe@googlegroups.com.
> To post to this group, send email to php...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/php-fig/674917bb-623a-4cea-b934-add8887acc65%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
--
Matthew Weier O'Phinney
mweiero...@gmail.com
https://mwop.net/
--
You received this message because you are subscribed to a topic in the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/php-fig/B3jtdJA7-6w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to php-fig+unsubscribe@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/CAJp_myWNHthoiYbcmCb51Dh%3DC7fpqaaHYSA8yJPijbU88xtx5g%40mail.gmail.com.
On 09/05/17 21:11, Rasmus Schultz wrote:
> I'd like to encourage anyone reading this to please post the biggest,
> most complex middleware stack they've ever used. Just the stack, not the
> implementations or individual component bootstrapping necessarily. Let's
> see what we're really dealing with?
--
You received this message because you are subscribed to a topic in the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/php-fig/B3jtdJA7-6w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to php-fig+unsubscribe@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/576da415-5830-4c83-a74a-ecb85bb40b34%40googlegroups.com.
What's a "non-response value"? You have "middleware" that doesn't return a Response object?
--
You received this message because you are subscribed to a topic in the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/php-fig/B3jtdJA7-6w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to php-fig+unsubscribe@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/CAP75ejOAWsUQkbW%2BkZDR9ZLUbbV0xA1Ky%3DDqdahi%3D%3DgLvP2ymA%40mail.gmail.com.
In my opinion, if a middleware component doesn't work when taken out of context from other middleware, or is dependent on related middleware and execution order etc., it's no longer middleware, strictly speaking - at that point, you're overloading the middleware mechanism with responsibilities that don't belong to that domain and don't naturally fit there.
--
You received this message because you are subscribed to a topic in the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/php-fig/B3jtdJA7-6w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to php-fig+unsubscribe@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/CAGOJM6%2BKW4nFeyMb07%3DGvY0C9nj9ChtrCe8cHLAiJJs%3DPwjd-w%40mail.gmail.com.
To unsubscribe from this group and all its topics, send an email to php-fig+u...@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To unsubscribe from this group and all its topics, send an email to php-fig+unsubscribe@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/3d95b640-8571-4937-91e7-30277b7a97cd%40googlegroups.com.
David,
What I don't underhand about your proposal is how a middleware that does not return a response would be implemented. For instance, a middleware that sets parsedBody?
I also don't understand how this would solve the DI concern. It looks like any middleware that wants to continue processing would need a reference to the next middleware factory, as in:
return $this->next->createMiddleware($this)->process($request);
Perhaps you could provide some implementation details to help me understand how this would work?
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/3d95b640-8571-4937-91e7-30277b7a97cd%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to php-fig+u...@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/CADqTB_gewQz6bfoVKUy1tNQVnHf0u%3DePezbnW-ubmEaewZQCBQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and all its topics, send an email to php-fig+unsubscribe@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.--To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/3d95b640-8571-4937-91e7-30277b7a97cd%40googlegroups.com.
You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to php-fig+unsubscribe@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/CADqTB_gewQz6bfoVKUy1tNQVnHf0u%3DePezbnW-ubmEaewZQCBQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
----
You received this message because you are subscribed to a topic in the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/php-fig/B3jtdJA7-6w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to php-fig+unsubscribe@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/CAGOJM6LqjaMGm3RxP9riUpZbjq-fhkMmgRaGCAvv3LKaYyv8mQ%40mail.gmail.com.
What do you mean by "middleware that does not return a response"?
--
You received this message because you are subscribed to a topic in the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/php-fig/B3jtdJA7-6w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to php-fig+unsubscribe@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/CAGOJM6%2Bx4KxbUs%2BAw%2B4RJWU4LPgV88kuFqB%3DQ-G_EHOmaa17yQ%40mail.gmail.com.
My question is more about how the interfaces proposed by David would do this delegation. Right now I don't see how it would be possible without passing a factory to a middleware, which (I thought) he was attempting to avoid.
interface RequestHandlerInterface
{
public function dispatch(ServerRequestInterface $request) : ResponseInterface;
}
interface Middleware {
function dispatch(RequestHandlerInterface $next) : RequestHandlerInterface;
}
class ResetParsedBody implements Middleware {
function dispatch(RequestHandlerInterface $next) : RequestHandlerInterface
{
return new class($next) implements RequestHandlerInterface {
private $next;
public function __construct(RequestHandlerInterface $next)
{
$this->next = $next;
}
public function dispatch(ServerRequestInterface $request) : ResponseInterface
{
return $this->next->dispatch($request->withParsedBody(null));
}
};
}
}
class UserIdMetadataEnrichment implements MiddlewareInterface
{
private $metadataEnricherChain;
private $userIdentityMapper;
public function __construct(
MetadataEnricherChain $metadataEnricherChain,
UserIdentityMapper $userIdentityMapper
)
{
$this->metadataEnricherChain = $metadataEnricherChain;
$this->userIdentityMapper = $userIdentityMapper;
}
public function __invoke(RequestInterface $request, DelegateInterface $delegate)
{
// ... do stuff
}
}
class UserIdMetadataEnrichmentFactory implements MiddlewareFactoryInterface
{
private $metadataEnricherChain;
private $userIdentityMapper;
public function __construct(
MetadataEnricherChain $metadataEnricherChain,
UserIdentityMapper $userIdentityMapper
)
{
$this->metadataEnricherChain = $metadataEnricherChain;
$this->userIdentityMapper = $userIdentityMapper;
}
public function createMiddleware(DelegateInterface $delegate)
{
return new UserIdMetadataEnrichment(
$delegate,
$this->metadataEnricherChain,
$this->userIdentityMapper
)
}
}
class UserIdMetadataEnrichment implements MiddlewareInterface
{
private $metadataEnricherChain;
private $userIdentityMapper;
private $delegate;
public function __construct(
DelegateInterface $delegate,
MetadataEnricherChain $metadataEnricherChain,
UserIdentityMapper $userIdentityMapper
)
{
$this->metadataEnricherChain = $metadataEnricherChain;
$this->userIdentityMapper = $userIdentityMapper;
$this->delegate = $delegate;
}
public function __invoke(RequestInterface $request)
{
// ... do stuff
}
}
--
You received this message because you are subscribed to a topic in the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/php-fig/B3jtdJA7-6w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to php-fig+unsubscribe@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/e9af0c97-575d-4a76-8e22-01275f7f37a2%40googlegroups.com.
> the middleware themselves cannot be autowired and must be created manually by the factory.Are you highlighting this as a problem?Of course the factory would need to create the middleware - that's what a factory is for. (?)
> At the end of the day it comes down to whether the delegate/next of a middleware should be a runtime dependency or an instance dependency. I think that is the core of what Rasmus is exploring here. It seems like he has decided it should not be a runtime dependencyI don't feel it's a decision so much as a conclusion.I'd like it not to be the case, because it would surely be simpler, but the fact is that there isn't always precisely one delegate - which leads me to conclude it can't be a runtime dependency, or at least not if you want the model to reflect reality, which is something I always strive for.
> I'm not happy about the idea that every middleware is going to effectively require two classes be writtenLet's explore that problem.I think, first of all, you need to not think of this as "middleware consisting of two classes" - it's really two different classes, one is a handler, the other is middleware: they have different purposes in different contexts.
If the only problem is deferring the loading and creation of handlers, and the issue is "not knowing" which constructor-argument is the delegate, maybe we could solve this by marking that argument somehow...
--
You received this message because you are subscribed to a topic in the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/php-fig/B3jtdJA7-6w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to php-fig+unsubscribe@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/a48f9e36-b994-419f-a35e-f721cc9475c1%40googlegroups.com.
To unsubscribe from this group and all its topics, send an email to php-fig+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/a48f9e36-b994-419f-a35e-f721cc9475c1%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to php-fig+u...@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/CADqTB_iisb8BXb4ww1TMNVeiJytAh%2BYeZm5hPm2PDOdrPRn9LQ%40mail.gmail.com.
To unsubscribe from this group and all its topics, send an email to php-fig+unsubscribe@googlegroups.com.
--To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/a48f9e36-b994-419f-a35e-f721cc9475c1%40googlegroups.com.
You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to php-fig+unsubscribe@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/CADqTB_iisb8BXb4ww1TMNVeiJytAh%2BYeZm5hPm2PDOdrPRn9LQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/php-fig/B3jtdJA7-6w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to php-fig+unsubscribe@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/CAFojS1sq5saNCvRWE%3Drj2Htki8hSJB4dys2xVpRwQm_ZfDsfjQ%40mail.gmail.com.
That is, PSR-15 should not define it's own DelegateInterface - we should have a general HandlerInterface instead, which will have a lot more uses, not least in the context of the current PSR-15 proposal as-is, where at least Dispatchers will be able to implement them, which provides an extra degree of high-level abstraction, which is currently missing from that proposal.
class Blog extends RouteGroup implements HandlerInterface
{
public function __construct()
{
$this->post('/comment', ContactPost::class);
// etc.
$this->add(SomeMiddleware::class);
}
}
// setup
$app->route('blog/*', new Blog()); // Blog would be typically installed via composer
$app = new … // either Slim or Expressive or what ever
$app->route('slim/*', $slimApp);
$app->route('expressive/*', $expressiveApp);
```php
$app->route('/api/blog', [
Authentication::class,
Authorization::class,
Blog::class,
], ['GET', 'POST']);
```
…
Now, does innermost middleware need to receive the delegate? No, but by having a
single interface to describe any link in the chain, versus two interfaces (one
for middleware that delegates, one for the final dispatched "things" --
controller, action, what have you), we simplify how application stacks/kernels
are built, as everything can be injected exactly the same.
--
You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to php-fig+u...@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/25371d15-a760-4716-a180-5a4ce5ee8308%40googlegroups.com.
The "Handler" shown in #6 is so generic as to be meaningless, or at least I don't know what it's supposed to do. It looks almost like it's trying to be a router, which is not the job of a middleware.
That said, the most compelling argument that's been made against the current PSR-15 draft is essentially "branching" the middleware logic. My question to Beau (or anyone from the PSR-15 team) would then be, how would the current draft handle that?
As a concrete example, say I want to apply:
- AuthenticationMiddleware only to paths /admin/*
- CacheMiddleware only to paths /api/*
- RouterMiddleware to all paths.
- ActionMiddleware to all paths, which is what calls out to a controller/action/app domain/thing.
Can we achieve the same by using only MiddlewareInterface and simply ignoring $next/$delegate? Matthew wrote:```php
$app->route('/api/blog', [
Authentication::class,
Authorization::class,
Blog::class,
], ['GET', 'POST']);
```
…
Now, does innermost middleware need to receive the delegate? No, but by having a
single interface to describe any link in the chain, versus two interfaces (one
for middleware that delegates, one for the final dispatched "things" --
controller, action, what have you), we simplify how application stacks/kernels
are built, as everything can be injected exactly the same.Honestly, I cannot image how implementing Blog::class as middleware would _simplify_ anything. Neither for applications nor for users.For applications it would be bad, because:1. if the stack runs empty, the application must provide a mechanism/convention to deal with that
2. the application must create a delegate object to call Blog::class, even if it is not usedFor users it would be bad, because:1. it is easy to misconfigure your stack: either by _forgetting_ to add Blog::class or by adding middlewares after Blog::class
2. it would be confusing if Blog::class is called with a $delegate, when it is not allowed to use it
If Blog::class implements HandlerInterface (or DelegateInterface) instead, then things will become simpler IMO:1. the stack can be verified earlier; thus the app can fail before creating middlewares or at least before Blog::class is called
2. the last Middleware will be called with the Blog::class as $next – no EmptyStackHandler/Delegate or similar is needed
--
You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to php-fig+unsubscribe@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/42102e4a-ffeb-46ce-aa51-b117dbf6975c%40googlegroups.com.
You received this message because you are subscribed to a topic in the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/php-fig/B3jtdJA7-6w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to php-fig+unsubscribe@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/CAGOJM6KFn4Gc3X7mLnvJp9c_fobmtMmcXj70ht7rWe05oHcJJw%40mail.gmail.com.
I think it's great that you're coming around to the idea, Woody :-)But I am no longer trying to view this as an alternative to PSR-15, because, assuming we standardize on that handler-interface first, there is nothing about PSR-15 that prevents us from exploring other options.
--
You received this message because you are subscribed to a topic in the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/php-fig/B3jtdJA7-6w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to php-fig+unsubscribe@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/b7a62479-e587-c7a7-7f1d-b5ddc3464a7d%40garfieldtech.com.
I think he was describing the other interfaces that are part of that proposal. (?)Since these aren't directly related to the problem at hand, and could be specified in a separate PSR, I'm rooting for a separate PSR for just the handler interface.
On May 17, 2017 19:03, "Larry Garfield" <la...@garfieldtech.com> wrote:
On 05/17/2017 09:40 AM, Beau Simensen wrote:--
On Wednesday, May 17, 2017 at 12:42:29 AM UTC-5, Rasmus Schultz wrote:I think it's great that you're coming around to the idea, Woody :-)
But I am no longer trying to view this as an alternative to PSR-15, because, assuming we standardize on that handler-interface first, there is nothing about PSR-15 that prevents us from exploring other options.
Indeed, if the end result of this discussion is extracting DelegateInterface into its own proposal as its own handler interface that can be used as the delegate in PSR-15, I'm happy with that.
I'm still a bit unclear on the "handler" as an uber-generic thing. Isn't that entirely separate from what Woody described, which is a 3-part pipeline? (Request modifiers, response modifiers, and request->response mappers.)
I admit the 3-part pipeline is appealing, and I've considered it before. I especially like that it keeps a shallower call stack. However, the problem is conditional request modifiers. Eg, an Auth modifier that may:
1) Add a user token to the request based on authentication.
2) Fail authentication and short circuit the entire pipeline with a 401/403 Response itself.
If the signature only allows returning a Request, then it can't do that. It has to be a nested mapper instead and do the delegate approach anyway. And if it's doing that anyway... what's the purpose of having the separate modifiers if they can't be used half the time anyway?
I'm afraid I'm still confused here about what is being proposed and what it solves...
--Larry Garfield
You received this message because you are subscribed to a topic in the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/php-fig/B3jtdJA7-6w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to php-fig+u...@googlegroups.com.
To unsubscribe from this group and all its topics, send an email to php-fig+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/d281d8b5-ce87-49c0-9b26-038dd9c27e07%40googlegroups.com.
This works perfectly well for simple systems and not so well for more complex systems. For instance, if we have a complex application where there is a "user" part and an "admin" part, the admin part needs a different sequence: […] Instead, the middleware becomes more of a tree structure
I can see the handler-interface having 3 uses in the context of PSR-15:
1. As the common interface of middleware dispatchers.
2. As the type-hint on delegates.
3. As type-hint for the "final" handler supported by many dispatchers.
Rasmus:
I can see the handler-interface having 3 uses in the context of PSR-15:
…
3. As type-hint for the "final" handler supported by many dispatchers.
3. I agree this is a bit of an ugly detail and it would be better if we could do without, but honestly this is just a detail, and it works, and it's not really a practical problem, I don't see how a PSR would matter here
// diff in pseudo code:
- function pipe(MiddlewareOrHandler[] stack) : Middleware {}
+ function pipe(Middleware[] stack, Handler $final) : Handler {}
- function router(array routes) : Middleware {}
+ function router(array routes) : Handler {}
$application = pipe([
ErrorHandlerMiddleware::class,
ForceHttpsMiddleware::class,
], prefix([
'/api/' => pipe([
HttpAuthenticationMiddleware::class,
], router([
'/api/articles' => /* controller */,
'/api/articles/{id}' => /* controller */,
])),
'/' => pipe([
MaintenanceModeMiddleware::class,
SessionMiddleware::class,
DebugBarMiddleware::class,
], router([
'/' => /* controller */,
'/article/{id}' => /* controller */,
])),
]));
And yes the router will be invoked with a $next, but IMO that's a good thing: the router can call $next if the URL doesn't match any route. That allows, for example, to use several routers in a single pipe (e.g. if you have modules).
And by the way this is a bit what Slim and IIRC Zend Expressive do: route handlers can be controllers or can be pipes, that's how you can add "route middlewares" (I hope I'm not wrong here).
$app->pipe('/', function (ServerRequestInterface $request, DelegateInterface $delegate) {
return $delegate->process($request);
});
$app->pipe('/', function (ServerRequestInterface $request, DelegateInterface $delegate) {
$response = new Response();
$response->getBody()->write('Wtf?');
return $response;
});
--
You received this message because you are subscribed to a topic in the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/php-fig/B3jtdJA7-6w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to php-fig+unsubscribe@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/9fb17b11-95da-4b42-9737-e4464b5c090f%40googlegroups.com.
You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to php-fig+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/CADqTB_iY4VBOkj5orto%3DTr51s668yMWwsxM0%2BKr8Yg7V6_vuaw%40mail.gmail.com.
On Saturday, May 20, 2017 at 10:33:33 PM UTC+2, Matthieu Napoli wrote:Rasmus:I can see the handler-interface having 3 uses in the context of PSR-15:
…
3. As type-hint for the "final" handler supported by many dispatchers.3. I agree this is a bit of an ugly detail and it would be better if we could do without, but honestly this is just a detail, and it works, and it's not really a practical problem, I don't see how a PSR would matter hereThat PSR would also allow interop of routers, controllers and final handlers, and indeed solve practical problems, e.g. if you use it with your pipe function:
// diff in pseudo code:
- function pipe(MiddlewareOrHandler[] stack) : Middleware {}
+ function pipe(Middleware[] stack, Handler $final) : Handler {}
- function router(array routes) : Middleware {}
+ function router(array routes) : Handler {}
Thus you do not need to fabricate handlers like the one at your Router::dispatch, and the code of your example becomes bit more explicit:
[…]
As you can see, there is no essential difference for the end user setup. Although, we do not need to create those meaningless $next delegates: the prefix and router functions return them.
And yes the router will be invoked with a $next, but IMO that's a good thing: the router can call $next if the URL doesn't match any route. That allows, for example, to use several routers in a single pipe (e.g. if you have modules).I disagree, that's not a good thing, this means $next would be used differently by different middlewares:For example for your HttpAuthenticationMiddleware, calling $next means: everything is fine; lets carry out the real task and if that fails I will try to handle that.For the router you're suggesting, calling $next means: something went wrong; lets delegate the task to someone else and if that fails I do not care.
And by the way this is a bit what Slim and IIRC Zend Expressive do: route handlers can be controllers or can be pipes, that's how you can add "route middlewares" (I hope I'm not wrong here).Slim controller actions are not middlewares, they get an $args argument instead of a $next.