Zend Expressive in 15 Minutes

Chris Tankersley
Chris TankersleyPHP Programmer at Home
Zend Expressive in 15
Minutes
Chris Tankersley
@dragonmantank
NomadPHP, March 2016
NomadPHP, March 2016 1
Who Am I
• PHP Programmer for over 11 years
• Sysadmin/DevOps for around 9 years
• https://github.com/dragonmantank
• Author of “Docker for Developers”
• Reigning, Defending, Undisputed PHP
MTG Champion of the World
NomadPHP, March 2016 2
What is it?
NomadPHP, March 2016 3
It’s the Future! And Now!
• A Microframework
• Implements PSR-7
• Fully functional Middleware stack
• The beginnings of Zend Framework 3
NomadPHP, March 2016 4
The Microframework
NomadPHP, March 2016 5
The Microframework
• Lightweight wrapper around other libraries
• PSR-7 Compliant
• Supports multiple routers
• Supports multiple service locators
• Supports multiple templating systems
NomadPHP, March 2016 6
NomadPHP, March 2016 7
<?php
use ZendExpressiveAppFactory;
chdir(dirname(__DIR__));
require 'vendor/autoload.php';
$app = AppFactory::create();
$app->get('/', function ($request, $response, $next) {
$response->getBody()->write('Hello, world!');
return $response;
});
$app->pipeRoutingMiddleware();
$app->pipeDispatchMiddleware();
$app->run();
Not just for basic sites
• Provides support for Controllers, Dependency Injection, and
Templating
• Right now feels somewhere between a microframework and full stack
like ZF2 or symfony2
NomadPHP, March 2016 8
NomadPHP, March 2016 9
use PsrHttpMessageResponseInterface;
use PsrHttpMessageServerRequestInterface;
/**
* Renders out the homepage
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @param callable|null $next
*
* @return HtmlResponse
*/
public function __invoke(
ServerRequestInterface $request,
ResponseInterface $response,
callable $next = null)
{
return new HtmlResponse($this->template->render('index::homepage'));
}
PSR-7 Implementation
NomadPHP, March 2016 10
What is PSR-7?
• HTTP Message Interfaces
• Provides a consistent interface for HTTP requests and responses
• Allows multiple libraries to read and generate HTTP messages more
easily
NomadPHP, March 2016 11
NomadPHP, March 2016 12
<?php
use ZendExpressiveAppFactory;
chdir(dirname(__DIR__));
require 'vendor/autoload.php';
$app = AppFactory::create();
$app->get('/', function ($request, $response, $next) {
$response->getBody()->write('Hello, world!');
return $response;
});
$app->pipeRoutingMiddleware();
$app->pipeDispatchMiddleware();
$app->run();
NomadPHP, March 2016 13
use PsrHttpMessageResponseInterface;
use PsrHttpMessageServerRequestInterface;
/**
* Renders out the homepage
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @param callable|null $next
*
* @return HtmlResponse
*/
public function __invoke(
ServerRequestInterface $request,
ResponseInterface $response,
callable $next = null)
{
return new HtmlResponse($this->template->render('index::homepage'));
}
Middleware
NomadPHP, March 2016 14
Built around Middleware
• Middleware interacts with the Request and Response
• Can be used for things like authentication, authorization, session
handling… anything “application”-y
• Almost everything is middleware, even routes
NomadPHP, March 2016 15
NomadPHP, March 2016 16
class SessionMiddleware
{
protected $sessionContainer;
// ...
public function __invoke(
ServerRequestInterface $request,
ResponseInterface $response,
callable $next = null)
{
$request = $request
->withAttribute('session', $this->sessionContainer->getSession());
if ($next) {
return $next($request, $response);
}
return $response;
}
}
NomadPHP, March 2016 17
class SessionMiddleware
{
protected $sessionContainer;
// ...
public function __invoke(
ServerRequestInterface $request,
ResponseInterface $response,
callable $next = null)
{
$request = $request
->withAttribute('session', $this->sessionContainer->getSession());
if ($next) {
return $next($request, $response);
}
return $response;
}
}
NomadPHP, March 2016 18
class SessionMiddleware
{
protected $sessionContainer;
// ...
public function __invoke(
ServerRequestInterface $request,
ResponseInterface $response,
callable $next = null)
{
$request = $request
->withAttribute('session', $this->sessionContainer->getSession());
if ($next) {
return $next($request, $response);
}
return $response;
}
}
NomadPHP, March 2016 19
use PsrHttpMessageResponseInterface;
use PsrHttpMessageServerRequestInterface;
/**
* Renders out the homepage
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @param callable|null $next
*
* @return HtmlResponse
*/
public function __invoke(
ServerRequestInterface $request,
ResponseInterface $response,
callable $next = null)
{
return new HtmlResponse($this->template->render('index::homepage'));
}
Getting Started
NomadPHP, March 2016 20
Resources
• Documentation - https://zend-expressive.readthedocs.org/en/latest/
• Skeleton App - https://github.com/zendframework/zend-expressive-
skeleton
• My Demo App - https://github.com/dragonmantank/phparch-zend-
expressive
• Session Middleware -
https://github.com/dragonmantank/zendexpressive-session-
middleware
NomadPHP, March 2016 21
http://ctankersley.com
chris@ctankersley.com
@dragonmantank
https://joind.in/talk/d9813
NomadPHP, March 2016 22
1 of 22

