Symfony2 - Request to Response

Post on 27-Aug-2014

403 views 0 download

Tags:

description

Key aspects of the road from a request to a response in Symfony2.

Transcript of Symfony2 - Request to Response

Request to Response

Key points

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

let’s visualize

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

● 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

AppKernel :● init container● init bundles

HttpKernel :● transform Request

to Response [handle()]

Kernel(s)

HttpKernel

AppKernel

AppCache

● EventDispatcher Component

Events & Listener

● 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

● 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

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

redirect to some page

kernel.request - todo

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

kernel.controller

● handle a preExecute() function on all controllers

kernel.controller - todo

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

kernel.response

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

kernel.response - todo

That’s all folks