HTTP Kernel and Bootstrap ProcessΒΆ
Note
SiteSupra does not use HttpKernel.
We had eight versions of SiteSupra before moving to Symfony. Unfortuantely, no all of the Symfony concepts do suit our needs well.
Our implementation is still a bit incomplete, especially RequestStack
and forwarding, so expect refactoring soon.
SiteSupra uses plain HttpFoundation
component (see documentation of HttpFoundation
and HTTP requests in symfony
for more information).
SiteSupra mimics Symfony behaviour as close as possible - a Request
object is created, every controller returns
Response
(read more on controllers here).
Basically, request processing happens in the following order:
Web server hits entry point
webroot/index.php
;SiteSupra builds container,
buildContainer()
is called;SiteSupra boots,
boot()
is called. Two events are fired at that moment -Supra::EVENT_BOOT_START
andSupra::EVENT_BOOT_END
. Methodboot()
is called for every registered package, allowing early initialization;Request handling starts by calling
handleRequest($request)
. This method loadsSupra\Core\Kernel\HttpKernel
and callshandle()
. Request handling by HttpKernel traverses through stages below:KernelEvent::REQUEST
is thrown. Request processing stops when there is at least one event configured for response toRequestResponseEvent
. Request object is returned;- Kernel tries to resolve controller and action by checking
_controller
and_action
parameters of requestAttributeBag
; if found, controller is instantiated, action is called andHttpKernel
expectsController
to return aResponse
. This is used when forwarding requests or instantiating requests without a route; - If controller is not resolved yet kernel loads routing and tries to find current route.
AttributeBag
is overwritten by one created from route configuration and controller is actually executed.KernelEvent::CONTROLLER_START
andKernelEvent::CONTROLLER_END
events are fired, and any listener can override response duringKernelEvent::CONTROLLER_END
event. If any exception (generic orResourceNotFoundException
) is thrown request processing moves to exceptions processing (see stage 5 below); - Kernel fires final
KernelEvent::RESPONSE
event and returns resultingResponse
object. Exception is thrown when the object is not an instance ofResponse
; - If any exception is caught during request processing, then the exception is processed in the following way:
- Kernel fires
KernelEvent::EXCEPTION
event (again, if any listener providesResponse
inside this exception event, then the response is returned); - If exception is instance of
ResourceNotFoundException
, a special event is fired -KernelEvent::ERROR404
, which allows, for example, on-the-fly compilation of assets. Finally, if no response is available after the event is processed, the exception is re-thrown (in debug mode) orexception404Action
of default exception controller (stored in container underexception.controller
key) is called; - If there’s still and exception and no response, an exception is re-thrown (in debug mode) or
exception500Action
of default exception controller (stored in container underexception.controller
key) is called.
Resulting response is sent to the browser (by calling
send()
method)). Any unhandled exception is caught by Debug component;SiteSupra shuts down firing
Supra::EVENT_SHUTDOWN_START
andSupra::EVENT_SHUTDOWN_END
events and callsshutdown()
method of all registered packages, thus allowing some late cleanup.
As you can see, this process is pretty simple and transparent. Last thing to note must be a SupraJsonResponse
class
that is used throughout CMS backend for passing messages, warnings, and errors to frontend in a common way.
See the class source code to learn more on messaging process.