Pergunta

I was planning to use symfony response object, but what is the simplest way to catch the exception and hook it up to the symfony exceptionhandler class.

Should I wrap the start of the application in a try/catch block or is there a more elegant/alternative way of doing things. Hook up an eventlistener maybe? How would I do that?

I am not looking to use big parts of the symfony framework.

Thanks

Foi útil?

Solução

You have to use Kernel Events. you can see an exemple here: Symfony2 logging 404 errors

and test the exception with $exception->getStatusCode()

public function onKernelException(Event $event) {
    //Get hold of the exception
    $exception = $event->getException();
    if ($exception->getStatusCode() == 404)
    {
        //Do stuffs
    }

}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top