Recommended

WTF Is Rancher? by
WTF Is Rancher?WTF Is Rancher?
WTF Is Rancher?Chris Tankersley
1.1K views11 slides
Getting Started With Aura by
Getting Started With AuraGetting Started With Aura
Getting Started With AuraChris Tankersley
977 views47 slides
Import golang; struct microservice - Codemotion Rome 2015 by
Import golang; struct microservice - Codemotion Rome 2015Import golang; struct microservice - Codemotion Rome 2015
Import golang; struct microservice - Codemotion Rome 2015Giorgio Cefaro
7K views70 slides
Docker for Developers - PHP Detroit 2018 by
Docker for Developers - PHP Detroit 2018Docker for Developers - PHP Detroit 2018
Docker for Developers - PHP Detroit 2018Chris Tankersley
865 views138 slides
Killer Docker Workflows for Development by
Killer Docker Workflows for DevelopmentKiller Docker Workflows for Development
Killer Docker Workflows for DevelopmentChris Tankersley
159 views64 slides
Plack perl superglue for web frameworks and servers by
Plack perl superglue for web frameworks and serversPlack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and serversTatsuhiko Miyagawa
6.7K views127 slides

More Related Content

What's hot

Docker for Developers - Sunshine PHP by
Docker for Developers - Sunshine PHPDocker for Developers - Sunshine PHP
Docker for Developers - Sunshine PHPChris Tankersley
812 views97 slides
Using PHP Functions! (Not those functions, Google Cloud Functions) by
Using PHP Functions! (Not those functions, Google Cloud Functions)Using PHP Functions! (Not those functions, Google Cloud Functions)
Using PHP Functions! (Not those functions, Google Cloud Functions)Chris Tankersley
177 views72 slides
Building Web Apps in Ratpack by
Building Web Apps in RatpackBuilding Web Apps in Ratpack
Building Web Apps in RatpackDaniel Woods
5.4K views30 slides
Docker for Developers - php[tek] 2017 by
Docker for Developers - php[tek] 2017Docker for Developers - php[tek] 2017
Docker for Developers - php[tek] 2017Chris Tankersley
1.1K views175 slides
Open shift intro for Philly PUG by
Open shift intro for Philly PUGOpen shift intro for Philly PUG
Open shift intro for Philly PUGSteven Pousty
385 views1 slide
Docker Workshop Birthday #3 by
Docker Workshop Birthday #3Docker Workshop Birthday #3
Docker Workshop Birthday #3Jirayut Nimsaeng
2K views53 slides

What's hot(20)

