Created
June 11, 2015 01:51
-
-
Save mtdowling/78560b586e39ab586bf0 to your computer and use it in GitHub Desktop.
Middlware
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Generic middleware that does not have to create a response. | |
$ringStyle = function(RequestInterface $request, callable $next) { | |
$request = $request->withHeader('Foo', 'Bar'); | |
$response = $next($request); | |
$response = $response->withHeader('Baz', 'Bam'); | |
return $response; | |
}; | |
// Intercept before calling next. | |
$intercept = function(RequestInterface $request, callable $next) use ($cache) { | |
if ($cache->hasRequest()) { | |
return $cache->getResponse($request); | |
} | |
return $next($request); | |
}; | |
// $next creates responses. But it's not a middleware. | |
$next = function(RequestInterface $request) { | |
return new Response(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment