Commit 5fefc7dd authored by Fabien Potencier's avatar Fabien Potencier

fixed PHP 5.4 warning when a response is an array, dispatch the view event...

fixed PHP 5.4 warning when a response is an array, dispatch the view event when an error does not return a Response
parent a57f50d3
......@@ -15,6 +15,7 @@ use Symfony\Component\HttpKernel\HttpKernel;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\TerminableInterface;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
......@@ -354,12 +355,17 @@ class Application extends \Pimple implements HttpKernelInterface, TerminableInte
$code = $exception instanceof HttpExceptionInterface ? $exception->getStatusCode() : 500;
$result = call_user_func($callback, $exception, $code);
if (null !== $result) {
$response = $result instanceof Response ? $result : new Response((string) $result);
$response = call_user_func($callback, $exception, $code);
if ($response instanceof Response) {
$event->setResponse($response);
} else {
$viewEvent = new GetResponseForControllerResultEvent($app['kernel'], $event->getRequest(), $event->getRequestType(), $response);
$app['dispatcher']->dispatch(KernelEvents::VIEW, $viewEvent);
if ($viewEvent->hasResponse()) {
$event->setResponse($viewEvent->getResponse());
}
}
}, $priority);
}
......
......@@ -46,7 +46,7 @@ class ConverterListener implements EventSubscriberInterface
$route = $this->routes->get($request->attributes->get('_route'));
if ($route && $converters = $route->getOption('_converters')) {
foreach ($converters as $name => $callback) {
$request->attributes->set($name, call_user_func($callback, $request->attributes->get($name, null), $request));
$request->attributes->set($name, call_user_func($callback, $request->attributes->get($name), $request));
}
}
}
......
......@@ -17,7 +17,7 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Response;
/**
* Handles converters.
* Converts string responses to proper Response instances.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
......@@ -31,9 +31,15 @@ class StringToResponseListener implements EventSubscriberInterface
public function onKernelView(GetResponseForControllerResultEvent $event)
{
$response = $event->getControllerResult();
$response = $response instanceof Response ? $response : new Response((string) $response);
$event->setResponse($response);
if (!(
null === $response
|| is_array($response)
|| $response instanceof Response
|| (is_object($response) && !method_exists($response, '__toString'))
)) {
$event->setResponse(new Response((string) $response));
}
}
public static function getSubscribedEvents()
......
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