Docker for Developers - Sunshine PHP by Chris Tankersley
Docker for Developers - Sunshine PHPDocker for Developers - Sunshine PHP
Docker for Developers - Sunshine PHP
Chris Tankersley812 views
Using PHP Functions! (Not those functions, Google Cloud Functions) by Chris Tankersley
Using PHP Functions! (Not those functions, Google Cloud Functions)Using PHP Functions! (Not those functions, Google Cloud Functions)
Using PHP Functions! (Not those functions, Google Cloud Functions)
Chris Tankersley177 views
Building Web Apps in Ratpack by Daniel Woods
Building Web Apps in RatpackBuilding Web Apps in Ratpack
Building Web Apps in Ratpack
Daniel Woods5.4K views
Docker for Developers - php[tek] 2017 by Chris Tankersley
Docker for Developers - php[tek] 2017Docker for Developers - php[tek] 2017
Docker for Developers - php[tek] 2017
Chris Tankersley1.1K views
Open shift intro for Philly PUG by Steven Pousty
Open shift intro for Philly PUGOpen shift intro for Philly PUG
Open shift intro for Philly PUG
Steven Pousty385 views
Ratpack - Classy and Compact Groovy Web Apps by James Williams
Ratpack - Classy and Compact Groovy Web AppsRatpack - Classy and Compact Groovy Web Apps
Ratpack - Classy and Compact Groovy Web Apps
James Williams4.2K views
Building a desktop app with HTTP::Engine, SQLite and jQuery by Tatsuhiko Miyagawa
Building a desktop app with HTTP::Engine, SQLite and jQueryBuilding a desktop app with HTTP::Engine, SQLite and jQuery
Building a desktop app with HTTP::Engine, SQLite and jQuery
Tatsuhiko Miyagawa4.2K views
2017 DevSecCon ZAP Scripting Workshop by Simon Bennetts
2017 DevSecCon ZAP Scripting Workshop2017 DevSecCon ZAP Scripting Workshop
2017 DevSecCon ZAP Scripting Workshop
Simon Bennetts3.6K views
How to deploy PHP projects with docker by Ruoshi Ling
How to deploy PHP projects with dockerHow to deploy PHP projects with docker
How to deploy PHP projects with docker
Ruoshi Ling50.3K views
Large-scaled Deploy Over 100 Servers in 3 Minutes by Hiroshi SHIBATA
Large-scaled Deploy Over 100 Servers in 3 MinutesLarge-scaled Deploy Over 100 Servers in 3 Minutes
Large-scaled Deploy Over 100 Servers in 3 Minutes
Hiroshi SHIBATA3.8K views
Docker and DevOps --- new IT culture by Terry Chen
Docker and DevOps --- new IT cultureDocker and DevOps --- new IT culture
Docker and DevOps --- new IT culture
Terry Chen748 views
Lean Drupal Repositories with Composer and Drush by Pantheon
Lean Drupal Repositories with Composer and DrushLean Drupal Repositories with Composer and Drush
Lean Drupal Repositories with Composer and Drush
Pantheon1.6K views
Middleware as Code with mruby by Hiroshi SHIBATA
Middleware as Code with mrubyMiddleware as Code with mruby
Middleware as Code with mruby
Hiroshi SHIBATA5.2K views
Joomla Continuous Delivery with Docker by Jirayut Nimsaeng
Joomla Continuous Delivery with DockerJoomla Continuous Delivery with Docker
Joomla Continuous Delivery with Docker
Jirayut Nimsaeng7.7K views
DevOps tools for everyone - Vagrant, Puppet and Webmin by postrational
DevOps tools for everyone - Vagrant, Puppet and WebminDevOps tools for everyone - Vagrant, Puppet and Webmin
DevOps tools for everyone - Vagrant, Puppet and Webmin
postrational57K views
Using Apache Camel connectors for external connectivity by Claus Ibsen
Using Apache Camel connectors for external connectivityUsing Apache Camel connectors for external connectivity
Using Apache Camel connectors for external connectivity
Claus Ibsen6.1K views

Viewers also liked

Zend expressive workshop by
Zend expressive workshopZend expressive workshop
Zend expressive workshopAdam Culp
1.7K views81 slides
PSR-7 - Middleware - Zend Expressive by
PSR-7 - Middleware - Zend ExpressivePSR-7 - Middleware - Zend Expressive
PSR-7 - Middleware - Zend ExpressiveMilad Arabi
515 views44 slides
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016) by
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)James Titcumb
694 views78 slides
Palestra Linux Survival Kit para PHPeiros by
Palestra Linux Survival Kit para PHPeirosPalestra Linux Survival Kit para PHPeiros
Palestra Linux Survival Kit para PHPeirosLeonardo Tumadjian
733 views45 slides
Creating an API with Expressive by
Creating an API with ExpressiveCreating an API with Expressive
Creating an API with ExpressiveElton Minetto
4.9K views36 slides
Expressive Microservice Framework Blastoff by
Expressive Microservice Framework BlastoffExpressive Microservice Framework Blastoff
Expressive Microservice Framework BlastoffAdam Culp
1.6K views57 slides

Viewers also liked(7)

