Commit 47e02334 authored by Crell's avatar Crell
Browse files

Switch to a new UrlMatcher and RouterListener so that we can use a full...

Switch to a new UrlMatcher and RouterListener so that we can use a full Request object for routing purposes, and look to the attributes for our main routing information.
parent fb620e79
......@@ -17,7 +17,7 @@
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\EventListener\RouterListener;
//use Symfony\Component\HttpKernel\EventListener\RouterListener;
use Symfony\Component\HttpKernel\EventListener\ExceptionListener;
use Drupal\Core\EventSubscriber\ViewSubscriber;
use Drupal\Core\EventSubscriber\AccessSubscriber;
......@@ -25,6 +25,7 @@
use Drupal\Core\EventSubscriber\LegacyControllerSubscriber;
use Drupal\Core\EventSubscriber\MaintenanceModeSubscriber;
use Drupal\Core\EventSubscriber\RequestCloseSubscriber;
use Drupal\Core\EventSubscriber\RouterListener;
use Exception;
......@@ -61,8 +62,7 @@ public function __construct(EventDispatcherInterface $dispatcher, ControllerReso
$this->dispatcher = $dispatcher;
$this->resolver = $resolver;
$context = new RequestContext();
$this->matcher = new UrlMatcher($context);
$this->matcher = new UrlMatcher();
$this->dispatcher->addSubscriber(new RouterListener($this->matcher));
$negotiation = new ContentNegotiation();
......
<?php
namespace Drupal\Core\EventSubscriber;
use Symfony\Component\HttpKernel\EventListener\RouterListener as SymfonyRouterListener;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
/**
* Description of RouterListener
*
* @author crell
*/
class RouterListener extends SymfonyRouterListener {
protected $urlMatcher;
public function __construct(UrlMatcherInterface $urlMatcher, LoggerInterface $logger = null) {
parent::__construct($urlMatcher, $logger);
$this->urlMatcher = $urlMatcher;
}
public function onKernelRequest(GetResponseEvent $event) {
$this->urlMatcher->setRequest($event->getRequest());
parent::onKernelRequest($event);
}
}
......@@ -8,8 +8,10 @@
namespace Drupal\Core;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
use Symfony\Component\Routing\Matcher\UrlMatcher as SymfonyUrlMatcher;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\Route;
......@@ -18,7 +20,7 @@
/**
* UrlMatcher matches URL based on a set of routes.
*/
class UrlMatcher extends SymfonyUrlMatcher {
class UrlMatcher implements UrlMatcherInterface {
/**
* The request context for this matcher.
......@@ -28,15 +30,56 @@ class UrlMatcher extends SymfonyUrlMatcher {
protected $context;
/**
* Constructor.
* The request object for this matcher.
*
* @param RequestContext $context
* The request context object.
* @var Symfony\Component\HttpFoundation\Request
*/
public function __construct(RequestContext $context) {
protected $request;
public function __construct() {
// We will not actually use this object, but it's needed to conform to
// the interface.
$this->context = new RequestContext();
}
/**
* Sets the request context.
*
* This method is just to satisfy the interface, and is largely vestigial.
* The request context object does not contain the information we need, so
* we will use the original request object.
*
* @param RequestContext $context
* The context
*
* @api
*/
public function setContext(RequestContext $context) {
$this->context = $context;
}
/**
* Gets the request context.
*
* This method is just to satisfy the interface, and is largely vestigial.
* The request context object does not contain the information we need, so
* we will use the original request object.
*
* @return RequestContext
* The context
*/
public function getContext() {
return $this->context;
}
public function setRequest(Request $request) {
$this->request = $request;
}
public function getRequest() {
return $this->request;
}
/**
* {@inheritDoc}
*
......@@ -44,15 +87,16 @@ public function __construct(RequestContext $context) {
*/
public function match($pathinfo) {
$this->allow = array();
$dpathinfo = $this->request->attributes->get('system_path');
// Symfony uses a prefixing / but we don't yet.
$dpathinfo = ltrim($pathinfo, '/');
if (!$dpathinfo) {
// Symfony uses a prefixing / but we don't yet.
$dpathinfo = ltrim($pathinfo, '/');
}
// Do our fancy frontpage logic.
if (empty($dpathinfo)) {
$dpathinfo = variable_get('site_frontpage', 'user');
$pathinfo = '/' . $dpathinfo;
}
if ($router_item = $this->matchDrupalItem($dpathinfo)) {
......
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