Forget about index.php and build you applications around HTTP!
-
Upload
kacper-gunia -
Category
Engineering
-
view
2.669 -
download
11
description
Transcript of Forget about index.php and build you applications around HTTP!
![Page 1: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/1.jpg)
FORGET ABOUT INDEX.PHPBUILD YOUR APPLICATIONS AROUND HTTP!
![Page 2: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/2.jpg)
Kacper Gunia @cakper Software Engineer @SensioLabsUK
Symfony Certified Developer
PHPers Silesia @PHPersPL
![Page 3: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/3.jpg)
Good old daysflickr.com/linkahwai/5162310920
![Page 4: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/4.jpg)
Hello world in PHP “ ” + tutorial
![Page 5: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/5.jpg)
Gojko’s two facts about programming web:
1) Ctrl-C 2) Ctrl-V
![Page 6: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/6.jpg)
<?php !
$name = $_GET['name']; echo "Hello $name!";
![Page 7: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/7.jpg)
![Page 8: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/8.jpg)
It works! :D
![Page 9: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/9.jpg)
but…
![Page 10: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/10.jpg)
![Page 11: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/11.jpg)
![Page 12: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/12.jpg)
and so on… ;)
![Page 13: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/13.jpg)
How HTTP works?flickr.com/see-‐through-‐the-‐eye-‐of-‐g/4278744230
![Page 14: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/14.jpg)
Request
Kabooooom!
Response
![Page 15: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/15.jpg)
This is what HTTP is about!
Request
Response
![Page 16: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/16.jpg)
This is what Your App is about!
Request
Response
![Page 17: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/17.jpg)
“(…) the goal of your application is always to interpret a request and
create the appropriate response based on your
application logic.”Symfony.com
![Page 18: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/18.jpg)
HTTP is simpleflickr.com/wildhaber/5936335464
![Page 19: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/19.jpg)
Requestflickr.com/haniamir/3318727924
![Page 20: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/20.jpg)
GET /index.php?name=Kacper HTTP/1.1 Host: localhost:8000
![Page 21: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/21.jpg)
GET /index.php?name=Kacper HTTP/1.1 Host: localhost:8000
I want to see…
![Page 22: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/22.jpg)
GET /index.php?name=Kacper HTTP/1.1 Host: localhost:8000
…this resource!
![Page 23: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/23.jpg)
GET /index.php?name=Kacper HTTP/1.1 Host: localhost:8000
And I know it should be on localhost
![Page 24: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/24.jpg)
GET /index.php?name=Kacper HTTP/1.1 Host: localhost:8000
Psst, I’m using 1.1 version of HTTP protocol
![Page 25: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/25.jpg)
Responseflickr.com/aftab/3364835006
![Page 26: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/26.jpg)
HTTP/1.1 200 OK Host: localhost:8000 Content-‐type: text/html !
Hello Kacper!
![Page 27: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/27.jpg)
HTTP/1.1 200 OK Host: localhost:8000 Content-‐type: text/html !
Hello Kacper!
OK man, I’ve found it!
![Page 28: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/28.jpg)
HTTP/1.1 200 OK Host: localhost:8000 Content-‐type: text/html !
Hello Kacper!
And it’s an HTML
![Page 29: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/29.jpg)
HTTP/1.1 200 OK Host: localhost:8000 Content-‐type: text/html !
Hello Kacper!
Hello World!
![Page 30: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/30.jpg)
[METH] [REQUEST-‐URI] HTTP/[VER] [Field1]: [Value1] [Field2]: [Value2] !
[request body, if any]
HTTP/[VER] [CODE] [TEXT] [Field1]: [Value1] [Field2]: [Value2] !
[response body]Res
po
nse
R
equ
est
![Page 31: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/31.jpg)
What if we create objects from Request & Response?
![Page 32: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/32.jpg)
Object-oriented HTTPflickr.com/mohammadafshar/9571051345
![Page 33: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/33.jpg)
GET /index.php?name=Kacper HTTP/1.1 Host: localhost:8000
$request-‐>getMethod(); GET $request-‐>getPathInfo(); /
![Page 34: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/34.jpg)
HTTP/1.1 200 OK Host: localhost:8000 Content-‐type: text/html !
Hello Kacper!
$response-‐>getStatusCode(); 200 $response-‐>getContent(); Hello Kacper!
![Page 35: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/35.jpg)
HttpFoundationflickr.com/rubempjr/8050505443
![Page 36: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/36.jpg)
“The HttpFoundation component defines an object-orientedlayer for the HTTP
specification”Symfony.com
![Page 37: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/37.jpg)
Requestflickr.com/haniamir/3318727924
![Page 38: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/38.jpg)
$request = Request::createFromGlobals(); !
$request = new Request( $_GET, $_POST, array(), $_COOKIE, $_FILES, $_SERVER );
![Page 39: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/39.jpg)
!
$_GET $request-‐>query $_POST $request-‐>request $_COOKIE $request-‐>cookies $_FILES $request-‐>files $_SERVER $request-‐>server !
$request-‐>headers $request-‐>attributes
ParameterBag instances
![Page 40: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/40.jpg)
$name = isset($_GET['name']) ? $_GET['name'] : "World";
$name = $request -‐>query -‐>get('name', 'World');
![Page 41: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/41.jpg)
$request-‐>isSecure();
Verify configured header or standard one
![Page 42: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/42.jpg)
$request-‐>isXmlHttpRequest();
Verify AJAX request
![Page 43: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/43.jpg)
$request = Request::create( '/', 'GET', ['name' => 'Kacper'] );
Simulate a Request
![Page 44: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/44.jpg)
Responseflickr.com/aftab/3364835006
![Page 45: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/45.jpg)
$response = new Response( ‘Hello Kacper!’, Response::HTTP_OK, ['content-‐type' => 'text/html'] ); !
$response-‐>prepare($request); $response-‐>send();
![Page 46: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/46.jpg)
$response = new RedirectResponse( 'http://example.com/' );
Redirect Response
![Page 47: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/47.jpg)
$response = new JsonResponse(); $response-‐>setData(['name' => 'Kacper']);
JSON Response
![Page 48: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/48.jpg)
Let’s use them together!
![Page 49: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/49.jpg)
$kernel = new AppKernel('dev', true); !
$request = Request::createFromGlobals(); $response = $kernel-‐>handle($request); $response-‐>send(); !
$kernel-‐>terminate($request, $response);
Symfony app_dev.php
![Page 50: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/50.jpg)
$kernel = new AppKernel('dev', true); !
$request = Request::createFromGlobals(); $response = $kernel-‐>handle($request); $response-‐>send(); !
$kernel-‐>terminate($request, $response);
Symfony app_dev.php
![Page 51: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/51.jpg)
Reminds something? ;)
![Page 52: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/52.jpg)
Request
Kabooooom!
Response
![Page 53: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/53.jpg)
Front Controllerflickr.com/cedwardbrice/8334047708
![Page 54: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/54.jpg)
”The Front Controller consolidates all request handling by channeling
requests through a single handler object (…)”
MartinFowler.com
![Page 55: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/55.jpg)
$kernel = new AppKernel('dev', true); !
$request = Request::createFromGlobals(); $response = $kernel-‐>handle($request); $response-‐>send(); !
$kernel-‐>terminate($request, $response);
![Page 56: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/56.jpg)
Let’s go deeper…
![Page 57: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/57.jpg)
HTTP Kernelflickr.com/stuckincustoms/6341844005
![Page 58: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/58.jpg)
“The HttpKernel component provides a structured process for converting a Request into
a Response by making use of the EventDispatcher.”
Symfony.com
![Page 59: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/59.jpg)
interface HttpKernelInterface { const MASTER_REQUEST = 1; const SUB_REQUEST = 2; !
/** * @return Response A Response instance */ public function handle( Request $request, $type = self::MASTER_REQUEST, $catch = true); }
![Page 60: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/60.jpg)
How Symfony transforms Request into Response?
![Page 61: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/61.jpg)
![Page 62: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/62.jpg)
Event Dispatcherflickr.com/parksjd/11847079564
![Page 63: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/63.jpg)
“The EventDispatcher component provides tools
that allow your application components to communicate
with each other by dispatching events and
listening to them.”Symfony.com
![Page 64: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/64.jpg)
EventDispatcher is an implementation of Mediator pattern
![Page 65: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/65.jpg)
$dispatcher = new EventDispatcher(); $dispatcher-‐>addListener( 'foo.action', function (Event $event) { // do whatever you need }); !
$event = new Event(); $dispatcher-‐>dispatch('foo.action', $event);
![Page 66: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/66.jpg)
The kernel.request Eventflickr.com/drakegoodman/13479419575
![Page 67: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/67.jpg)
![Page 68: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/68.jpg)
Manipulate your Request here…
![Page 69: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/69.jpg)
…you can even return a Response!
![Page 70: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/70.jpg)
public function onKernelRequest(GetResponseEvent $event) { $request = $event-‐>getRequest(); if ($request-‐>query-‐>get('name') === 'Kacper') { $event-‐>setResponse( new Response("We don't like you!") ); } }
![Page 71: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/71.jpg)
![Page 72: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/72.jpg)
…or e.g. detect device, location…
![Page 73: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/73.jpg)
…and routing is resolved here
![Page 74: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/74.jpg)
The Routing Componentflickr.com/checksam/12814058644
![Page 75: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/75.jpg)
“The Routing component maps an
HTTP request to a set of configuration
variables.”Symfony.com
![Page 76: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/76.jpg)
$route = new Route('/', array('controller' => 'HelloController')); $routes = new RouteCollection(); $routes-‐>add('hello_route', $route); !
$context = new RequestContext(); $context-‐>fromRequest($request); !
$matcher = new UrlMatcher($routes, $context); !
$parameters = $matcher-‐>match('/'); // ['controller' => 'HelloController', '_route' => 'hello_route']
![Page 77: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/77.jpg)
$route = new Route('/', array('controller' => 'HelloController')); $routes = new RouteCollection(); $routes-‐>add('hello_route', $route); !
$context = new RequestContext(); $context-‐>fromRequest($request); !
$matcher = new UrlMatcher($routes, $context); !
$parameters = $matcher-‐>match('/'); // ['controller' => 'HelloController', '_route' => 'hello_route']
![Page 78: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/78.jpg)
$route = new Route('/', array('controller' => 'HelloController')); $routes = new RouteCollection(); $routes-‐>add('hello_route', $route); !
$context = new RequestContext(); $context-‐>fromRequest($request); !
$matcher = new UrlMatcher($routes, $context); !
$parameters = $matcher-‐>match('/'); // ['controller' => 'HelloController', '_route' => 'hello_route']
![Page 79: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/79.jpg)
$route = new Route('/', array('controller' => 'HelloController')); $routes = new RouteCollection(); $routes-‐>add('hello_route', $route); !
$context = new RequestContext(); $context-‐>fromRequest($request); !
$matcher = new UrlMatcher($routes, $context); !
$parameters = $matcher-‐>match('/'); // ['controller' => 'HelloController', '_route' => 'hello_route']
![Page 80: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/80.jpg)
$route = new Route('/', array('controller' => 'HelloController')); $routes = new RouteCollection(); $routes-‐>add('hello_route', $route); !
$context = new RequestContext(); $context-‐>fromRequest($request); !
$matcher = new UrlMatcher($routes, $context); !
$parameters = $matcher-‐>match('/'); // ['controller' => 'HelloController', '_route' => 'hello_route']
![Page 81: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/81.jpg)
Resolve Controllerflickr.com/rightbrainphotography/480979176
![Page 82: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/82.jpg)
![Page 83: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/83.jpg)
interface ControllerResolverInterface { public function getController( Request $request ); !
public function getArguments( Request $request, $controller ); }
![Page 84: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/84.jpg)
Controller is a PHP callable
![Page 85: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/85.jpg)
The kernel.controller Eventflickr.com/drakegoodman/12451824524
![Page 86: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/86.jpg)
![Page 87: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/87.jpg)
Change controller here (if you need)
![Page 88: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/88.jpg)
and initialise data
![Page 89: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/89.jpg)
e.g. parameters conversion
happens now
![Page 90: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/90.jpg)
Resolve Argumentsflickr.com/joiseyshowaa/2720195951
![Page 91: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/91.jpg)
![Page 92: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/92.jpg)
interface ControllerResolverInterface { public function getController( Request $request ); !
public function getArguments( Request $request, $controller ); }
![Page 93: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/93.jpg)
Arguments come from
$request->attributes ParameterBag
![Page 94: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/94.jpg)
Controller Callflickr.com/taspicsvns/11768808836
![Page 95: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/95.jpg)
![Page 96: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/96.jpg)
Time for your application logic
![Page 97: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/97.jpg)
Return Response object
![Page 98: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/98.jpg)
Optional: The kernel.view event
flickr.com/drakegoodman/11006558364
![Page 99: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/99.jpg)
![Page 100: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/100.jpg)
Transform non-Response into Response
![Page 101: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/101.jpg)
e.g. @Template annotation
![Page 102: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/102.jpg)
e.g. transform arrays into
JSON Responses
![Page 103: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/103.jpg)
The kernel.response Eventflickr.com/drakegoodman/14482752231
![Page 104: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/104.jpg)
![Page 105: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/105.jpg)
Manipulate Response
![Page 106: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/106.jpg)
e.g. WebDebugToolbar
![Page 107: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/107.jpg)
Send Responseflickr.com/stuckincustoms/5727003126
![Page 108: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/108.jpg)
The kernel.terminate Eventflickr.com/drakegoodman/12203395206
![Page 109: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/109.jpg)
Do the heavy stuff now
![Page 110: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/110.jpg)
e.g. Send Emails
![Page 111: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/111.jpg)
HTTP Cacheflickr.com/soldiersmediacenter/403524071
![Page 112: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/112.jpg)
Cache-Control Expires
![Page 113: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/113.jpg)
Cache-Control Expires
![Page 114: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/114.jpg)
$response = new Response(); !
$response-‐>setPublic(); $response-‐>setMaxAge(600); $response-‐>setSharedMaxAge(600);
![Page 115: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/115.jpg)
Validation
![Page 116: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/116.jpg)
public function indexAction(Request $request, $name) { $response = new Response("Hello $name"); $response-‐>setETag(md5($response-‐>getContent())); $response-‐>setPublic(); $response-‐>isNotModified($request); !
return $response; }
![Page 117: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/117.jpg)
ESIflickr.com/nasamarshall/6950477589
![Page 118: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/118.jpg)
“The ESI specification describes tags you can
embed in your pages to communicate with
the gateway cache.”Symfony.com
![Page 119: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/119.jpg)
<!DOCTYPE html> <html> <body> <!-‐-‐ ... content -‐-‐> !
<!-‐-‐ Embed the content of another page -‐-‐> <esi:include src="http://..."/> !
<!-‐-‐ ... content -‐-‐> </body> </html>
![Page 120: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/120.jpg)
But I don’t have Varnish!
![Page 121: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/121.jpg)
Symfony2 Reverse Proxyflickr.com/zacharyz/3950845049
![Page 122: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/122.jpg)
$kernel = new AppKernel('prod', false); $kernel-‐>loadClassCache(); !
$kernel = new AppCache($kernel); !
$request = Request::createFromGlobals(); $response = $kernel-‐>handle($request); $response-‐>send(); $kernel-‐>terminate($request, $response);
![Page 123: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/123.jpg)
$kernel = new AppKernel('prod', false); $kernel-‐>loadClassCache(); !
$kernel = new AppCache($kernel); !
$request = Request::createFromGlobals(); $response = $kernel-‐>handle($request); $response-‐>send(); $kernel-‐>terminate($request, $response);
![Page 124: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/124.jpg)
OK, but are those things actually used outside of Symfony?
![Page 125: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/125.jpg)
flickr.com/tombricker/5709640847
YES!
![Page 126: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/126.jpg)
Drupal 8phpBB
SilexeZ Publish
Laravel
![Page 127: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/127.jpg)
Kacper Gunia Software Engineer
Symfony Certified Developer
PHPers Silesia
Thanks!
![Page 128: Forget about index.php and build you applications around HTTP!](https://reader038.fdocuments.net/reader038/viewer/2022102721/53f480e58d7f728e318b4846/html5/thumbnails/128.jpg)
joind.in/10880