PHP Frameworks in 2015 - The rise of middleware

17
the rise of middleware PHP Frameworks Emmanuel Idé

Transcript of PHP Frameworks in 2015 - The rise of middleware

Page 1: PHP Frameworks in 2015 - The rise of middleware

the rise of middleware PHP FrameworksEmmanuel Idé

Page 2: PHP Frameworks in 2015 - The rise of middleware

PHP FrameworksPhase IDecouple!OO / MVC

Page 3: PHP Frameworks in 2015 - The rise of middleware

PHP FrameworksPhase IIDecouple!!IoC / Dependency Injection

Page 4: PHP Frameworks in 2015 - The rise of middleware

PHP FrameworksPhase IIIDecouple!!!MiddleWare

Page 5: PHP Frameworks in 2015 - The rise of 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.

Page 6: PHP Frameworks in 2015 - The rise of middleware

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.

Page 7: PHP Frameworks in 2015 - The rise of middleware

Decorator Pattern

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

Page 8: PHP Frameworks in 2015 - The rise of middleware

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).

Page 9: PHP Frameworks in 2015 - The rise of middleware

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

Page 10: PHP Frameworks in 2015 - The rise of middleware

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

Page 11: PHP Frameworks in 2015 - The rise of middleware

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.

Page 12: PHP Frameworks in 2015 - The rise of middleware

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

Page 13: PHP Frameworks in 2015 - The rise of middleware

Why shall we care, we have SAPI

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

Page 14: PHP Frameworks in 2015 - The rise of middleware

stackphp.com

Stack is a convention for composing HttpKernelInterface middlewares.

Page 15: PHP Frameworks in 2015 - The rise of middleware

Symfony 2HttpKernelInterface

- No specification

- coupled to the framework

Page 16: PHP Frameworks in 2015 - The rise of middleware

Symfony 3

the HttpKernel is going to be split into several smaller ones

Page 17: PHP Frameworks in 2015 - The rise of middleware

Who supports stack?

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