Zend expressive workshop by Adam Culp
Zend expressive workshopZend expressive workshop
Zend expressive workshop
Adam Culp1.7K views
PSR-7 - Middleware - Zend Expressive by Milad Arabi
PSR-7 - Middleware - Zend ExpressivePSR-7 - Middleware - Zend Expressive
PSR-7 - Middleware - Zend Expressive
Milad Arabi515 views
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016) by James Titcumb
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
James Titcumb694 views
Creating an API with Expressive by Elton Minetto
Creating an API with ExpressiveCreating an API with Expressive
Creating an API with Expressive
Elton Minetto4.9K views
Expressive Microservice Framework Blastoff by Adam Culp
Expressive Microservice Framework BlastoffExpressive Microservice Framework Blastoff
Expressive Microservice Framework Blastoff
Adam Culp1.6K views
Beyond The Browser - Creating a RESTful Web Service With WordPress by Christopher Reding
Beyond The Browser - Creating a RESTful Web Service With WordPressBeyond The Browser - Creating a RESTful Web Service With WordPress
Beyond The Browser - Creating a RESTful Web Service With WordPress
Christopher Reding6.3K views

Similar to Zend Expressive in 15 Minutes

Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016) by
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)James Titcumb
1.3K views78 slides
Developing web APIs using middleware in PHP 7 by
Developing web APIs using middleware in PHP 7Developing web APIs using middleware in PHP 7
Developing web APIs using middleware in PHP 7Zend by Rogue Wave Software
1.9K views27 slides
Using Sinatra to Build REST APIs in Ruby by
Using Sinatra to Build REST APIs in RubyUsing Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in RubyLaunchAny
9.5K views53 slides
Make your application expressive by
Make your application expressiveMake your application expressive
Make your application expressiveChristian Varela
745 views85 slides
PSGI and Plack from first principles by
PSGI and Plack from first principlesPSGI and Plack from first principles
PSGI and Plack from first principlesPerl Careers
2K views42 slides
Apache Dispatch by
Apache DispatchApache Dispatch
Apache DispatchFred Moyer
1.4K views27 slides

Similar to Zend Expressive in 15 Minutes(20)

Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016) by James Titcumb
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
James Titcumb1.3K views
Using Sinatra to Build REST APIs in Ruby by LaunchAny
Using Sinatra to Build REST APIs in RubyUsing Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in Ruby
LaunchAny9.5K views
PSGI and Plack from first principles by Perl Careers
PSGI and Plack from first principlesPSGI and Plack from first principles
PSGI and Plack from first principles
Perl Careers2K views
Apache Dispatch by Fred Moyer
Apache DispatchApache Dispatch
Apache Dispatch
Fred Moyer1.4K views
PHP by sometech
PHPPHP
PHP
sometech5.2K views
Node.js: CAMTA Presentation by Rob Tweed
Node.js: CAMTA PresentationNode.js: CAMTA Presentation
Node.js: CAMTA Presentation
Rob Tweed2.7K views
What's New In Laravel 5 by Darren Craig
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5
Darren Craig2.2K views
Ran Mizrahi - Symfony2 meets Drupal8 by Ran Mizrahi
Ran Mizrahi - Symfony2 meets Drupal8Ran Mizrahi - Symfony2 meets Drupal8
Ran Mizrahi - Symfony2 meets Drupal8
Ran Mizrahi2.7K views
PHP, RabbitMQ, and You by Jason Lotito
PHP, RabbitMQ, and YouPHP, RabbitMQ, and You
PHP, RabbitMQ, and You
Jason Lotito4.8K views
Using the new WordPress REST API by Caldera Labs
Using the new WordPress REST APIUsing the new WordPress REST API
Using the new WordPress REST API
Caldera Labs3.4K views
Supercharging WordPress Development in 2018 by Adam Tomat
Supercharging WordPress Development in 2018Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018
Adam Tomat212 views
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017) by James Titcumb
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)
James Titcumb483 views
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017) by James Titcumb
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
James Titcumb1.5K views

More from Chris Tankersley

Docker is Dead: Long Live Containers by
Docker is Dead: Long Live ContainersDocker is Dead: Long Live Containers
Docker is Dead: Long Live ContainersChris Tankersley
53 views52 slides
Bend time to your will with git by
Bend time to your will with gitBend time to your will with git
Bend time to your will with gitChris Tankersley
194 views73 slides
Dead Simple APIs with OpenAPI by
Dead Simple APIs with OpenAPIDead Simple APIs with OpenAPI
Dead Simple APIs with OpenAPIChris Tankersley
311 views63 slides
You Got Async in my PHP! by
You Got Async in my PHP!You Got Async in my PHP!
You Got Async in my PHP!Chris Tankersley
164 views140 slides
Docker for Developers by
Docker for DevelopersDocker for Developers
Docker for DevelopersChris Tankersley
934 views175 slides
They are Watching You by
They are Watching YouThey are Watching You
They are Watching YouChris Tankersley
286 views25 slides

