milosh012
milosh012

Reputation: 48

Symfony 2 bootstrap process

Can someone explain me basic bootstrap process of symfony 2 application. From entry point, to specific action in controller, and rendering view using twig template system.

Upvotes: 1

Views: 1168

Answers (1)

room13
room13

Reputation: 1922

There is a chapter in the symfony book about this: http://symfony.com/doc/current/book/internals.html

Reading the whole chapter will give you a pretty good understanding of how things work under the hood.

I will cite the important part here for the sake of completeness:

Handling Requests

The handle() method takes a Request and always returns a Response. To convert the Request, handle() relies on the Resolver and an ordered chain of Event notifications (see the next section for more information about each Event):

  • Before doing anything else, the kernel.request event is notified -- if one of the listeners returns a Response, it jumps to step 8 directly;
  • The Resolver is called to determine the Controller to execute;
  • Listeners of the kernel.controller event can now manipulate the Controller callable the way they want (change it, wrap it, ...);
  • The Kernel checks that the Controller is actually a valid PHP callable;
  • The Resolver is called to determine the arguments to pass to the Controller;
  • The Kernel calls the Controller;
  • If the Controller does not return a Response, listeners of the kernel.view event can convert the Controller return value to a Response;
  • Listeners of the kernel.response event can manipulate the Response (content and headers);
  • The Response is returned.

If an Exception is thrown during processing, the kernel.exception is notified and listeners are given a chance to convert the Exception to a Response. If that works, the kernel.response event is notified; if not, the Exception is re-thrown.

If you don't want Exceptions to be caught (for embedded requests for instance), disable the kernel.exception event by passing false as the third argument to the handle() method.

Upvotes: 4

Related Questions