\Drupal\Core\Routing\UrlMatcher is dead code

Created on 21 September 2021, over 3 years ago
Updated 6 February 2023, almost 2 years ago

Problem/Motivation

Discovered in #3233047: Drupal\Core\Routing\RequestContext::fromRequest() should be returning $this β†’ we have an unused method in \Drupal\Core\Routing\UrlMatcher:

  public function finalMatch(RouteCollection $collection, Request $request) {

This was part of Symfony CMF's interface, but #2917331: Decouple from Symfony CMF β†’ removed Symfony CMF from core and so this method is no longer required.

It further transpires that \Drupal\Core\Routing\UrlMatcher is a deprecated service that was removed from core in #3114192: Remove deprecated services in core.services.yml β†’ but the class itself was not removed.

Steps to reproduce

Proposed resolution

Remove the class.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ“Œ Task
Status

Needs work

Version

10.1 ✨

Component
RoutingΒ  β†’

Last updated 3 days ago

Created by

πŸ‡¬πŸ‡§United Kingdom longwave UK

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Should this be closed as a duplicate

  • Status changed to Needs work almost 2 years ago
  • πŸ‡«πŸ‡·France andypost

    No, this one is to deprecate UrlMatcher and use the one from Symfony
    But second is about AccessAwareRouter polishing

    Setting needs work for change record and proper deprecation of the class according https://www.drupal.org/about/core/policies/core-change-policies/drupal-d... β†’

    +++ b/core/lib/Drupal/Core/Routing/Router.php
    @@ -7,7 +7,8 @@
    +use Symfony\Component\Routing\Matcher\UrlMatcher;
    
    @@ -28,7 +29,7 @@
    -class Router extends UrlMatcher implements RequestMatcherInterface, RouterInterface {
    +class Router extends UrlMatcher implements RouterInterface {
    
    +++ /dev/null
    @@ -1,58 +0,0 @@
    -class UrlMatcher extends BaseUrlMatcher {
    

    Filed change record https://www.drupal.org/node/3339050 β†’

  • πŸ‡«πŸ‡·France andypost

    Btw core's UrlMatcher still very different implementation from SF one

      protected function getAttributes(Route $route, $name, array $attributes): array {
        if ($route instanceof RouteObjectInterface && is_string($route->getRouteKey())) {
          $name = $route->getRouteKey();
        }
        $attributes[RouteObjectInterface::ROUTE_NAME] = $name;
        $attributes[RouteObjectInterface::ROUTE_OBJECT] = $route;
    
        return $this->mergeDefaults($attributes, $route->getDefaults());
      }
    

    SF code

        protected function getAttributes(Route $route, string $name, array $attributes): array
        {
            $defaults = $route->getDefaults();
            if (isset($defaults['_canonical_route'])) {
                $name = $defaults['_canonical_route'];
                unset($defaults['_canonical_route']);
            }
            $attributes['_route'] = $name;
    
            return $this->mergeDefaults($attributes, $defaults);
        }
    
Production build 0.71.5 2024