Mac OS X 10.14; rv:63.0) Gecko/20100101 Firefox/63.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-GB,en;q=0.5 Accept-Encoding: gzip, deflate, br Connection: keep-alive If-Modified-Since: Mon, 04 Nov 2018 16:21:02 GMT Cache-Control: max-age=0 Rob Allen ~ @akrabat
$response = $response->withHeader('Location', 'http://example.com'); // or $response = new Response(); $response = $response->withStatus(302) ->withHeader('Location', 'http://example.com'); Rob Allen ~ @akrabat
->withHeader('Content-Type', 'application/html') ->withBody($body); Mitigate: Use read-only streams for server requests and client responses Rob Allen ~ @akrabat
the next // component 1 function findCountry($request) { $country = $this->geoLocate($request); $request = $request->withAttribute('country', $country); return $request; } // In an action method function listAction($request, $response, $args) { $country = $request->getAttribute('country'); // do something now that we know the country } Rob Allen ~ @akrabat
ResponseInterface { // do something before // call down the chain to the next middleware if ($next) { $response = $next($request, $response); } // do something with $response after return $response; } Rob Allen ~ @akrabat
ResponseInterface { // do something before // call down the chain to the next middleware if ($next) { $response = $next($request, $response); } // do something with $response after return $response; } Rob Allen ~ @akrabat
ResponseInterface { // do something before // call down the chain to the next middleware if ($next) { $response = $next($request, $response); } // do something with $response after return $response; } Rob Allen ~ @akrabat
ResponseInterface { // do something before // call down the chain to the next middleware if ($next) { $response = $next($request, $response); } // do something with $response after return $response; } Rob Allen ~ @akrabat
ResponseInterface { // do something before // call down the chain to the next middleware if ($next) { $response = $next($request, $response); } // do something with $response after return $response; } Rob Allen ~ @akrabat
one middleware to the next class IpAddress { public function __invoke($request, $response, $next) { $ipAddress = $this->determineClientIpAddress($request); $request = $request->withAttribute('ip_address', $ipAddress); return $response = $next($request, $response); } // full source: github.com/akrabat/ip-address-middleware } Rob Allen ~ @akrabat
one middleware to the next class IpAddressMiddleware { public function __invoke($request, $response, $next) { $ipAddress = $this->determineClientIpAddress($request); $request = $request->withAttribute('ip_address', $ipAddress); return $response = $next($request, $response); } // full source: github.com/akrabat/ip-address-middleware } Rob Allen ~ @akrabat
one middleware to the next class IpAddressMiddleware { public function __invoke($request, $response, $next) { $ipAddress = $this->determineClientIpAddress($request); $request = $request->withAttribute('ip_address', $ipAddress); return $response = $next($request, $response); } // full source: github.com/akrabat/ip-address-middleware } Rob Allen ~ @akrabat
one middleware to the next class IpAddressMiddleware { public function __invoke($request, $response, $next) { $ipAddress = $this->determineClientIpAddress($request); $request = $request->withAttribute('ip_address', $ipAddress); return $response = $next($request, $response); } // full source: github.com/akrabat/ip-address-middleware } Rob Allen ~ @akrabat
one middleware to the next class IpAddressMiddleware { public function __invoke($request, $response, $next) { $ipAddress = $this->determineClientIpAddress($request); $request = $request->withAttribute('ip_address', $ipAddress); return $response = $next($request, $response); } // full source: github.com/akrabat/ip-address-middleware } Rob Allen ~ @akrabat
class HomePageHandler implements RequestHandlerInterface { public function handle(ServerRequestInterface $request) : ResponseInterface { return new HtmlResponse( '<p>Hello World</p>' ); } } Rob Allen ~ @akrabat
class HomePageHandler implements RequestHandlerInterface { public function handle(ServerRequestInterface $request) : ResponseInterface { return new HtmlResponse( '<p>Hello World</p>' ); } } Rob Allen ~ @akrabat
class HomePageHandler implements RequestHandlerInterface { public function handle(ServerRequestInterface $request) : ResponseInterface { return new HtmlResponse( '<p>Hello World</p>' ); } } Rob Allen ~ @akrabat
$app->add(IpAddress::class); // add routes $app->get('/', App\Action\HomePageAction::class); $app->get('/api/ping', 'App\Controller\ApiController:pingAction'); // run $app->run(); Rob Allen ~ @akrabat