Unverified Commit 47485748 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3540398 by catch: Remove Url generator from router class

parent 6c0071f6
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1115,7 +1115,7 @@ services:
  Drupal\Core\Routing\AccessAwareRouterInterface: '@router'
  router.no_access_checks:
    class: \Drupal\Core\Routing\Router
    arguments: ['@router.route_provider', '@path.current', '@url_generator']
    arguments: ['@router.route_provider', '@path.current']
    tags:
      - { name: service_collector, tag: route_enhancer, call: addRouteEnhancer  }
      - { name: service_collector, tag: route_filter, call: addRouteFilter }
+8 −12
Original line number Diff line number Diff line
@@ -3,11 +3,11 @@
namespace Drupal\Core\Routing;

use Drupal\Core\Path\CurrentPathStack;
use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
use Symfony\Component\HttpFoundation\Exception\BadRequestException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface as BaseUrlGeneratorInterface;
use Symfony\Component\Routing\Matcher\RequestMatcherInterface;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\RouterInterface;
@@ -30,6 +30,12 @@
 *    See ::applyRouteEnhancers().
 */
class Router extends UrlMatcher implements RequestMatcherInterface, RouterInterface {
  use DeprecatedServicePropertyTrait;

  /**
   * The service properties that should raise a deprecation error.
   */
  private array $deprecatedProperties = ['urlGenerator' => 'url_generator'];

  /**
   * The route provider responsible for the first-pass match.
@@ -52,13 +58,6 @@ class Router extends UrlMatcher implements RequestMatcherInterface, RouterInterf
   */
  protected $filters = [];

  /**
   * The URL generator.
   *
   * @var \Symfony\Component\Routing\Generator\UrlGeneratorInterface
   */
  protected $urlGenerator;

  /**
   * Constructs a new Router.
   *
@@ -66,13 +65,10 @@ class Router extends UrlMatcher implements RequestMatcherInterface, RouterInterf
   *   The route provider.
   * @param \Drupal\Core\Path\CurrentPathStack $current_path
   *   The current path stack.
   * @param \Symfony\Component\Routing\Generator\UrlGeneratorInterface $url_generator
   *   The URL generator.
   */
  public function __construct(RouteProviderInterface $route_provider, CurrentPathStack $current_path, BaseUrlGeneratorInterface $url_generator) {
  public function __construct(RouteProviderInterface $route_provider, CurrentPathStack $current_path) {
    parent::__construct($current_path);
    $this->routeProvider = $route_provider;
    $this->urlGenerator = $url_generator;
  }

  /**
+1 −3
Original line number Diff line number Diff line
@@ -9,7 +9,6 @@
use Drupal\Core\Routing\RouteCompiler;
use Drupal\Core\Routing\RouteProviderInterface;
use Drupal\Core\Routing\Router;
use Drupal\Core\Routing\UrlGeneratorInterface;
use Drupal\Tests\UnitTestCase;
use Prophecy\Argument;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
@@ -41,9 +40,8 @@ public function testMatchesWithDifferentFitOrder(): void {
    $route_provider->getRouteCollectionForRequest(Argument::any())
      ->willReturn($route_collection);

    $url_generator = $this->prophesize(UrlGeneratorInterface::class);
    $current_path_stack = $this->prophesize(CurrentPathStack::class);
    $router = new Router($route_provider->reveal(), $current_path_stack->reveal(), $url_generator->reveal());
    $router = new Router($route_provider->reveal(), $current_path_stack->reveal());

    $request_context = $this->createMock(RequestContext::class);
    $request_context->expects($this->any())
+1 −8
Original line number Diff line number Diff line
@@ -7,9 +7,7 @@
use Drupal\Core\Path\CurrentPathStack;
use Drupal\Core\Routing\RouteProviderInterface;
use Drupal\Core\Routing\Router;
use Drupal\Core\Routing\UrlGeneratorInterface;
use Drupal\Tests\UnitTestCase;
use Prophecy\Argument;

/**
 * @coversDefaultClass \Drupal\Core\Routing\Router
@@ -25,13 +23,8 @@ public function testGenerateUnsupported(): void {
    $this->expectException(\BadMethodCallException::class);
    $route_provider = $this->prophesize(RouteProviderInterface::class);
    $current_path_stack = $this->prophesize(CurrentPathStack::class);
    $url_generator = $this->prophesize(UrlGeneratorInterface::class);
    $route_name = 'test.route';
    $route_path = '/test';
    $url_generator
      ->generate($route_name, Argument::any(), Argument::any())
      ->willReturn($route_path);
    $router = new Router($route_provider->reveal(), $current_path_stack->reveal(), $url_generator->reveal());
    $router = new Router($route_provider->reveal(), $current_path_stack->reveal());
    $router->generate($route_name);
  }