SlideShare a Scribd company logo
The Future of HTTP
In CakePHP
First, the Present
Request & Response
Added in 2.0.0
Symfony HttpKernel
& StackPHP
Symfony all
the Things
PSR-7
HTTP message interfaces
What’s the Problem?
HTTP in PHP is :(
$_POST
Only works for POST methods and url-encoded
data.
$_SERVER
No-consistency, or normalization
Request URI
Hard to find.
File Uploads
A pretty big mess.
Frameworks to
the Rescue!
Not Invented Here
Every framework has their own HTTP stack
No Shared Solutions
Sharing is caring
What do other
languages do?
Python
Web Server Gateway Interface
Ruby
Rack
Go-Lang
http module in stdlib
Common Traits
All these platforms have a single implementation.
PSR-7
Requests &
Responses
Requests
Immutable
All PSR7 objects are immutable*
// Read a header as text
$value = $request->getHeaderLine(‘Content-Type’);
// Read header as an array
$value = $request->getHeader(‘Content-Type’);
// Read all the headers
$headers = $request->getHeaders();
Reading Headers
// Get an array of cookie values.
$cookies = $request->getCookieParams();
// Get a list of UploadedFile objects
$files = $request->getUploadedFiles();
// Read the file data.
$files[0]->getStream();
$files[0]->getSize();
$files[0]->getClientFileName();
// Move the file.
$files[0]->moveTo($targetPath);
Cookies & Files
// Get the URI
$uri = $request->getUri();
// Read data out of the URI.
$path = $uri->getPath();
$query = $uri->getQuery();
$host = $uri->getHost();
URL data
// Get the application base dir
$base = $request->getAttribute(‘base’);
// Get the application webroot
$webroot = $request->getAttribute(‘webroot’);
// Get the routing parameters
$params = $request->getAttribute(‘params’);
Request Attributes
Responses
Also Immutable
// Bodies are also Streams.
$body = new Stream(‘php://memory');
$body->write(‘{“ok”:true}’);
// Build up a response.
$res->withHeader(‘Content-Type’, ‘application/json’)
->withStatus(204)
->withBody($body);
Building Responses
Middleware
CORS
Exceptions
Assets
Routes
App
CORS
Exceptions
Assets
Routes
App
Request
Response
CORS
Exceptions
Assets
Routes
App
Request
Response
1. Must accept a Request, Response and ‘next’
2. Must return a Response, or call ‘next’
3. No more Rules.
Middleware Rules
Middleware
Examples
$middleware = new CakeHttpMiddlewareStack();
// Catch any exceptions in the lower layers.
$middleware->push(new ErrorHandlerMiddleware());
// Handle plugin/theme assets
$middleware->push(new AssetMiddleware());
// Apply routing
$middleware->push(new RoutingMiddleware());
// Apply CORS at the first middleware
$middleware->prepend(new CorsMiddleware());
Setup Middleware
// Using closures
$wow = function ($req, $res, $next) {
$res = $res->withHeader(‘X-Wow’, ‘Wow’);
return $next($req, $res);
};
// Add to a middleware stack
$middleware->push($wow);
Middleware
class WowMiddleware
{
public function __invoke($res, $req, $next)
{
$res = $res->withHeader(‘X-Wow’, ‘Wow’);
return $next($req, $res);
}
}
// Add to a middleware stack
$middleware->push(new WowMiddleware());
Middleware
HttpClient
$client = new CakeHttpClient();
$res = $client->get(‘http://cakephp.org');
// Use PSR7 methods.
$status = $res->getStatusCode();
$contentType = $res->getHeaderLine(‘Content-Type’);
$body = $res->getBody()->getContents();
Client Example
Fully backwards
compatible
Client Responses still support the current
interface.
Future of HTTP in CakePHP
Sounds Nice, but
is upgrading going to suck?
Nope
It should be painless really.
Timeline
Now
3.3 - Fall 2016
3.4 - Early 2017
4.0 - ?
PSR-7 in 3.3.0
Opt-in stack that replaces DispatcherFilters
require dirname(__DIR__) . '/vendor/autoload.php';
use CakeHttpServer;
use AppApplication;
// Bind your application to the server.
$app = new Application(dirname(__DIR__) . ‘/config');
$server = new Server($app);
// Run the request/response and emit the response
$server->emit($server->run());
index.php of the future
class Application extends BaseApplication
{
public function middleware($middleware)
{
// Catch any exceptions in the lower layers.
$middleware->push(new ErrorHandlerMiddleware());
// Handle plugin/theme assets
$middleware->push(new AssetMiddleware());
// Apply routing
$middleware->push(new RoutingMiddleware());
return $middleware;
}
}
Application Class
3.4.0
NetworkRequest will implement PSR7
Future 3.x.0
Runtime errors on deprecated methods.
4.0.0
Clean up. Remove deprecations.
In Review
1. PSR7 middleware is coming as an opt-in feature for 3.3.0
2. New applications will default to the new HTTP stack in 3.3.0
3. Controllers will have access to PSR7 methods in 3.4.0
4. Runtime deprecations will be introduced in a future 3.x
5. The code you write today will continue to work until 4.0.0.
Thank You
Github - markstory
Twitter - mark_story
https://joind.in/talk/3b577

More Related Content

PDF
New in cakephp3
PDF
Agile database access with CakePHP 3
PDF
Advanced Querying with CakePHP 3
PDF
CakeFest 2013 keynote
PDF
Internationalizing CakePHP Applications
PDF
The Origin of Lithium
PDF
PHP Data Objects
KEY
Php 101: PDO
New in cakephp3
Agile database access with CakePHP 3
Advanced Querying with CakePHP 3
CakeFest 2013 keynote
Internationalizing CakePHP Applications
The Origin of Lithium
PHP Data Objects
Php 101: PDO

What's hot (20)

PPT
Quebec pdo
PDF
Lithium: The Framework for People Who Hate Frameworks
PDF
Dependency Injection IPC 201
PDF
Building Lithium Apps
PDF
Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition
PDF
The State of Lithium
PDF
Symfony2 - WebExpo 2010
PPT
PHP - PDO Objects
PDF
Dependency Injection
PDF
Doctrine fixtures
PDF
Php unit the-mostunknownparts
KEY
Lithium Best
PDF
international PHP2011_Bastian Feder_jQuery's Secrets
PDF
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway
PDF
Dependency Injection with PHP and PHP 5.3
KEY
Introducing CakeEntity
PDF
Doctrine 2
KEY
Introducing CakeEntity
PDF
Dependency injection-zendcon-2010
PDF
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Quebec pdo
Lithium: The Framework for People Who Hate Frameworks
Dependency Injection IPC 201
Building Lithium Apps
Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition
The State of Lithium
Symfony2 - WebExpo 2010
PHP - PDO Objects
Dependency Injection
Doctrine fixtures
Php unit the-mostunknownparts
Lithium Best
international PHP2011_Bastian Feder_jQuery's Secrets
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway
Dependency Injection with PHP and PHP 5.3
Introducing CakeEntity
Doctrine 2
Introducing CakeEntity
Dependency injection-zendcon-2010
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Ad

Similar to Future of HTTP in CakePHP (20)

PDF
PSR-7, middlewares e o futuro dos frameworks
PDF
Psr 7 symfony-day
ODP
Aura Project for PHP
KEY
Phpne august-2012-symfony-components-friends
KEY
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
KEY
PDF
PHP 5.3 Overview
PDF
When symfony met promises
PDF
The symfony platform: Create your very own framework (PHP Quebec 2008)
PDF
Modern php
PDF
Introducción a aplicaciones php basadas en middleware y psr 7
ODP
Symfony2, creare bundle e valore per il cliente
PDF
Bootstrat REST APIs with Laravel 5
KEY
Using and scaling Rack and Rack-based middleware
PDF
Symfony without the framework
PPT
nguyenhainhathuy-building-restful-web-service
PDF
Zend/Expressive 3 – The Next Generation
PDF
Solid principles
PDF
Symfony internals [english]
PDF
Durian: a PHP 5.5 microframework with generator-style middleware
PSR-7, middlewares e o futuro dos frameworks
Psr 7 symfony-day
Aura Project for PHP
Phpne august-2012-symfony-components-friends
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
PHP 5.3 Overview
When symfony met promises
The symfony platform: Create your very own framework (PHP Quebec 2008)
Modern php
Introducción a aplicaciones php basadas en middleware y psr 7
Symfony2, creare bundle e valore per il cliente
Bootstrat REST APIs with Laravel 5
Using and scaling Rack and Rack-based middleware
Symfony without the framework
nguyenhainhathuy-building-restful-web-service
Zend/Expressive 3 – The Next Generation
Solid principles
Symfony internals [english]
Durian: a PHP 5.5 microframework with generator-style middleware
Ad

More from markstory (20)

PDF
Dependency injection in CakePHP
PDF
Safer, More Helpful CakePHP
PDF
CakePHP - The Road Ahead
PDF
CakePHP mistakes made 2015
PDF
PHP WTF
PDF
CakePHP 3.0 and beyond
PDF
CakePHP mistakes made confoo 2015
PDF
CakePHP mistakes made
PDF
Performance and optimization CakeFest 2014
PDF
Road to CakePHP 3.0
PDF
Performance and optimization
PDF
OWASP Top 10 2013
PDF
CakePHP the yum & yuck
PDF
Introduction to Twig
PDF
Owasp top 10
PDF
Simple search with elastic search
PDF
Making the most of 2.2
PDF
Intro to continuous integration
PDF
Evented applications with RabbitMQ and CakePHP
PDF
Ch ch-changes cake php2
Dependency injection in CakePHP
Safer, More Helpful CakePHP
CakePHP - The Road Ahead
CakePHP mistakes made 2015
PHP WTF
CakePHP 3.0 and beyond
CakePHP mistakes made confoo 2015
CakePHP mistakes made
Performance and optimization CakeFest 2014
Road to CakePHP 3.0
Performance and optimization
OWASP Top 10 2013
CakePHP the yum & yuck
Introduction to Twig
Owasp top 10
Simple search with elastic search
Making the most of 2.2
Intro to continuous integration
Evented applications with RabbitMQ and CakePHP
Ch ch-changes cake php2

Recently uploaded (20)

PDF
Design an Analysis of Algorithms I-SECS-1021-03
DOCX
Greta — No-Code AI for Building Full-Stack Web & Mobile Apps
PDF
Nekopoi APK 2025 free lastest update
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
iTop VPN Free 5.6.0.5262 Crack latest version 2025
PDF
Complete Guide to Website Development in Malaysia for SMEs
PPTX
Transform Your Business with a Software ERP System
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
medical staffing services at VALiNTRY
PDF
Download FL Studio Crack Latest version 2025 ?
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Salesforce Agentforce AI Implementation.pdf
PDF
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
history of c programming in notes for students .pptx
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
Design an Analysis of Algorithms I-SECS-1021-03
Greta — No-Code AI for Building Full-Stack Web & Mobile Apps
Nekopoi APK 2025 free lastest update
wealthsignaloriginal-com-DS-text-... (1).pdf
Navsoft: AI-Powered Business Solutions & Custom Software Development
iTop VPN Free 5.6.0.5262 Crack latest version 2025
Complete Guide to Website Development in Malaysia for SMEs
Transform Your Business with a Software ERP System
Operating system designcfffgfgggggggvggggggggg
Reimagine Home Health with the Power of Agentic AI​
Design an Analysis of Algorithms II-SECS-1021-03
Wondershare Filmora 15 Crack With Activation Key [2025
medical staffing services at VALiNTRY
Download FL Studio Crack Latest version 2025 ?
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Salesforce Agentforce AI Implementation.pdf
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
history of c programming in notes for students .pptx
Embracing Complexity in Serverless! GOTO Serverless Bengaluru

Future of HTTP in CakePHP