SlideShare a Scribd company logo
Zend Expressive 3 PSR-15
PSR-15 Middleware in Minutes
Juciellen
Cabrera
PHP Developer - 4Linux | Rankdone
@jucycabrera
#PHPWomen
Zend Expressive 3 e PSR-15
Expressive
PSR-15 Middleware in Minutes
2018-03-16
>= PHP 7.1
Instalação
composer create-project zendframework/zend-expressive-skeleton expressive
requires
● php: ^7.1
● fig/http-message-util: ^1.1.2
● psr/container: ^1.0
● psr/http-message: ^1.0.1
● psr/http-server-middleware: ^1.0
● zendframework/zend-expressive-router: ^3.0
● zendframework/zend-expressive-template: ^2.0
● zendframework/zend-httphandlerrunner: ^1.0.1
● zendframework/zend-stratigility: ^3.0
[1] Minimal (no default middleware, templates, or
assets; configuration only)
[2] Flat (flat source code structure; default selection)
[3] Modular (modular source code structure;
recommended)
Zend Expressive 3 e PSR-15
Rotas
● Aura.Router
● Fast Router
● Zend Route
return function (Application $app, MiddlewareFactory $factory, ContainerInterface
$container) : void {
$app->get('/', AppActionHomePageAction::class, 'home');
$app->post('/album', AppActionAlbumCreateAction::class, 'album.create');
$app->put('/album/:id', AppActionAlbumUpdateAction::class, 'album.put');
$app->patch('/album/:id', AppActionAlbumUpdateAction::class, 'album.patch');
$app->delete('/album/:id', AppActionAlbumDeleteAction::class, 'album.delete');
$app->route('/contact', AppActionContactAction::class, ['GET', 'POST', ...], 'contact');
$app->any('/contact', AppActionContactAction::class)->setName('contact');
$app->route(
'/contact',
AppActionContactAction::class,
ZendExpressiveRouterRoute::HTTP_METHOD_ANY,
'contact'
);
Injeção de Dependência
[1] Aura.Di
[2] Pimple
[3] zend-servicemanager
[4] Auryn
[5] Symfony DI Container
Templates
[1] Plates
[2] Twig
[3] zend-view installs zend-servicemanager
[n] None of the above
Manipulação de erro
[1] Whoops
[n] None of the above
PSR-7
HTTP message interfaces
Interfaces de mensagens HTTP
HTTP messages are the foundation of web
development. Web browsers and HTTP
clients such as cURL create HTTP request messages
that are sent to a web server,
which provides an HTTP response message.
Mensagens HTTP são a base do desenvolvimento
web. Browsers e clients HTTP como cURL criam
mensagens de requisição HTTP que são enviadas
para um servidor web, que provisiona uma
mensagem de resposta HTTP.
Server-side code receives an HTTP
request message, and returns an HTTP response
message.
O código do lado do servidor recebe uma
mensagem de requisição HTTP e retorna uma
mensagem de resposta HTTP.
Interfaces
● MessageInterface.php
● RequestInterface.php
● ResponseInterface.php
● ServerRequestInterface.php
● StreamInterface.php
● UploadedFileInterface.php
● UriInterface.php
<?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);
}
PSR-15
A request handler is an individual component that
processes a request and
produces a response, as defined by PSR-7.
Um request handler (manipulador de requisição é
um componente individual que processa uma
requisição e produz uma resposta, como definido
pela PSR-7.
namespace PsrHttpServer;
use PsrHttpMessageResponseInterface;
use PsrHttpMessageServerRequestInterface;
interface RequestHandlerInterface
{
public function handle(ServerRequestInterface $request):
ResponseInterface;
}
namespace AppHandler;
use PsrHttpMessageResponseInterface;
use PsrHttpMessageServerRequestInterface;
use PsrHttpServerRequestHandlerInterface;
use ZendDiactorosResponseJsonResponse;
class PingHandler implements RequestHandlerInterface
{
public function handle(ServerRequestInterface $request) : ResponseInterface
{
return new JsonResponse(['ack' => time()]);
}
}
Middleware is any code sitting between a request
and a response.
Middleware é qualquer código entre a requisição e a
resposta.
Middlewares
● Authentication
● Authorization
● CORS
● Log
● Routing
namespace PsrHttpServer;
use PsrHttpMessageResponseInterface;
use PsrHttpMessageServerRequestInterface;
interface MiddlewareInterface
{
public function process(ServerRequestInterface $request,
RequestHandlerInterface $handler): ResponseInterface;
}
Pipeline
The terminology "pipeline" is often used to describe the
onion. One way of looking at the "onion" is as a queue
(FIFO). This means that the first middleware on the
queue is executed first, and this invokes the next.
A terminologia “pipeline” é frequentemente usada para
descrever uma cebola. Uma forma de olhar para a
cebola é como uma fila (FIFO). Isso significa que o
primeiro middleware da fila é executado primeiro e
invoca o próximo.
return function (Application $app, MiddlewareFactory $factory, ContainerInterface
$container) : void {
$app->pipe(ErrorHandler::class);
$app->pipe(ServerUrlMiddleware::class);
$app->pipe(RouteMiddleware::class);
$app->pipe(ImplicitHeadMiddleware::class);
$app->pipe(ImplicitOptionsMiddleware::class);
$app->pipe(MethodNotAllowedMiddleware::class);
$app->pipe(UrlHelperMiddleware::class);
$app->pipe(DispatchMiddleware::class);
$app->pipe(NotFoundHandler::class);
}
Command Line Tooling
composer expressive
handler:create
middleware:create
module:create
module:register
composer run --timeout=0 serve
composer expressive handler:create “AppHandlerPhpCommunitiesCreateHandler”
PhpCommunitiesCreateHandler
PhpCommunitiesCreateHandlerFactory
Referências
https://www.php-fig.org/psr/psr-7/
https://www.php-fig.org/psr/psr-15/
https://docs.zendframework.com/zend-expressive/v3/getting-started/quick-start/
https://framework.zend.com/blog/2018-03-16-expressive-3.html
https://packagist.org/packages/zendframework/zend-expressive
Obrigada!
@jucycabrera
jucarol17@gmail.com

More Related Content

ODP
PHP5.5 is Here
PDF
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHP
PDF
PHP Internals and Virtual Machine
PDF
The new features of PHP 7
PPTX
PHP7 Presentation
PPT
The Php Life Cycle
PPTX
Wykorzystanie form request przy implementacji API w Laravelu
KEY
Zend Framework Study@Tokyo #2
PHP5.5 is Here
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHP
PHP Internals and Virtual Machine
The new features of PHP 7
PHP7 Presentation
The Php Life Cycle
Wykorzystanie form request przy implementacji API w Laravelu
Zend Framework Study@Tokyo #2

What's hot (20)

PDF
Zend\Expressive - höher, schneller, weiter
PDF
Foomo / Zugspitze Presentation
PDF
Lumberjack XPath 101
PDF
Key features PHP 5.3 - 5.6
PPT
On UnQLite
PDF
Php engine
PPT
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
PDF
Quick tour of PHP from inside
ODP
PHP Tips for certification - OdW13
KEY
Zend Framework Study@Tokyo vol1
PDF
Diving into HHVM Extensions (PHPNW Conference 2015)
PPTX
Php 7 hhvm and co
PPTX
A new way to develop with WordPress!
KEY
Yapcasia2011 - Hello Embed Perl
KEY
Study2study#4 nginx conf_1_24
PPTX
RESTful API 제대로 만들기
PPT
Symfony2 Service Container: Inject me, my friend
PDF
Linux shell
PDF
Working with web_services
Zend\Expressive - höher, schneller, weiter
Foomo / Zugspitze Presentation
Lumberjack XPath 101
Key features PHP 5.3 - 5.6
On UnQLite
Php engine
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
Quick tour of PHP from inside
PHP Tips for certification - OdW13
Zend Framework Study@Tokyo vol1
Diving into HHVM Extensions (PHPNW Conference 2015)
Php 7 hhvm and co
A new way to develop with WordPress!
Yapcasia2011 - Hello Embed Perl
Study2study#4 nginx conf_1_24
RESTful API 제대로 만들기
Symfony2 Service Container: Inject me, my friend
Linux shell
Working with web_services
Ad

Similar to Zend Expressive 3 e PSR-15 (20)

PDF
Criando uma API com Zend Expressive 3
PDF
Zend/Expressive 3 – The Next Generation
PDF
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
PDF
Submit PHP: Standards in PHP world. Михайло Морозов
PPT
Zend Framework
PDF
Make your application expressive
PDF
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
PDF
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
PDF
Node js introduction
ODP
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
PPTX
Building Web Apps with Express
PDF
Using the new WordPress REST API
PPTX
Laravel5 Introduction and essentials
PPTX
PSR-7 - Middleware - Zend Expressive
PDF
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)
PPT
Hacking with hhvm
PDF
What's New In Laravel 5
PDF
Performance tuning with zend framework
PDF
PHP QA Tools
PDF
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Criando uma API com Zend Expressive 3
Zend/Expressive 3 – The Next Generation
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
Submit PHP: Standards in PHP world. Михайло Морозов
Zend Framework
Make your application expressive
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
Node js introduction
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
Building Web Apps with Express
Using the new WordPress REST API
Laravel5 Introduction and essentials
PSR-7 - Middleware - Zend Expressive
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)
Hacking with hhvm
What's New In Laravel 5
Performance tuning with zend framework
PHP QA Tools
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Ad

