Skip to content

Instantly share code, notes, and snippets.

@mtdowling
Created June 11, 2015 01:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mtdowling/78560b586e39ab586bf0 to your computer and use it in GitHub Desktop.
Save mtdowling/78560b586e39ab586bf0 to your computer and use it in GitHub Desktop.
Middlware
<?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