PHP Frameworks in 2015 - The rise of middleware

Post on 02-Aug-2015

81 views 0 download

Transcript of PHP Frameworks in 2015 - The rise of middleware

the rise of middleware PHP FrameworksEmmanuel Idé

PHP FrameworksPhase IDecouple!OO / MVC

PHP FrameworksPhase IIDecouple!!IoC / Dependency Injection

PHP FrameworksPhase IIIDecouple!!!MiddleWare

What is middlewarehttps://mattstauffer.co/blog/laravel-5.0-middleware-filter-style

The way this works is that middleware implements a decorator pattern: it takes the request, does something, and returns another request object to the next layer of the stack.

What is middlewarehttp://stackoverflow.com/questions/2256569/what-is-rack-middleware

Middleware is a dreadful term which refers to any software component/library which assists with but is not directly involved in the execution of some task.

Decorator Pattern

Attach additional responsibilities to an object dynamically, without using subclassing.

Pipes-and-Filters Pattern

The Pipes and Filters architectural pattern provides a structure for systems, having components that process a stream of data (filters) and connections that transmit data between adjacent components (pipes).

HTP Interfaces1997: Java Servlet2003: Python WSGI2007: Ruby Rack2010: Node Express2011: Symfony2 HttpKernelInterface

HTP Interfaces1997: Java Servlet2003: Python WSGI2007: Ruby Rack2010: Node Express2011: Symfony2 HttpKernelInterface

Rack definitionsEnvironment Environment variables representing the HTTP request. Mostly taken from CGI, but has additional Rack-specific variables.

Response The response format. It is an array with three elements: The status code, a hash of headers and a list of strings for the body.

ApplicationAn app is an object with a call method. The input argument is an env hash, the return value a response array.

Rubyclass HelloWorld def call(env) [200, {"Content-Type" => "text/plain"}, ["Hello world!"]] endend

class HelloWorld def call(env) [200, {"Content-Type" => "text/plain"}, ["Hello world!"]] end end

Why shall we care, we have SAPI

$_SERVER, $_ENV, $_GET, $_POST, $_COOKIE, $_FILES and $_REQUEST

stackphp.com

Stack is a convention for composing HttpKernelInterface middlewares.

Symfony 2HttpKernelInterface

- No specification

- coupled to the framework

Symfony 3

the HttpKernel is going to be split into several smaller ones

Who supports stack?

Laravel, Symfony, Drupal, etc.. (ZF3 roadmap announces alternative to stack)