Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Composing PHP Applications with Middleware (PHP...
Search
Josh Butts
November 16, 2016
220
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
Transcript
26 slides
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
More Decks by Josh Butts
See All by Josh Butts
Supercharged_Search_-_Longhorn_PHP_2025.pdf
jimbojsb
0
59
I Didn't Know Laravel Could Do That!
jimbojsb
4
930
Make It Searchable (Midwest PHP 2018)
jimbojsb
1
460
High Availability PHP (Nomad PHP January 2018)
jimbojsb
1
190
Things Your Application Does When You're Not Looking (PHP Serbia 2017)
jimbojsb
0
310
Containerizing PHP Applications (Lone Star PHP 2017)
jimbojsb
2
360
Containerizing PHP Applications (PHP World 2016)
jimbojsb
0
250
Just-In-Time Software Manufacturing (True North PHP 2016)
jimbojsb
1
290
Containerizing PHP Applications (True North PHP 2016)
jimbojsb
0
270
Featured
See All Featured
Scaling GitHub
holman
464
140k
First, design no harm
axbom
PRO
2
1.4k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
550
How to Think Like a Performance Engineer
csswizardry
28
3k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.8k
The World Runs on Bad Software
bkeepers
PRO
72
12k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
How GitHub (no longer) Works
holman
316
150k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
550
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.9k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
890
Intergalactic Javascript Robots from Outer Space
tanoku
273
28k