More from Chris Tankersley(20)

BASHing at the CLI - Midwest PHP 2018 by Chris Tankersley
BASHing at the CLI - Midwest PHP 2018BASHing at the CLI - Midwest PHP 2018
BASHing at the CLI - Midwest PHP 2018
Chris Tankersley363 views
Docker for PHP Developers - php[world] 2017 by Chris Tankersley
Docker for PHP Developers - php[world] 2017Docker for PHP Developers - php[world] 2017
Docker for PHP Developers - php[world] 2017
Chris Tankersley821 views
Docker for PHP Developers - Madison PHP 2017 by Chris Tankersley
Docker for PHP Developers - Madison PHP 2017Docker for PHP Developers - Madison PHP 2017
Docker for PHP Developers - Madison PHP 2017
Chris Tankersley1.7K views
OOP Is More Then Cars and Dogs - Midwest PHP 2017 by Chris Tankersley
OOP Is More Then Cars and Dogs - Midwest PHP 2017OOP Is More Then Cars and Dogs - Midwest PHP 2017
OOP Is More Then Cars and Dogs - Midwest PHP 2017
Chris Tankersley608 views
From Docker to Production - SunshinePHP 2017 by Chris Tankersley
From Docker to Production - SunshinePHP 2017From Docker to Production - SunshinePHP 2017
From Docker to Production - SunshinePHP 2017
Chris Tankersley853 views
Coming to Terms with OOP In Drupal - php[world] 2016 by Chris Tankersley
Coming to Terms with OOP In Drupal - php[world] 2016Coming to Terms with OOP In Drupal - php[world] 2016
Coming to Terms with OOP In Drupal - php[world] 2016
Chris Tankersley387 views
How We Got Here: A Brief History of Open Source by Chris Tankersley
How We Got Here: A Brief History of Open SourceHow We Got Here: A Brief History of Open Source
How We Got Here: A Brief History of Open Source
Chris Tankersley382 views
Docker for PHP Developers - ZendCon 2016 by Chris Tankersley
Docker for PHP Developers - ZendCon 2016Docker for PHP Developers - ZendCon 2016
Docker for PHP Developers - ZendCon 2016
Chris Tankersley565 views
From Docker to Production - ZendCon 2016 by Chris Tankersley
From Docker to Production - ZendCon 2016From Docker to Production - ZendCon 2016
From Docker to Production - ZendCon 2016
Chris Tankersley399 views
Oh Crap, My Code is Slow - Madison PHP 2016 by Chris Tankersley
Oh Crap, My Code is Slow - Madison PHP 2016Oh Crap, My Code is Slow - Madison PHP 2016
Oh Crap, My Code is Slow - Madison PHP 2016
Chris Tankersley387 views
Docker for Developers - PNWPHP 2016 Workshop by Chris Tankersley
Docker for Developers - PNWPHP 2016 WorkshopDocker for Developers - PNWPHP 2016 Workshop
Docker for Developers - PNWPHP 2016 Workshop
Chris Tankersley686 views

Recently uploaded

Top 10 Strategic Technologies in 2024: AI and Automation by
Top 10 Strategic Technologies in 2024: AI and AutomationTop 10 Strategic Technologies in 2024: AI and Automation
Top 10 Strategic Technologies in 2024: AI and AutomationAutomationEdge Technologies
14 views14 slides
Java Platform Approach 1.0 - Picnic Meetup by
Java Platform Approach 1.0 - Picnic MeetupJava Platform Approach 1.0 - Picnic Meetup
Java Platform Approach 1.0 - Picnic MeetupRick Ossendrijver
25 views39 slides
Five Things You SHOULD Know About Postman by
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About PostmanPostman
27 views43 slides
The details of description: Techniques, tips, and tangents on alternative tex... by
The details of description: Techniques, tips, and tangents on alternative tex...The details of description: Techniques, tips, and tangents on alternative tex...
The details of description: Techniques, tips, and tangents on alternative tex...BookNet Canada
121 views24 slides
20231123_Camunda Meetup Vienna.pdf by
20231123_Camunda Meetup Vienna.pdf20231123_Camunda Meetup Vienna.pdf
20231123_Camunda Meetup Vienna.pdfPhactum Softwareentwicklung GmbH
28 views73 slides
AMAZON PRODUCT RESEARCH.pdf by
AMAZON PRODUCT RESEARCH.pdfAMAZON PRODUCT RESEARCH.pdf
AMAZON PRODUCT RESEARCH.pdfJerikkLaureta
15 views13 slides

