A Year With Symfony Writing healthy, reusable Symfony2 by Matthias Noback

The abstract service has one argument and is marked as abstract. The token provider services mention abstract_token_provider as their parent. The token_provider service has no extra arguments, so it just inherits the first constructor argument from abstract_token_provider.

Exception event are allowed to: • Set a proper Response object for this specific exception. • Replace the original Exception object. When none of the listeners has called setResponse() on the event object, the exception will be thrown (again), but this time it will not be handled automatically. So in case your display_errors PHP setting equals true, PHP just renders it as-is. $response->isRedirect() ) { // ensure that we actually have an error response if ($e instanceof HttpExceptionInterface) { // keep the HTTP status code and headers $response->setStatusCode($e->getStatusCode()); $response->headers->add($e->getHeaders()); } else { $response->setStatusCode(500); } } This is quite useful: we can enforce a certain status code to be used by adding an X-Status-Code header to the Response object (remember: this only works for exceptions that are caught by the HttpKernel), or by throwing exceptions that implement HttpExceptionInterface.

Download PDF sample

Rated 4.35 of 5 – based on 42 votes