Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

…event when an error does not return a Response
  • Loading branch information...
commit 5fefc7dd32c2b7573555cd45f47c668ad032f0cb 1 parent a57f50d
@fabpot authored
View
14 src/Silex/Application.php
@@ -15,6 +15,7 @@
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 @@ public function error($callback, $priority = -8)
$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);
}
View
2  src/Silex/EventListener/ConverterListener.php
@@ -46,7 +46,7 @@ public function onKernelController(FilterControllerEvent $event)
$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));
}
}
}
View
12 src/Silex/EventListener/StringToResponseListener.php
@@ -17,7 +17,7 @@
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()
Please sign in to comment.
Something went wrong with that request. Please try again.