8. Protocolo HTTP
Requisição
POST /path HTTP/1.1
Host: example.com
foo=bar&baz=bat
Processamento
Resposta
HTTP/1.1 200 OK
Content-Type: text/plain
This is the response body
9. PSR-7
<?php
namespace PsrHttpMessage;
interface MessageInterface
{
public function getProtocolVersion();
public function withProtocolVersion($version);
public function getHeaders();
public function hasHeader($name);
public function getHeader($name);
public function getHeaderLine($name);
public function withHeader($name, $value);
public function withAddedHeader($name, $value);
public function withoutHeader($name);
public function getBody();
public function withBody(StreamInterface $body);
}
10. PSR-7
<?php
namespace PsrHttpMessage;
interface RequestInterface extends MessageInterface
{
public function getRequestTarget();
public function withRequestTarget($requestTarget);
public function getMethod();
public function withMethod($method);
public function getUri();
public function withUri(UriInterface $uri, $preserveHost = false);
}
11. PSR-7
<?php
namespace PsrHttpMessage;
interface RequestInterface extends MessageInterface
{
public function getRequestTarget();
public function withRequestTarget($requestTarget);
public function getMethod();
public function withMethod($method);
public function getUri();
public function withUri(UriInterface $uri, $preserveHost = false);
}
<?php
namespace PsrHttpMessage;
interface ResponseInterface extends MessageInterface
{
public function getStatusCode();
public function withStatus($code, $reasonPhrase = ‘’);
public function getReasonPhrase();
}
14. Middlewares
Middleware é um código que existe entre a
requisição e a resposta, podendo receber uma
requisição e realizar ações baseadas nela,
como retornar uma resposta ou delegar para o
próximo middleware na fila.
Documentação do Zend Stratigility
(Tradução Livre)
“ ”
16. Stratigility
<?php
use ZendStratigilityMiddlewarePipe;
use ZendDiactorosServer;
require __DIR__ . ‘/../vendor/autoload.php’;
$app = new MiddlewarePipe();
$app->pipe(‘/’, function ($req, $res, $next) {
if (! in_array($req->getUri()->getPath(), [‘/’, ‘’], true)) {
return $next($req, $res);
}
return $res->end(‘Hello world!’);
});
$app->pipe(‘/foo’, function ($req, $res, $next) {
return $res->end(‘FOO!’);
});
17. Zend Expressive
O Zend Expressive é desenvolvido com base
no Zend Stratigility para prover um framework
minimalista de Middlewares PSR-7 em PHP
Documentação do Zend Stratigility
(Tradução Livre)
“ ”