Commit b3fc523b authored by Fabien Potencier's avatar Fabien Potencier

fixed exception handling

parent cb5003a0
......@@ -309,16 +309,19 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe
$this['dispatcher']->addListener(SilexEvents::ERROR, function (GetResponseForErrorEvent $event) use ($callback) {
$exception = $event->getException();
if(is_array($callback)){
if (is_array($callback)) {
$callbackReflection = new \ReflectionMethod($callback[0], $callback[1]);
} elseif (is_object($callback) && !$callback instanceof \Closure) {
$callbackReflection = new \ReflectionObject($callback);
$callbackReflection = $callbackReflection->getMethod('__invoke');
} else {
$callbackReflection = new \ReflectionFunction($callback);
}
if($callbackReflection->getNumberOfParameters() > 0){
if ($callbackReflection->getNumberOfParameters() > 0) {
$parameters = $callbackReflection->getParameters();
$expectedException = $parameters[0];
if($expectedException->getClass() && !($expectedException->getClass()->isInstance($exception))){
if ($expectedException->getClass() && !$expectedException->getClass()->isInstance($exception)) {
return;
}
}
......
......@@ -345,13 +345,8 @@ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
throw new \Exception();
});
$stub = $this->getMock('\StdClass');
$stub->expects($this->any())
->method('handler')
->will($this->returnValue('Caught Exception'));
// Array style callback for error handler
$app->error(array($stub, 'handler'));
$app->error(array($this, 'exceptionHandler'));
$request = Request::create('/foo');
$response = $app->handle($request);
......@@ -366,4 +361,9 @@ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
return $response;
}
public function exceptionHandler()
{
return 'Caught Exception';
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment