Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Composing PHP Applications with Middleware (PHP...
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Josh Butts
November 16, 2016
200
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Composing PHP Applications with Middleware (PHP WorldΒ 2016)
Josh Butts
November 16, 2016
More Decks by Josh Butts
See All by Josh Butts
Supercharged_Search_-_Longhorn_PHP_2025.pdf
jimbojsb
0
47
I Didn't Know Laravel Could Do That!
jimbojsb
4
910
Make It Searchable (Midwest PHP 2018)
jimbojsb
1
450
High Availability PHP (Nomad PHP January 2018)
jimbojsb
1
180
Things Your Application Does When You're Not Looking (PHP Serbia 2017)
jimbojsb
0
300
Containerizing PHP Applications (Lone Star PHP 2017)
jimbojsb
2
350
Containerizing PHP Applications (PHP World 2016)
jimbojsb
0
230
Just-In-Time Software Manufacturing (True North PHP 2016)
jimbojsb
1
270
Containerizing PHP Applications (True North PHP 2016)
jimbojsb
0
250
Featured
See All Featured
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
220
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
500
Darren the Foodie - Storyboard
khoart
PRO
3
3.7k
Practical Orchestrator
shlominoach
191
12k
The Curse of the Amulet
leimatthew05
2
14k
Ten Tips & Tricks for a π± transition
stuffmc
0
170
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
500
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
γγ³γγγγ£γ³γΉγ«οΌζͺζ₯γγ€γγγγγγ―γγγΌγγγγ #pmconf2020
aki_iinuma
128
56k
The Spectacular Lies of Maps
axbom
PRO
1
940
Automating Front-end Workflow
addyosmani
1369
210k
Building Adaptive Systems
keathley
44
3.2k
Transcript
Composing PHP Applications with Middleware Josh Butts PHP World 2016
About Me β’ VP of Engineering, offers.com β’ Austin PHP
Organizer β’ Play competitive Skee Ball β’ github.com/jimbojsb β’ @jimbojsb 2
PSR-7 Lets Start With 3
What is PSR-7 β’ FIG standard for HTTP messages β’
A collection of interfaces β’ By itself, has nothing specific to do with middleware 4
Request - Historically β’ $_SERVER, $_GET, $_POST, etc β’ apache_request_headers()
β’ php://input 5
Response - Historically β’ header() β’ http_response_code() β’ header_list() β’
echo 6
URI - Historically β’ parse_url() β’ parse_str() β’ http_build_query() 7
DID WE END UP HERE? How in the hell 8
PSR-7 Enter 9
But first - More History β’ 2014 - everyone* has
gone out and built and object model of HTTP β’ Hello World for writing a framework β’ None of them are compatible β’ Symfony\HttpFoundation widely used 10
PSR-7 is a collection of Interfaces 11
Concrete Implementations of PSR-7 β’ Zend\Diactoros β’ GuzzleHTTP\Psr7 β’ Slim\Http
12
MIDDLEWARE I thought this talk was about 13
What is middleware? β’ Turns a Request into a Response
β’ Stackable β’ Reusable β’ Dispatachable 14
PHP Copied This Trend β’ Node.js Connect β’ Ruby Rack
β’ Python WSGI β’ Even StackPHP 15
Express.js is getting it right β’ All middleware all the
way down β’ Even error handlers are middleware β’ Even the app instance itself is middleware 16
Components of a PHP Middleware App β’ PSR-7 implementation β’
Collection of middleware β’ Middleware dispatcher β’ Any other libraries that will actually do business logic for you 17
Pick a dispatcher β’ Zend-Stratagility β’ Relay β’ Radar β’
Slim v3 β’ Zend Expressive 18
Pick a PSR-7 Implementation β’ Do not write one β’
Unless youβre using Slim already just use Zend/Diactoros 19
What does a middleware look like? 20 <?php $middleware =
function( \Psr\Http\Message\RequestInterface $request, \Psr\Http\Message\ResponseInterface $response, callable $next) { // do the actual stuff };
It might also look like this 21 <?php $middleware =
function( \Psr\Http\Message\RequestInterface $request, callable $next) { // do some stuff };
PSR-15 β’ There is still some debate as to which
is better β’ Itβs likely the standard will not pass along the response β’ Lots of existing middleware out there that would not meet this spec 22
LETS LOOK AT CODE All thatβs fine 23
QUESTIONS? 24
GITHUB.COM/JIMBOJSB/ MIDDLEWARE-TALK 25
JOIND.IN/TALK/AF8F4 Iβd love your feedback 26