From 9c2c9928703e6ca5dbdbd0d89c7a1d530b1e8d29 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 6 May 2010 14:26:48 +0200 Subject: [PATCH] added a raw argument to the HttpKernel::handle() method --- src/Symfony/Components/HttpKernel/HttpKernel.php | 10 ++++++++-- .../Components/HttpKernel/HttpKernelInterface.php | 5 ++--- src/Symfony/Foundation/Kernel.php | 11 +---------- src/Symfony/Foundation/bootstrap.php | 9 +-------- .../Framework/WebBundle/Listener/ControllerLoader.php | 2 +- .../Framework/WebBundle/Listener/ExceptionHandler.php | 2 +- 6 files changed, 14 insertions(+), 25 deletions(-) diff --git a/src/Symfony/Components/HttpKernel/HttpKernel.php b/src/Symfony/Components/HttpKernel/HttpKernel.php index 5d7a8a7f29..5f09fecfc0 100644 --- a/src/Symfony/Components/HttpKernel/HttpKernel.php +++ b/src/Symfony/Components/HttpKernel/HttpKernel.php @@ -55,12 +55,13 @@ class HttpKernel implements HttpKernelInterface * * @param Request $request A Request instance * @param Boolean $main Whether this is the main request or not + * @param Boolean $raw Whether to catch exceptions or not * * @return Response $response A Response instance * * @throws \Exception When Exception couldn't be caught by event processing */ - public function handle(Request $request = null, $main = true) + public function handle(Request $request = null, $main = true, $raw = false) { $main = (Boolean) $main; @@ -80,6 +81,11 @@ class HttpKernel implements HttpKernelInterface } catch (\Exception $e) { + if (true === $raw) + { + throw $e; + } + // exception $event = $this->dispatcher->notifyUntil(new Event($this, 'core.exception', array('main_request' => $main, 'request' => $request, 'exception' => $e))); if ($event->isProcessed()) @@ -104,7 +110,7 @@ class HttpKernel implements HttpKernelInterface * @throws \LogicException If one of the listener does not behave as expected * @throws NotFoundHttpException When controller cannot be found */ - public function handleRaw(Request $request, $main = true) + protected function handleRaw(Request $request, $main = true) { $main = (Boolean) $main; diff --git a/src/Symfony/Components/HttpKernel/HttpKernelInterface.php b/src/Symfony/Components/HttpKernel/HttpKernelInterface.php index 4ce25ca62b..300ae5d21a 100644 --- a/src/Symfony/Components/HttpKernel/HttpKernelInterface.php +++ b/src/Symfony/Components/HttpKernel/HttpKernelInterface.php @@ -25,12 +25,11 @@ interface HttpKernelInterface * * @param Request $request A Request instance * @param Boolean $main Whether this is the main request or not + * @param Boolean $raw Whether to catch exceptions or not * * @return Response $response A Response instance - * - * @throws \Exception When Exception couldn't be caught by event processing */ - public function handle(Request $request = null, $main = true); + public function handle(Request $request = null, $main = true, $raw = false); /** * Gets the Request instance associated with the main request. diff --git a/src/Symfony/Foundation/Kernel.php b/src/Symfony/Foundation/Kernel.php index dc6e3e8126..1fb3352c09 100644 --- a/src/Symfony/Foundation/Kernel.php +++ b/src/Symfony/Foundation/Kernel.php @@ -172,8 +172,6 @@ abstract class Kernel implements HttpKernelInterface, \Serializable * @param Boolean $raw Whether to catch exceptions or not * * @return Response $response A Response instance - * - * @throws \Exception */ public function handle(Request $request = null, $main = true, $raw = false) { @@ -196,14 +194,7 @@ abstract class Kernel implements HttpKernelInterface, \Serializable $this->request = $request; } - if (true === $raw) - { - return $this->container->getHttpKernelService()->handleRaw($request, $main); - } - else - { - return $this->container->getHttpKernelService()->handle($request, $main); - } + return $this->container->getHttpKernelService()->handle($request, $main, $raw); } public function getBundleDirs() diff --git a/src/Symfony/Foundation/bootstrap.php b/src/Symfony/Foundation/bootstrap.php index e4ea37cbbb..bf56c5db62 100644 --- a/src/Symfony/Foundation/bootstrap.php +++ b/src/Symfony/Foundation/bootstrap.php @@ -497,14 +497,7 @@ abstract class Kernel implements HttpKernelInterface, \Serializable $this->request = $request; } - if (true === $raw) - { - return $this->container->getHttpKernelService()->handleRaw($request, $main); - } - else - { - return $this->container->getHttpKernelService()->handle($request, $main); - } + return $this->container->getHttpKernelService()->handle($request, $main, $raw); } public function getBundleDirs() diff --git a/src/Symfony/Framework/WebBundle/Listener/ControllerLoader.php b/src/Symfony/Framework/WebBundle/Listener/ControllerLoader.php index 3d97f82231..ecdde008d8 100644 --- a/src/Symfony/Framework/WebBundle/Listener/ControllerLoader.php +++ b/src/Symfony/Framework/WebBundle/Listener/ControllerLoader.php @@ -47,7 +47,7 @@ class ControllerLoader $subRequest = $request->duplicate($query, null, $path); - $response = $this->container->getHttpKernelService()->handleRaw($subRequest, false); + $response = $this->container->handle($subRequest, false, true); $this->container->setService('request', $request); diff --git a/src/Symfony/Framework/WebBundle/Listener/ExceptionHandler.php b/src/Symfony/Framework/WebBundle/Listener/ExceptionHandler.php index d7eab6d253..fdfc4ed9d9 100644 --- a/src/Symfony/Framework/WebBundle/Listener/ExceptionHandler.php +++ b/src/Symfony/Framework/WebBundle/Listener/ExceptionHandler.php @@ -72,7 +72,7 @@ class ExceptionHandler try { - $response = $event->getSubject()->handleRaw($request, false); + $response = $event->getSubject()->handle($request, false, true); error_log(sprintf('%s: %s', get_class($exception), $exception->getMessage())); }