|
@@ -14,9 +14,13 @@ namespace Symfony\Bundle\FrameworkBundle;
|
|
|
use Symfony\Component\HttpKernel\Log\LoggerInterface;
|
|
|
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
|
|
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
|
|
+use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
|
|
|
+use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
-use Symfony\Component\Routing\RouterInterface;
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
|
+use Symfony\Component\Routing\Matcher\Exception\MethodNotAllowedException;
|
|
|
+use Symfony\Component\Routing\Matcher\Exception\NotFoundException;
|
|
|
+use Symfony\Component\Routing\RouterInterface;
|
|
|
|
|
|
/**
|
|
|
* RequestListener.
|
|
@@ -83,7 +87,9 @@ class RequestListener
|
|
|
}
|
|
|
|
|
|
// add attributes based on the path info (routing)
|
|
|
- if (false !== $parameters = $this->router->match($request->getPathInfo())) {
|
|
|
+ try {
|
|
|
+ $parameters = $this->router->match($request->getPathInfo());
|
|
|
+
|
|
|
if (null !== $this->logger) {
|
|
|
$this->logger->info(sprintf('Matched route "%s" (parameters: %s)', $parameters['_route'], json_encode($parameters)));
|
|
|
}
|
|
@@ -93,8 +99,18 @@ class RequestListener
|
|
|
if ($locale = $request->attributes->get('_locale')) {
|
|
|
$request->getSession()->setLocale($locale);
|
|
|
}
|
|
|
- } elseif (null !== $this->logger) {
|
|
|
- $this->logger->err(sprintf('No route found for %s', $request->getPathInfo()));
|
|
|
+ } catch (NotFoundException $e) {
|
|
|
+ $message = sprintf('No route found for "%s %s"', $request->getMethod(), $request->getPathInfo());
|
|
|
+ if (null !== $this->logger) {
|
|
|
+ $this->logger->err($message);
|
|
|
+ }
|
|
|
+ throw new NotFoundHttpException('Not Found', $message, 0, $e);
|
|
|
+ } catch (MethodNotAllowedException $e) {
|
|
|
+ $message = sprintf('No route found for "%s %s": Method Not Allowed (Allow: %s)', $request->getMethod(), $request->getPathInfo(), strtoupper(implode(', ', $e->getAllowedMethods())));
|
|
|
+ if (null !== $this->logger) {
|
|
|
+ $this->logger->err($message);
|
|
|
+ }
|
|
|
+ throw new MethodNotAllowedHttpException($e->getAllowedMethods(), 'Method Not Allowed', $message, 0, $e);
|
|
|
}
|
|
|
}
|
|
|
}
|