Remove no-longer-needed RouterListener subclass. We can use the Symfony one directly now.

8.0.x
Larry Garfield 2012-09-22 13:21:10 -05:00 committed by effulgentsia
parent 5ae1aca2df
commit 126bb1903f
1 changed files with 0 additions and 96 deletions

View File

@ -1,96 +0,0 @@
<?php
/**
* @file
* Definition of Drupal\Core\EventSubscriber\RouterListener.
*/
namespace Drupal\Core\EventSubscriber;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\EventListener\RouterListener as SymfonyRouterListener;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
use Symfony\Component\HttpKernel\Log\LoggerInterface;
use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
/**
* Drupal-specific Router listener.
*
* This is the bridge from the kernel to the UrlMatcher.
*/
class RouterListener extends SymfonyRouterListener {
/**
* The Matcher object for this listener.
*
* This property is private in the base class, so we have to hack around it.
*
* @var Symfony\Component\Router\Matcher\UrlMatcherInterface
*/
protected $urlMatcher;
/**
* The Logging object for this listener.
*
* This property is private in the base class, so we have to hack around it.
*
* @var Symfony\Component\HttpKernel\Log\LoggerInterface
*/
protected $logger;
public function __construct(UrlMatcherInterface $urlMatcher, LoggerInterface $logger = null) {
parent::__construct($urlMatcher, $logger);
$this->urlMatcher = $urlMatcher;
$this->logger = $logger;
}
/**
* {@inheritdoc}
*
* This method is nearly identical to the parent, except it passes the
* $request->attributes->get('system_path') variable to the matcher.
* That is where Drupal stores its processed, de-aliased, and sanitized
* internal path. We also pass the full request object to the URL Matcher,
* since we want attributes to be available to the matcher and to controllers.
*/
public function onKernelRequest(GetResponseEvent $event) {
$request = $event->getRequest();
if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
$this->urlMatcher->getContext()->fromRequest($request);
$this->urlMatcher->setRequest($request);
}
if ($request->attributes->has('_controller')) {
// Routing is already done.
return;
}
// Add attributes based on the path info (routing).
try {
$parameters = $this->urlMatcher->match($request->attributes->get('system_path'));
if (null !== $this->logger) {
$this->logger->info(sprintf('Matched route "%s" (parameters: %s)', $parameters['_route'], $this->parametersToString($parameters)));
}
$request->attributes->add($parameters);
unset($parameters['_route']);
unset($parameters['_controller']);
$request->attributes->set('_route_params', $parameters);
}
catch (ResourceNotFoundException $e) {
$message = sprintf('No route found for "%s %s"', $request->getMethod(), $request->getPathInfo());
throw new NotFoundHttpException($message, $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())));
throw new MethodNotAllowedHttpException($e->getAllowedMethods(), $message, $e);
}
}
}