SlideShare a Scribd company logo
1 of 22
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

More Related Content

What's hot

Docker for Developers - Sunshine PHP
Docker for Developers - Sunshine PHPDocker for Developers - Sunshine PHP
Docker for Developers - Sunshine PHPChris 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)
Using PHP Functions! (Not those functions, Google Cloud Functions)Chris Tankersley
 
Building Web Apps in Ratpack
Building Web Apps in RatpackBuilding Web Apps in Ratpack
Building Web Apps in RatpackDaniel Woods
 
Docker for Developers - php[tek] 2017
Docker for Developers - php[tek] 2017Docker for Developers - php[tek] 2017
Docker for Developers - php[tek] 2017Chris Tankersley
 
Open shift intro for Philly PUG
Open shift intro for Philly PUGOpen shift intro for Philly PUG
Open shift intro for Philly PUGSteven Pousty
 
Docker Workshop Birthday #3
Docker Workshop Birthday #3Docker Workshop Birthday #3
Docker Workshop Birthday #3Jirayut Nimsaeng
 
Ratpack - Classy and Compact Groovy Web Apps
Ratpack - Classy and Compact Groovy Web AppsRatpack - Classy and Compact Groovy Web Apps
Ratpack - Classy and Compact Groovy Web AppsJames Williams
 
Building a desktop app with HTTP::Engine, SQLite and jQuery
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 jQueryTatsuhiko Miyagawa
 
2017 DevSecCon ZAP Scripting Workshop
2017 DevSecCon ZAP Scripting Workshop2017 DevSecCon ZAP Scripting Workshop
2017 DevSecCon ZAP Scripting WorkshopSimon Bennetts
 
How to deploy PHP projects with docker
How to deploy PHP projects with dockerHow to deploy PHP projects with docker
How to deploy PHP projects with dockerRuoshi Ling
 
Large-scaled Deploy Over 100 Servers in 3 Minutes
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 MinutesHiroshi SHIBATA
 
Docker and DevOps --- new IT culture
Docker and DevOps --- new IT cultureDocker and DevOps --- new IT culture
Docker and DevOps --- new IT cultureTerry Chen
 
Lean Drupal Repositories with Composer and Drush
Lean Drupal Repositories with Composer and DrushLean Drupal Repositories with Composer and Drush
Lean Drupal Repositories with Composer and DrushPantheon
 
Middleware as Code with mruby
Middleware as Code with mrubyMiddleware as Code with mruby
Middleware as Code with mrubyHiroshi SHIBATA
 
Joomla Continuous Delivery with Docker
Joomla Continuous Delivery with DockerJoomla Continuous Delivery with Docker
Joomla Continuous Delivery with DockerJirayut Nimsaeng
 
DevOps tools for everyone - Vagrant, Puppet and Webmin
DevOps tools for everyone - Vagrant, Puppet and WebminDevOps tools for everyone - Vagrant, Puppet and Webmin
DevOps tools for everyone - Vagrant, Puppet and Webminpostrational
 
Using Apache Camel connectors for external connectivity
Using Apache Camel connectors for external connectivityUsing Apache Camel connectors for external connectivity
Using Apache Camel connectors for external connectivityClaus Ibsen
 

What's hot (20)

Docker for Developers - Sunshine PHP
Docker for Developers - Sunshine PHPDocker for Developers - Sunshine PHP
Docker for Developers - Sunshine PHP
 
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)
Using PHP Functions! (Not those functions, Google Cloud Functions)
 
Building Web Apps in Ratpack
Building Web Apps in RatpackBuilding Web Apps in Ratpack
Building Web Apps in Ratpack
 
Docker for Developers - php[tek] 2017
Docker for Developers - php[tek] 2017Docker for Developers - php[tek] 2017
Docker for Developers - php[tek] 2017
 
Open shift intro for Philly PUG
Open shift intro for Philly PUGOpen shift intro for Philly PUG
Open shift intro for Philly PUG
 
Docker Workshop Birthday #3
Docker Workshop Birthday #3Docker Workshop Birthday #3
Docker Workshop Birthday #3
 
Plack at OSCON 2010
Plack at OSCON 2010Plack at OSCON 2010
Plack at OSCON 2010
 
Ratpack - Classy and Compact Groovy Web Apps
Ratpack - Classy and Compact Groovy Web AppsRatpack - Classy and Compact Groovy Web Apps
Ratpack - Classy and Compact Groovy Web Apps
 
Building a desktop app with HTTP::Engine, SQLite and jQuery
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
 
Plack at YAPC::NA 2010
Plack at YAPC::NA 2010Plack at YAPC::NA 2010
Plack at YAPC::NA 2010
 
2017 DevSecCon ZAP Scripting Workshop
2017 DevSecCon ZAP Scripting Workshop2017 DevSecCon ZAP Scripting Workshop
2017 DevSecCon ZAP Scripting Workshop
 
How to deploy PHP projects with docker
How to deploy PHP projects with dockerHow to deploy PHP projects with docker
How to deploy PHP projects with docker
 
Large-scaled Deploy Over 100 Servers in 3 Minutes
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
 
Docker and DevOps --- new IT culture
Docker and DevOps --- new IT cultureDocker and DevOps --- new IT culture
Docker and DevOps --- new IT culture
 
Lean Drupal Repositories with Composer and Drush
Lean Drupal Repositories with Composer and DrushLean Drupal Repositories with Composer and Drush
Lean Drupal Repositories with Composer and Drush
 
Middleware as Code with mruby
Middleware as Code with mrubyMiddleware as Code with mruby
Middleware as Code with mruby
 
Joomla Continuous Delivery with Docker
Joomla Continuous Delivery with DockerJoomla Continuous Delivery with Docker
Joomla Continuous Delivery with Docker
 
DevOps tools for everyone - Vagrant, Puppet and Webmin
DevOps tools for everyone - Vagrant, Puppet and WebminDevOps tools for everyone - Vagrant, Puppet and Webmin
DevOps tools for everyone - Vagrant, Puppet and Webmin
 
Ratpack JVM_MX Meetup February 2016
Ratpack JVM_MX Meetup February 2016Ratpack JVM_MX Meetup February 2016
Ratpack JVM_MX Meetup February 2016
 
Using Apache Camel connectors for external connectivity
Using Apache Camel connectors for external connectivityUsing Apache Camel connectors for external connectivity
Using Apache Camel connectors for external connectivity
 

Viewers also liked

Zend expressive workshop
Zend expressive workshopZend expressive workshop
Zend expressive workshopAdam Culp
 
PSR-7 - Middleware - Zend Expressive
PSR-7 - Middleware - Zend ExpressivePSR-7 - Middleware - Zend Expressive
PSR-7 - Middleware - Zend ExpressiveMilad Arabi
 
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)
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)James Titcumb
 
Palestra Linux Survival Kit para PHPeiros
Palestra Linux Survival Kit para PHPeirosPalestra Linux Survival Kit para PHPeiros
Palestra Linux Survival Kit para PHPeirosLeonardo Tumadjian
 
Creating an API with Expressive
Creating an API with ExpressiveCreating an API with Expressive
Creating an API with ExpressiveElton Minetto
 
Expressive Microservice Framework Blastoff
Expressive Microservice Framework BlastoffExpressive Microservice Framework Blastoff
Expressive Microservice Framework BlastoffAdam Culp
 
Beyond The Browser - Creating a RESTful Web Service With WordPress
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 WordPressChristopher Reding
 

Viewers also liked (7)

Zend expressive workshop
Zend expressive workshopZend expressive workshop
Zend expressive workshop
 
PSR-7 - Middleware - Zend Expressive
PSR-7 - Middleware - Zend ExpressivePSR-7 - Middleware - Zend Expressive
PSR-7 - Middleware - Zend Expressive
 
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)
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
 
Palestra Linux Survival Kit para PHPeiros
Palestra Linux Survival Kit para PHPeirosPalestra Linux Survival Kit para PHPeiros
Palestra Linux Survival Kit para PHPeiros
 
Creating an API with Expressive
Creating an API with ExpressiveCreating an API with Expressive
Creating an API with Expressive
 
Expressive Microservice Framework Blastoff
Expressive Microservice Framework BlastoffExpressive Microservice Framework Blastoff
Expressive Microservice Framework Blastoff
 
Beyond The Browser - Creating a RESTful Web Service With WordPress
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
 

Similar to Zend Expressive in 15 Minutes

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)
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)James Titcumb
 
Using Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in RubyUsing Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in RubyLaunchAny
 
Make your application expressive
Make your application expressiveMake your application expressive
Make your application expressiveChristian Varela
 
PSGI and Plack from first principles
PSGI and Plack from first principlesPSGI and Plack from first principles
PSGI and Plack from first principlesPerl Careers
 
Apache Dispatch
Apache DispatchApache Dispatch
Apache DispatchFred Moyer
 
Node.js: CAMTA Presentation
Node.js: CAMTA PresentationNode.js: CAMTA Presentation
Node.js: CAMTA PresentationRob Tweed
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5Darren Craig
 
Ran Mizrahi - Symfony2 meets Drupal8
Ran Mizrahi - Symfony2 meets Drupal8Ran Mizrahi - Symfony2 meets Drupal8
Ran Mizrahi - Symfony2 meets Drupal8Ran Mizrahi
 
PHP, RabbitMQ, and You
PHP, RabbitMQ, and YouPHP, RabbitMQ, and You
PHP, RabbitMQ, and YouJason Lotito
 
Using the new WordPress REST API
Using the new WordPress REST APIUsing the new WordPress REST API
Using the new WordPress REST APICaldera Labs
 
Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018Adam Tomat
 
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)
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)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)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)James Titcumb
 
Speed up web APIs with Expressive and Swoole (PHP Day 2018)
Speed up web APIs with Expressive and Swoole (PHP Day 2018) Speed up web APIs with Expressive and Swoole (PHP Day 2018)
Speed up web APIs with Expressive and Swoole (PHP Day 2018) Zend by Rogue Wave Software
 

Similar to Zend Expressive in 15 Minutes (20)

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)
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
 
Developing web APIs using middleware in PHP 7
Developing web APIs using middleware in PHP 7Developing web APIs using middleware in PHP 7
Developing web APIs using middleware in PHP 7
 
Using Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in RubyUsing Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in Ruby
 
Make your application expressive
Make your application expressiveMake your application expressive
Make your application expressive
 
PSGI and Plack from first principles
PSGI and Plack from first principlesPSGI and Plack from first principles
PSGI and Plack from first principles
 
Apache Dispatch
Apache DispatchApache Dispatch
Apache Dispatch
 
PHP
PHPPHP
PHP
 
Node.js: CAMTA Presentation
Node.js: CAMTA PresentationNode.js: CAMTA Presentation
Node.js: CAMTA Presentation
 
PHP Development Tools
PHP  Development ToolsPHP  Development Tools
PHP Development Tools
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5
 
Ran Mizrahi - Symfony2 meets Drupal8
Ran Mizrahi - Symfony2 meets Drupal8Ran Mizrahi - Symfony2 meets Drupal8
Ran Mizrahi - Symfony2 meets Drupal8
 
PHP, RabbitMQ, and You
PHP, RabbitMQ, and YouPHP, RabbitMQ, and You
PHP, RabbitMQ, and You
 
Zend Expressive 3 e PSR-15
Zend Expressive 3 e PSR-15Zend Expressive 3 e PSR-15
Zend Expressive 3 e PSR-15
 
Using the new WordPress REST API
Using the new WordPress REST APIUsing the new WordPress REST API
Using the new WordPress REST API
 
Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018
 
Laravel level 0 (introduction)
Laravel level 0 (introduction)Laravel level 0 (introduction)
Laravel level 0 (introduction)
 
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)
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)
 
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)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
 
PSGI/Plack OSDC.TW
PSGI/Plack OSDC.TWPSGI/Plack OSDC.TW
PSGI/Plack OSDC.TW
 
Speed up web APIs with Expressive and Swoole (PHP Day 2018)
Speed up web APIs with Expressive and Swoole (PHP Day 2018) Speed up web APIs with Expressive and Swoole (PHP Day 2018)
Speed up web APIs with Expressive and Swoole (PHP Day 2018)
 

More from Chris Tankersley

Docker is Dead: Long Live Containers
Docker is Dead: Long Live ContainersDocker is Dead: Long Live Containers
Docker is Dead: Long Live ContainersChris Tankersley
 
Bend time to your will with git
Bend time to your will with gitBend time to your will with git
Bend time to your will with gitChris Tankersley
 
Dead Simple APIs with OpenAPI
Dead Simple APIs with OpenAPIDead Simple APIs with OpenAPI
Dead Simple APIs with OpenAPIChris Tankersley
 
BASHing at the CLI - Midwest PHP 2018
BASHing at the CLI - Midwest PHP 2018BASHing at the CLI - Midwest PHP 2018
BASHing at the CLI - Midwest PHP 2018Chris Tankersley
 
You Were Lied To About Optimization
You Were Lied To About OptimizationYou Were Lied To About Optimization
You Were Lied To About OptimizationChris Tankersley
 
Docker for PHP Developers - php[world] 2017
Docker for PHP Developers - php[world] 2017Docker for PHP Developers - php[world] 2017
Docker for PHP Developers - php[world] 2017Chris Tankersley
 
Docker for PHP Developers - Madison PHP 2017
Docker for PHP Developers - Madison PHP 2017Docker for PHP Developers - Madison PHP 2017
Docker for PHP Developers - Madison PHP 2017Chris Tankersley
 
Why Docker? Dayton PHP, April 2017
Why Docker? Dayton PHP, April 2017Why Docker? Dayton PHP, April 2017
Why Docker? Dayton PHP, April 2017Chris Tankersley
 
OOP Is More Then Cars and Dogs - Midwest PHP 2017
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 2017Chris Tankersley
 
From Docker to Production - SunshinePHP 2017
From Docker to Production - SunshinePHP 2017From Docker to Production - SunshinePHP 2017
From Docker to Production - SunshinePHP 2017Chris Tankersley
 
Coming to Terms with OOP In Drupal - php[world] 2016
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] 2016Chris Tankersley
 
How We Got Here: A Brief History of Open Source
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 SourceChris Tankersley
 
Docker for PHP Developers - ZendCon 2016
Docker for PHP Developers - ZendCon 2016Docker for PHP Developers - ZendCon 2016
Docker for PHP Developers - ZendCon 2016Chris Tankersley
 
From Docker to Production - ZendCon 2016
From Docker to Production - ZendCon 2016From Docker to Production - ZendCon 2016
From Docker to Production - ZendCon 2016Chris Tankersley
 
Oh Crap, My Code is Slow - Madison PHP 2016
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 2016Chris Tankersley
 
Docker for Developers - PNWPHP 2016 Workshop
Docker for Developers - PNWPHP 2016 WorkshopDocker for Developers - PNWPHP 2016 Workshop
Docker for Developers - PNWPHP 2016 WorkshopChris Tankersley
 
A Brief History of Open Source
A Brief History of Open SourceA Brief History of Open Source
A Brief History of Open SourceChris Tankersley
 

More from Chris Tankersley (20)

Docker is Dead: Long Live Containers
Docker is Dead: Long Live ContainersDocker is Dead: Long Live Containers
Docker is Dead: Long Live Containers
 
Bend time to your will with git
Bend time to your will with gitBend time to your will with git
Bend time to your will with git
 
Dead Simple APIs with OpenAPI
Dead Simple APIs with OpenAPIDead Simple APIs with OpenAPI
Dead Simple APIs with OpenAPI
 
You Got Async in my PHP!
You Got Async in my PHP!You Got Async in my PHP!
You Got Async in my PHP!
 
Docker for Developers
Docker for DevelopersDocker for Developers
Docker for Developers
 
They are Watching You
They are Watching YouThey are Watching You
They are Watching You
 
BASHing at the CLI - Midwest PHP 2018
BASHing at the CLI - Midwest PHP 2018BASHing at the CLI - Midwest PHP 2018
BASHing at the CLI - Midwest PHP 2018
 
You Were Lied To About Optimization
You Were Lied To About OptimizationYou Were Lied To About Optimization
You Were Lied To About Optimization
 
Docker for PHP Developers - php[world] 2017
Docker for PHP Developers - php[world] 2017Docker for PHP Developers - php[world] 2017
Docker for PHP Developers - php[world] 2017
 
Docker for PHP Developers - Madison PHP 2017
Docker for PHP Developers - Madison PHP 2017Docker for PHP Developers - Madison PHP 2017
Docker for PHP Developers - Madison PHP 2017
 
Why Docker? Dayton PHP, April 2017
Why Docker? Dayton PHP, April 2017Why Docker? Dayton PHP, April 2017
Why Docker? Dayton PHP, April 2017
 
OOP Is More Then Cars and Dogs - Midwest PHP 2017
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
 
From Docker to Production - SunshinePHP 2017
From Docker to Production - SunshinePHP 2017From Docker to Production - SunshinePHP 2017
From Docker to Production - SunshinePHP 2017
 
Coming to Terms with OOP In Drupal - php[world] 2016
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
 
How We Got Here: A Brief History of Open Source
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
 
Docker for PHP Developers - ZendCon 2016
Docker for PHP Developers - ZendCon 2016Docker for PHP Developers - ZendCon 2016
Docker for PHP Developers - ZendCon 2016
 
From Docker to Production - ZendCon 2016
From Docker to Production - ZendCon 2016From Docker to Production - ZendCon 2016
From Docker to Production - ZendCon 2016
 
Oh Crap, My Code is Slow - Madison PHP 2016
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
 
Docker for Developers - PNWPHP 2016 Workshop
Docker for Developers - PNWPHP 2016 WorkshopDocker for Developers - PNWPHP 2016 Workshop
Docker for Developers - PNWPHP 2016 Workshop
 
A Brief History of Open Source
A Brief History of Open SourceA Brief History of Open Source
A Brief History of Open Source
 

Recently uploaded

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 

Recently uploaded (20)

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

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