Recently uploaded(20)

Five Things You SHOULD Know About Postman by Postman
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About Postman
Postman27 views
The details of description: Techniques, tips, and tangents on alternative tex... by BookNet Canada
The details of description: Techniques, tips, and tangents on alternative tex...The details of description: Techniques, tips, and tangents on alternative tex...
The details of description: Techniques, tips, and tangents on alternative tex...
BookNet Canada121 views
AMAZON PRODUCT RESEARCH.pdf by JerikkLaureta
AMAZON PRODUCT RESEARCH.pdfAMAZON PRODUCT RESEARCH.pdf
AMAZON PRODUCT RESEARCH.pdf
JerikkLaureta15 views
Voice Logger - Telephony Integration Solution at Aegis by Nirmal Sharma
Voice Logger - Telephony Integration Solution at AegisVoice Logger - Telephony Integration Solution at Aegis
Voice Logger - Telephony Integration Solution at Aegis
Nirmal Sharma17 views
SAP Automation Using Bar Code and FIORI.pdf by Virendra Rai, PMP
SAP Automation Using Bar Code and FIORI.pdfSAP Automation Using Bar Code and FIORI.pdf
SAP Automation Using Bar Code and FIORI.pdf
Future of Learning - Khoong Chan Meng by NUS-ISS
Future of Learning - Khoong Chan MengFuture of Learning - Khoong Chan Meng
Future of Learning - Khoong Chan Meng
NUS-ISS33 views
How the World's Leading Independent Automotive Distributor is Reinventing Its... by NUS-ISS
How the World's Leading Independent Automotive Distributor is Reinventing Its...How the World's Leading Independent Automotive Distributor is Reinventing Its...
How the World's Leading Independent Automotive Distributor is Reinventing Its...
NUS-ISS15 views
Attacking IoT Devices from a Web Perspective - Linux Day by Simone Onofri
Attacking IoT Devices from a Web Perspective - Linux Day Attacking IoT Devices from a Web Perspective - Linux Day
Attacking IoT Devices from a Web Perspective - Linux Day
Simone Onofri15 views
Empathic Computing: Delivering the Potential of the Metaverse by Mark Billinghurst
Empathic Computing: Delivering  the Potential of the MetaverseEmpathic Computing: Delivering  the Potential of the Metaverse
Empathic Computing: Delivering the Potential of the Metaverse
Mark Billinghurst470 views
Architecting CX Measurement Frameworks and Ensuring CX Metrics are fit for Pu... by NUS-ISS
Architecting CX Measurement Frameworks and Ensuring CX Metrics are fit for Pu...Architecting CX Measurement Frameworks and Ensuring CX Metrics are fit for Pu...
Architecting CX Measurement Frameworks and Ensuring CX Metrics are fit for Pu...
NUS-ISS37 views
DALI Basics Course 2023 by Ivory Egg
DALI Basics Course  2023DALI Basics Course  2023
DALI Basics Course 2023
Ivory Egg14 views
AI: mind, matter, meaning, metaphors, being, becoming, life values by Twain Liu 刘秋艳
AI: mind, matter, meaning, metaphors, being, becoming, life valuesAI: mind, matter, meaning, metaphors, being, becoming, life values
AI: mind, matter, meaning, metaphors, being, becoming, life values

