<?php
use Radar\Adr\Boot;use Zend\Diactoros\Response as Response;
require '../vendor/autoload.php';
$boot = new Boot();$adr = $boot->adr();
/** * Middleware */
$adr->middle(function ($request, $response, callable $next) {
$response = $response->withStatus(403, 'You need to login');
return $response;});
<?php
use Radar\Adr\Boot;
use Relay\Middleware\ResponseSender;
use Zend\Diactoros\Response as Response;
use Zend\Diactoros\ServerRequestFactory as ServerRequestFactory;
require '../vendor/autoload.php';
$boot = new Boot();
$adr = $boot->adr();
$adr->middle(new ResponseSender());
$adr->middle(function ($request, $response, callable $next) {
$response = $response->withStatus(403, 'You need to login');
return $response;
});
$adr->run(ServerRequestFactory::fromGlobals(), new Response());
$adr->get('foo', '/foo', '\Foo') ->responder('\HtmlResponder');
$adr->get('bar', '/bar', '\Bar') ->responder('\HtmlResponder');
$adr->get('generic', '{/controller,action,id}', '\Clx\ClientList') ->responder('\HtmlResponder');
> On Oct 2, 2015, at 08:58, Chris Johnson <cxjo...@gmail.com> wrote:
>
> How do I get the same result as your sample code, when I have routing to multiple Actions and Responders?
As long as your 403 handler is in the stack *before* the RoutingHandler, it should take precedence over any routing.
Hi Chris.
You should be able to invoke your responder right there in the middleware, I think. You’ll need to also create a payload instance, and pass that along when you invoke the responder. Something along these lines should work:
$adr->middle(function ($request, $response, callable $next) {
if (! /* auth credentials detected */) { $payload = new Aura\Payload\Payload(); $payload = $payload ->setStatus($payload::NOT_AUTHENTICATED) ->setMessages('You need to login');
$responder = new Your\HtmlResponder(); return $responder($request, $response, $payload); }
return $next($request, $response);});
Note that if your middleware is a class rather than a lambda, you should be able to configure the container to inject the payload and responder instances rather than creating them inline. I do not think this approach is unreasonable, even if it is a departure from the usual way of ADR. What do you think?
--rocco
--
You received this message because you are subscribed to a topic in the Google Groups "The Aura Project for PHP" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/auraphp/xbRC8RZQfHk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to auraphp+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.