More from Juciellen Cabrera (7)

PDF
Refatoração - aquela caprichada no código
PDF
Does your code spark joy? Refactoring techniques to make your life easier.
PDF
Object Calisthenics em 10 minutos
PDF
Testes de API - Construindo uma suíte de testes para suas APIs
PDF
Slides Testes de API com Codeception
PDF
Php, por onde começar
PDF
Slides palestra codeception
Refatoração - aquela caprichada no código
Does your code spark joy? Refactoring techniques to make your life easier.
Object Calisthenics em 10 minutos
Testes de API - Construindo uma suíte de testes para suas APIs
Slides Testes de API com Codeception
Php, por onde começar
Slides palestra codeception

Recently uploaded (20)

PPTX
MYSQL Presentation for SQL database connectivity
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Machine learning based COVID-19 study performance prediction
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Empathic Computing: Creating Shared Understanding
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Spectroscopy.pptx food analysis technology
PPTX
Big Data Technologies - Introduction.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Cloud computing and distributed systems.
MYSQL Presentation for SQL database connectivity
Encapsulation_ Review paper, used for researhc scholars
Reach Out and Touch Someone: Haptics and Empathic Computing
The Rise and Fall of 3GPP – Time for a Sabbatical?
Mobile App Security Testing_ A Comprehensive Guide.pdf
Machine learning based COVID-19 study performance prediction
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Empathic Computing: Creating Shared Understanding
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
Network Security Unit 5.pdf for BCA BBA.
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Spectroscopy.pptx food analysis technology
Big Data Technologies - Introduction.pptx
Unlocking AI with Model Context Protocol (MCP)
Cloud computing and distributed systems.

Zend Expressive 3 e PSR-15