Zend Expressive in 15 Minutes

  • 1. Zend Expressive in 15 Minutes Chris Tankersley @dragonmantank NomadPHP, March 2016 NomadPHP, March 2016 1
  • 2. Who Am I • PHP Programmer for over 11 years • Sysadmin/DevOps for around 9 years • https://github.com/dragonmantank • Author of “Docker for Developers” • Reigning, Defending, Undisputed PHP MTG Champion of the World NomadPHP, March 2016 2
  • 3. What is it? NomadPHP, March 2016 3
  • 4. It’s the Future! And Now! • A Microframework • Implements PSR-7 • Fully functional Middleware stack • The beginnings of Zend Framework 3 NomadPHP, March 2016 4
  • 6. The Microframework • Lightweight wrapper around other libraries • PSR-7 Compliant • Supports multiple routers • Supports multiple service locators • Supports multiple templating systems NomadPHP, March 2016 6
  • 7. NomadPHP, March 2016 7 <?php use ZendExpressiveAppFactory; chdir(dirname(__DIR__)); require 'vendor/autoload.php'; $app = AppFactory::create(); $app->get('/', function ($request, $response, $next) { $response->getBody()->write('Hello, world!'); return $response; }); $app->pipeRoutingMiddleware(); $app->pipeDispatchMiddleware(); $app->run();
  • 8. Not just for basic sites • Provides support for Controllers, Dependency Injection, and Templating • Right now feels somewhere between a microframework and full stack like ZF2 or symfony2 NomadPHP, March 2016 8
  • 9. NomadPHP, March 2016 9 use PsrHttpMessageResponseInterface; use PsrHttpMessageServerRequestInterface; /** * Renders out the homepage * * @param ServerRequestInterface $request * @param ResponseInterface $response * @param callable|null $next * * @return HtmlResponse */ public function __invoke( ServerRequestInterface $request, ResponseInterface $response, callable $next = null) { return new HtmlResponse($this->template->render('index::homepage')); }
  • 11. What is PSR-7? • HTTP Message Interfaces • Provides a consistent interface for HTTP requests and responses • Allows multiple libraries to read and generate HTTP messages more easily NomadPHP, March 2016 11
  • 12. NomadPHP, March 2016 12 <?php use ZendExpressiveAppFactory; chdir(dirname(__DIR__)); require 'vendor/autoload.php'; $app = AppFactory::create(); $app->get('/', function ($request, $response, $next) { $response->getBody()->write('Hello, world!'); return $response; }); $app->pipeRoutingMiddleware(); $app->pipeDispatchMiddleware(); $app->run();
  • 13. NomadPHP, March 2016 13 use PsrHttpMessageResponseInterface; use PsrHttpMessageServerRequestInterface; /** * Renders out the homepage * * @param ServerRequestInterface $request * @param ResponseInterface $response * @param callable|null $next * * @return HtmlResponse */ public function __invoke( ServerRequestInterface $request, ResponseInterface $response, callable $next = null) { return new HtmlResponse($this->template->render('index::homepage')); }
  • 15. Built around Middleware • Middleware interacts with the Request and Response • Can be used for things like authentication, authorization, session handling… anything “application”-y • Almost everything is middleware, even routes NomadPHP, March 2016 15
  • 16. NomadPHP, March 2016 16 class SessionMiddleware { protected $sessionContainer; // ... public function __invoke( ServerRequestInterface $request, ResponseInterface $response, callable $next = null) { $request = $request ->withAttribute('session', $this->sessionContainer->getSession()); if ($next) { return $next($request, $response); } return $response; } }
  • 17. NomadPHP, March 2016 17 class SessionMiddleware { protected $sessionContainer; // ... public function __invoke( ServerRequestInterface $request, ResponseInterface $response, callable $next = null) { $request = $request ->withAttribute('session', $this->sessionContainer->getSession()); if ($next) { return $next($request, $response); } return $response; } }
  • 18. NomadPHP, March 2016 18 class SessionMiddleware { protected $sessionContainer; // ... public function __invoke( ServerRequestInterface $request, ResponseInterface $response, callable $next = null) { $request = $request ->withAttribute('session', $this->sessionContainer->getSession()); if ($next) { return $next($request, $response); } return $response; } }
  • 19. NomadPHP, March 2016 19 use PsrHttpMessageResponseInterface; use PsrHttpMessageServerRequestInterface; /** * Renders out the homepage * * @param ServerRequestInterface $request * @param ResponseInterface $response * @param callable|null $next * * @return HtmlResponse */ public function __invoke( ServerRequestInterface $request, ResponseInterface $response, callable $next = null) { return new HtmlResponse($this->template->render('index::homepage')); }
  • 21. Resources • Documentation - https://zend-expressive.readthedocs.org/en/latest/ • Skeleton App - https://github.com/zendframework/zend-expressive- skeleton • My Demo App - https://github.com/dragonmantank/phparch-zend- expressive • Session Middleware - https://github.com/dragonmantank/zendexpressive-session- middleware NomadPHP, March 2016 21