Download - Symfony2 - Request to Response

Transcript
Page 1: Symfony2 - Request to Response

Request to Response

Page 2: Symfony2 - Request to Response

Key points

● webserver● front controller● Kernel● Events & Listeners● Controller

Page 3: Symfony2 - Request to Response

let’s visualize

Page 4: Symfony2 - Request to Response

webserver

● apache○ htaccess○ mod_rewrite

● ex : php composer.phar create-project symfony/framework-standard-edition /path/to/workshop-symfony 2.5.*

cd /path/to/workshop-symfonyphp -S localhost:8080 -t web

Page 5: Symfony2 - Request to Response

● app.php vs app_dev.php● bootstrapping [require_once __DIR__.'/../app/bootstrap.php.cache';]

● autoloading [require_once __DIR__.'/./autoload.php';]

● create Request object [$request = Request::createFromGlobals();]

● handle & send response

entry point

Page 6: Symfony2 - Request to Response

AppKernel :● init container● init bundles

HttpKernel :● transform Request

to Response [handle()]

Kernel(s)

HttpKernel

AppKernel

AppCache

Page 7: Symfony2 - Request to Response

● EventDispatcher Component

Events & Listener

Page 8: Symfony2 - Request to Response

● kernel.request● kernel.controller● kernel.view ( when no-response)

● kernel.response ● kernel.finish_request (when response should not modify)

● kernel.terminate (heavy duty stuff)

● kernel.exception (obvious)

Main events

Page 9: Symfony2 - Request to Response
Page 10: Symfony2 - Request to Response
Page 11: Symfony2 - Request to Response

● dispatched as soon as a request arrives● add information to the request, initialize parts of the

system, return response if possible● if any listener returns response the others are not called● ex : routing, firewall, locale

kernel.request

Page 12: Symfony2 - Request to Response

● add version information to request● some routes should not be available in version 2 -

redirect to some page

kernel.request - todo

Page 13: Symfony2 - Request to Response
Page 14: Symfony2 - Request to Response
Page 15: Symfony2 - Request to Response

● dispatched after the controller is determined● initialize things, change the controller before executing● ex : param converter, info collecting

kernel.controller

Page 16: Symfony2 - Request to Response

● handle a preExecute() function on all controllers

kernel.controller - todo

Page 17: Symfony2 - Request to Response
Page 18: Symfony2 - Request to Response
Page 19: Symfony2 - Request to Response

● dispatched after we have a response● modify the response object just before it is sent● ex : context, webdebug

kernel.response

Page 20: Symfony2 - Request to Response

● add an extra header on some routes● change the title of the page

kernel.response - todo

Page 21: Symfony2 - Request to Response

That’s all folks