diff --git a/core/core.services.yml b/core/core.services.yml
index 21a3e590ba..af82ef92dc 100644
--- a/core/core.services.yml
+++ b/core/core.services.yml
@@ -823,16 +823,6 @@ services:
     tags:
       - { name: service_collector, tag: non_lazy_route_filter, call: addRouteFilter }
     deprecated: The "%service_id%" service is deprecated. You should use the 'router.no_access_checks' service instead.
-  route_filter.lazy_collector:
-    class: Drupal\Core\Routing\LazyRouteFilter
-    tags:
-      - { name: non_lazy_route_filter }
-    parent: container.trait
-  route_filter_subscriber:
-    class: Drupal\Core\EventSubscriber\RouteFilterSubscriber
-    arguments: ['@route_filter.lazy_collector']
-    tags:
-      - { name: event_subscriber }
   url_generator.non_bubbling:
     class: Drupal\Core\Routing\UrlGenerator
     arguments: ['@router.route_provider', '@path_processor_manager', '@route_processor_manager', '@request_stack', '%filter_protocols%']
@@ -864,10 +854,12 @@ services:
     deprecated: The "%service_id%" service is deprecated. You should use the 'router.no_access_checks' service instead.
   router.no_access_checks:
     class: \Drupal\Core\Routing\Router
-    arguments: ['@router.route_provider', '@path.current', '@url_generator']
+    arguments: ['@router.route_provider', '@path.current', '@url_generator', '@class_resolver']
     tags:
       - { name: service_collector, tag: non_lazy_route_enhancer, call: addRouteEnhancer }
+      - { name: service_collector, tag: route_enhancer, call: addRouteEnhancer  }
       - { name: service_collector, tag: non_lazy_route_filter, call: addRouteFilter }
+      - { name: service_collector, tag: route_filter, call: addRouteFilter }
     calls:
       - [setContext, ['@router.request_context']]
   router.path_roots_subscriber:
@@ -997,21 +989,11 @@ services:
     arguments: ['@form_ajax_response_builder', '@string_translation']
     tags:
       - { name: event_subscriber }
-  route_enhancer.lazy_collector:
-    class: Drupal\Core\Routing\LazyRouteEnhancer
-    tags:
-      - { name: non_lazy_route_enhancer, priority: 5000 }
-    parent: container.trait
-  route_enhancer_subscriber:
-    class: Drupal\Core\EventSubscriber\RouteEnhancerSubscriber
-    arguments: ['@route_enhancer.lazy_collector']
-    tags:
-      - { name: event_subscriber }
   route_enhancer.param_conversion:
     class: Drupal\Core\Routing\Enhancer\ParamConversionEnhancer
     arguments: ['@paramconverter_manager']
     tags:
-      - { name: route_enhancer }
+      - { name: route_enhancer, priority: 5000 }
       - { name: event_subscriber }
   route_enhancer.form:
     class: Drupal\Core\Routing\Enhancer\FormRouteEnhancer
diff --git a/core/lib/Drupal/Core/CoreServiceProvider.php b/core/lib/Drupal/Core/CoreServiceProvider.php
index 8a22bc50d4..e07046ae0a 100644
--- a/core/lib/Drupal/Core/CoreServiceProvider.php
+++ b/core/lib/Drupal/Core/CoreServiceProvider.php
@@ -10,8 +10,6 @@
 use Drupal\Core\DependencyInjection\Compiler\GuzzleMiddlewarePass;
 use Drupal\Core\DependencyInjection\Compiler\ContextProvidersPass;
 use Drupal\Core\DependencyInjection\Compiler\ProxyServicesPass;
-use Drupal\Core\DependencyInjection\Compiler\RegisterLazyRouteEnhancers;
-use Drupal\Core\DependencyInjection\Compiler\RegisterLazyRouteFilters;
 use Drupal\Core\DependencyInjection\Compiler\DependencySerializationTraitPass;
 use Drupal\Core\DependencyInjection\Compiler\StackedKernelPass;
 use Drupal\Core\DependencyInjection\Compiler\StackedSessionHandlerPass;
@@ -84,8 +82,6 @@ public function register(ContainerBuilder $container) {
     $container->addCompilerPass(new RegisterEventSubscribersPass(), PassConfig::TYPE_AFTER_REMOVING);
 
     $container->addCompilerPass(new RegisterAccessChecksPass());
-    $container->addCompilerPass(new RegisterLazyRouteEnhancers());
-    $container->addCompilerPass(new RegisterLazyRouteFilters());
 
     // Add a compiler pass for registering services needing destruction.
     $container->addCompilerPass(new RegisterServicesForDestructionPass());
diff --git a/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterLazyRouteEnhancers.php b/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterLazyRouteEnhancers.php
deleted file mode 100644
index 8e2929b860..0000000000
--- a/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterLazyRouteEnhancers.php
+++ /dev/null
@@ -1,32 +0,0 @@
-<?php
-
-namespace Drupal\Core\DependencyInjection\Compiler;
-
-use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
-use Symfony\Component\DependencyInjection\ContainerBuilder;
-
-/**
- * Registers all lazy route enhancers onto the lazy route enhancers.
- */
-class RegisterLazyRouteEnhancers implements CompilerPassInterface {
-
-  /**
-   * {@inheritdoc}
-   */
-  public function process(ContainerBuilder $container) {
-    if (!$container->hasDefinition('route_enhancer.lazy_collector')) {
-      return;
-    }
-
-    $service_ids = [];
-
-    foreach ($container->findTaggedServiceIds('route_enhancer') as $id => $attributes) {
-      $service_ids[$id] = $id;
-    }
-
-    $container
-      ->getDefinition('route_enhancer.lazy_collector')
-      ->addArgument($service_ids);
-  }
-
-}
diff --git a/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterLazyRouteFilters.php b/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterLazyRouteFilters.php
deleted file mode 100644
index d77477921b..0000000000
--- a/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterLazyRouteFilters.php
+++ /dev/null
@@ -1,32 +0,0 @@
-<?php
-
-namespace Drupal\Core\DependencyInjection\Compiler;
-
-use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
-use Symfony\Component\DependencyInjection\ContainerBuilder;
-
-/**
- * Registers all lazy route filters onto the lazy route filter.
- */
-class RegisterLazyRouteFilters implements CompilerPassInterface {
-
-  /**
-   * {@inheritdoc}
-   */
-  public function process(ContainerBuilder $container) {
-    if (!$container->hasDefinition('route_filter.lazy_collector')) {
-      return;
-    }
-
-    $service_ids = [];
-
-    foreach ($container->findTaggedServiceIds('route_filter') as $id => $attributes) {
-      $service_ids[$id] = $id;
-    }
-
-    $container
-      ->getDefinition('route_filter.lazy_collector')
-      ->addArgument($service_ids);
-  }
-
-}
diff --git a/core/lib/Drupal/Core/Entity/Enhancer/EntityRouteEnhancer.php b/core/lib/Drupal/Core/Entity/Enhancer/EntityRouteEnhancer.php
index 287464985b..af640ec3f7 100644
--- a/core/lib/Drupal/Core/Entity/Enhancer/EntityRouteEnhancer.php
+++ b/core/lib/Drupal/Core/Entity/Enhancer/EntityRouteEnhancer.php
@@ -2,9 +2,8 @@
 
 namespace Drupal\Core\Entity\Enhancer;
 
-use Drupal\Core\Routing\Enhancer\RouteEnhancerInterface;
+use Symfony\Cmf\Component\Routing\Enhancer\RouteEnhancerInterface;
 use Symfony\Component\HttpFoundation\Request;
-use Symfony\Component\Routing\Route;
 use Symfony\Cmf\Component\Routing\RouteObjectInterface;
 
 /**
@@ -16,6 +15,15 @@ class EntityRouteEnhancer implements RouteEnhancerInterface {
    * {@inheritdoc}
    */
   public function enhance(array $defaults, Request $request) {
+    $route = $defaults[RouteObjectInterface::ROUTE_OBJECT];
+    if ($route->hasDefault('_controller') ||
+      !($route->hasDefault('_entity_form')
+        || $route->hasDefault('_entity_list')
+        || $route->hasDefault('_entity_view')
+      )) {
+      return $defaults;
+    }
+
     if (empty($defaults['_controller'])) {
       if (!empty($defaults['_entity_form'])) {
         $defaults = $this->enhanceEntityForm($defaults, $request);
@@ -31,17 +39,6 @@ public function enhance(array $defaults, Request $request) {
   }
 
   /**
-   * {@inheritdoc}
-   */
-  public function applies(Route $route) {
-    return !$route->hasDefault('_controller') &&
-      ($route->hasDefault('_entity_form')
-        || $route->hasDefault('_entity_list')
-        || $route->hasDefault('_entity_view')
-      );
-  }
-
-  /**
    * Update defaults for entity forms.
    *
    * @param array $defaults
diff --git a/core/lib/Drupal/Core/EventSubscriber/RouteEnhancerSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/RouteEnhancerSubscriber.php
deleted file mode 100644
index 8763842b58..0000000000
--- a/core/lib/Drupal/Core/EventSubscriber/RouteEnhancerSubscriber.php
+++ /dev/null
@@ -1,48 +0,0 @@
-<?php
-
-namespace Drupal\Core\EventSubscriber;
-
-use Drupal\Core\Routing\LazyRouteEnhancer;
-use Drupal\Core\Routing\RouteBuildEvent;
-use Drupal\Core\Routing\RoutingEvents;
-use Symfony\Component\EventDispatcher\EventSubscriberInterface;
-
-/**
- * Listens to the new routes before they get saved.
- */
-class RouteEnhancerSubscriber implements EventSubscriberInterface {
-
-  /**
-   * @var \Drupal\Core\Routing\LazyRouteEnhancer
-   */
-  protected $routeEnhancer;
-
-  /**
-   * Constructs the RouteEnhancerSubscriber object.
-   *
-   * @param \Drupal\Core\Routing\LazyRouteEnhancer $route_enhancer
-   *   The lazy route enhancer.
-   */
-  public function __construct(LazyRouteEnhancer $route_enhancer) {
-    $this->routeEnhancer = $route_enhancer;
-  }
-
-  /**
-   * Adds the route_enhancer object to the route collection.
-   *
-   * @param \Drupal\Core\Routing\RouteBuildEvent $event
-   *   The route build event.
-   */
-  public function onRouteAlter(RouteBuildEvent $event) {
-    $this->routeEnhancer->setEnhancers($event->getRouteCollection());
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public static function getSubscribedEvents() {
-    $events[RoutingEvents::ALTER][] = ['onRouteAlter', -300];
-    return $events;
-  }
-
-}
diff --git a/core/lib/Drupal/Core/EventSubscriber/RouteFilterSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/RouteFilterSubscriber.php
deleted file mode 100644
index f64b8db514..0000000000
--- a/core/lib/Drupal/Core/EventSubscriber/RouteFilterSubscriber.php
+++ /dev/null
@@ -1,50 +0,0 @@
-<?php
-
-namespace Drupal\Core\EventSubscriber;
-
-use Drupal\Core\Routing\LazyRouteFilter;
-use Drupal\Core\Routing\RouteBuildEvent;
-use Drupal\Core\Routing\RoutingEvents;
-use Symfony\Component\EventDispatcher\EventSubscriberInterface;
-
-/**
- * Listens to the filtered collection of route instances.
- */
-class RouteFilterSubscriber implements EventSubscriberInterface {
-
-  /**
-   * The lazy route filter.
-   *
-   * @var \Drupal\Core\Routing\LazyRouteFilter
-   */
-  protected $routeFilter;
-
-  /**
-   * Constructs the RouteFilterSubscriber object.
-   *
-   * @param \Drupal\Core\Routing\LazyRouteFilter $route_filter
-   *   The lazy route filter.
-   */
-  public function __construct(LazyRouteFilter $route_filter) {
-    $this->routeFilter = $route_filter;
-  }
-
-  /**
-   * Get the Response object from filtered route collection.
-   *
-   * @param \Drupal\Core\Routing\RouteBuildEvent $event
-   *   The route build event.
-   */
-  public function onRouteAlter(RouteBuildEvent $event) {
-    $this->routeFilter->setFilters($event->getRouteCollection());
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public static function getSubscribedEvents() {
-    $events[RoutingEvents::ALTER][] = ['onRouteAlter', -300];
-    return $events;
-  }
-
-}
diff --git a/core/lib/Drupal/Core/Routing/ContentTypeHeaderMatcher.php b/core/lib/Drupal/Core/Routing/ContentTypeHeaderMatcher.php
index 13e18f35a9..6bed3b42e9 100644
--- a/core/lib/Drupal/Core/Routing/ContentTypeHeaderMatcher.php
+++ b/core/lib/Drupal/Core/Routing/ContentTypeHeaderMatcher.php
@@ -4,13 +4,13 @@
 
 use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException;
-use Symfony\Component\Routing\Route;
 use Symfony\Component\Routing\RouteCollection;
+use Symfony\Cmf\Component\Routing\NestedMatcher\RouteFilterInterface as BaseRouteFilterInterface;
 
 /**
  * Filters routes based on the HTTP Content-type header.
  */
-class ContentTypeHeaderMatcher implements RouteFilterInterface {
+class ContentTypeHeaderMatcher implements BaseRouteFilterInterface {
 
   /**
    * {@inheritdoc}
@@ -50,11 +50,4 @@ public function filter(RouteCollection $collection, Request $request) {
     }
   }
 
-  /**
-   * {@inheritdoc}
-   */
-  public function applies(Route $route) {
-    return TRUE;
-  }
-
 }
diff --git a/core/lib/Drupal/Core/Routing/Enhancer/EntityRevisionRouteEnhancer.php b/core/lib/Drupal/Core/Routing/Enhancer/EntityRevisionRouteEnhancer.php
index 9880edd523..7cca560147 100644
--- a/core/lib/Drupal/Core/Routing/Enhancer/EntityRevisionRouteEnhancer.php
+++ b/core/lib/Drupal/Core/Routing/Enhancer/EntityRevisionRouteEnhancer.php
@@ -5,16 +5,19 @@
 use Symfony\Cmf\Component\Routing\RouteObjectInterface;
 use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\Routing\Route;
+use Symfony\Cmf\Component\Routing\Enhancer\RouteEnhancerInterface as BaseRouteEnhancerInterface;
 
 /**
  * Adds _entity_revision to the request attributes, if possible.
  */
-class EntityRevisionRouteEnhancer implements RouteEnhancerInterface {
+class EntityRevisionRouteEnhancer implements BaseRouteEnhancerInterface {
 
   /**
-   * {@inheritdoc}
+   * Returns whether the enhancer runs on the current route.
+   *
+   * @return bool
    */
-  public function applies(Route $route) {
+  protected function applies(Route $route) {
     // Check whether there is any entity revision parameter.
     $parameters = $route->getOption('parameters') ?: [];
     foreach ($parameters as $info) {
@@ -31,6 +34,10 @@ public function applies(Route $route) {
   public function enhance(array $defaults, Request $request) {
     /** @var \Symfony\Component\Routing\Route $route */
     $route = $defaults[RouteObjectInterface::ROUTE_OBJECT];
+    if (!$this->applies($route)) {
+      return $defaults;
+    }
+
     $options = $route->getOptions();
     if (isset($options['parameters'])) {
       foreach ($options['parameters'] as $name => $details) {
diff --git a/core/lib/Drupal/Core/Routing/Enhancer/FormRouteEnhancer.php b/core/lib/Drupal/Core/Routing/Enhancer/FormRouteEnhancer.php
index d2bdb1209e..88e18fb6f7 100644
--- a/core/lib/Drupal/Core/Routing/Enhancer/FormRouteEnhancer.php
+++ b/core/lib/Drupal/Core/Routing/Enhancer/FormRouteEnhancer.php
@@ -2,25 +2,24 @@
 
 namespace Drupal\Core\Routing\Enhancer;
 
+use Symfony\Cmf\Component\Routing\RouteObjectInterface;
 use Symfony\Component\HttpFoundation\Request;
-use Symfony\Component\Routing\Route;
+use Symfony\Cmf\Component\Routing\Enhancer\RouteEnhancerInterface as BaseRouteEnhancerInterface;
 
 /**
  * Enhancer to add a wrapping controller for _form routes.
  */
-class FormRouteEnhancer implements RouteEnhancerInterface {
-
-  /**
-   * {@inheritdoc}
-   */
-  public function applies(Route $route) {
-    return $route->hasDefault('_form') && !$route->hasDefault('_controller');
-  }
+class FormRouteEnhancer implements BaseRouteEnhancerInterface {
 
   /**
    * {@inheritdoc}
    */
   public function enhance(array $defaults, Request $request) {
+    $route = $defaults[RouteObjectInterface::ROUTE_OBJECT];
+    if (!$route->hasDefault('_form') || $route->hasDefault('_controller')) {
+      return $defaults;
+    }
+
     $defaults['_controller'] = 'controller.form:getContentResult';
     return $defaults;
   }
diff --git a/core/lib/Drupal/Core/Routing/Enhancer/ParamConversionEnhancer.php b/core/lib/Drupal/Core/Routing/Enhancer/ParamConversionEnhancer.php
index 09d6148118..70bfc8cfea 100644
--- a/core/lib/Drupal/Core/Routing/Enhancer/ParamConversionEnhancer.php
+++ b/core/lib/Drupal/Core/Routing/Enhancer/ParamConversionEnhancer.php
@@ -11,12 +11,12 @@
 use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
 use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
 use Symfony\Component\HttpKernel\KernelEvents;
-use Symfony\Component\Routing\Route;
+use Symfony\Cmf\Component\Routing\Enhancer\RouteEnhancerInterface as BaseRouteEnhancerInterface;
 
 /**
  * Provides a route enhancer that handles parameter conversion.
  */
-class ParamConversionEnhancer implements RouteEnhancerInterface, EventSubscriberInterface {
+class ParamConversionEnhancer implements BaseRouteEnhancerInterface, EventSubscriberInterface {
 
   /**
    * The parameter conversion manager.
@@ -89,11 +89,4 @@ public static function getSubscribedEvents() {
     return $events;
   }
 
-  /**
-   * {@inheritdoc}
-   */
-  public function applies(Route $route) {
-    return TRUE;
-  }
-
 }
diff --git a/core/lib/Drupal/Core/Routing/Enhancer/RouteEnhancerInterface.php b/core/lib/Drupal/Core/Routing/Enhancer/RouteEnhancerInterface.php
index d6be823b5e..369aba9c9d 100644
--- a/core/lib/Drupal/Core/Routing/Enhancer/RouteEnhancerInterface.php
+++ b/core/lib/Drupal/Core/Routing/Enhancer/RouteEnhancerInterface.php
@@ -5,8 +5,14 @@
 use Symfony\Cmf\Component\Routing\Enhancer\RouteEnhancerInterface as BaseRouteEnhancerInterface;
 use Symfony\Component\Routing\Route;
 
+@trigger_error('\Drupal\Core\Routing\Enhancer\RouteEnhancerInterface is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, you should use \Symfony\Cmf\Component\Routing\Enhancer\RouteEnhancerInterface. See https://www.drupal.org/node/2894934', E_USER_DEPRECATED);
+
 /**
  * A route enhance service to determine route enhance rules.
+ *
+ * @deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead,
+ * you should use Symfony\Cmf\Component\Routing\Enhancer\RouteEnhancerInterface.
+ * See https://www.drupal.org/node/2894934
  */
 interface RouteEnhancerInterface extends BaseRouteEnhancerInterface {
 
diff --git a/core/lib/Drupal/Core/Routing/LazyRouteEnhancer.php b/core/lib/Drupal/Core/Routing/LazyRouteEnhancer.php
deleted file mode 100644
index 356fe3e6fa..0000000000
--- a/core/lib/Drupal/Core/Routing/LazyRouteEnhancer.php
+++ /dev/null
@@ -1,101 +0,0 @@
-<?php
-
-namespace Drupal\Core\Routing;
-
-use Drupal\Core\Routing\Enhancer\RouteEnhancerInterface;
-use Symfony\Cmf\Component\Routing\Enhancer\RouteEnhancerInterface as BaseRouteEnhancerInterface;
-use Symfony\Cmf\Component\Routing\RouteObjectInterface;
-use Symfony\Component\DependencyInjection\ContainerAwareInterface;
-use Symfony\Component\DependencyInjection\ContainerAwareTrait;
-use Symfony\Component\HttpFoundation\Request;
-use Symfony\Component\Routing\RouteCollection;
-
-/**
- * A route enhancer which lazily loads route enhancers, depending on the route.
- *
- * We lazy initialize route enhancers, because otherwise all dependencies of
- * all route enhancers are initialized on every request, which is slow. However,
- * with the use of lazy loading, dependencies are instantiated only when used.
- */
-class LazyRouteEnhancer implements BaseRouteEnhancerInterface, ContainerAwareInterface {
-
-  use ContainerAwareTrait;
-
-  /**
-   * Array of enhancers service IDs.
-   *
-   * @var array
-   */
-  protected $serviceIds = [];
-
-  /**
-   * The initialized route enhancers.
-   *
-   * @var \Symfony\Cmf\Component\Routing\Enhancer\RouteEnhancerInterface[]|\Drupal\Core\Routing\Enhancer\RouteEnhancerInterface[]
-   */
-  protected $enhancers = NULL;
-
-  /**
-   * Constructs the LazyRouteEnhancer object.
-   *
-   * @param $service_ids
-   *   Array of enhancers service IDs.
-   */
-  public function __construct($service_ids) {
-    $this->serviceIds = $service_ids;
-  }
-
-  /**
-   * For each route, saves a list of applicable enhancers to the route.
-   *
-   * @param \Symfony\Component\Routing\RouteCollection $route_collection
-   *   A collection of routes to apply enhancer checks to.
-   */
-  public function setEnhancers(RouteCollection $route_collection) {
-    /** @var \Symfony\Component\Routing\Route $route **/
-    foreach ($route_collection as $route_name => $route) {
-      $service_ids = [];
-      foreach ($this->getEnhancers() as $service_id => $enhancer) {
-        if ((!$enhancer instanceof RouteEnhancerInterface) || $enhancer->applies($route)) {
-          $service_ids[] = $service_id;
-        }
-      }
-      if ($service_ids) {
-        $route->setOption('_route_enhancers', array_unique($service_ids));
-      }
-    }
-  }
-
-  /**
-   * For each route, gets a list of applicable enhancer to the route.
-   *
-   * @return \Symfony\Cmf\Component\Routing\Enhancer\RouteEnhancerInterface[]|\Drupal\Core\Routing\Enhancer\RouteEnhancerInterface[]
-   */
-  protected function getEnhancers() {
-    if (!isset($this->enhancers)) {
-      foreach ($this->serviceIds as $service_id) {
-        $this->enhancers[$service_id] = $this->container->get($service_id);
-      }
-    }
-    return $this->enhancers;
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public function enhance(array $defaults, Request $request) {
-    /** @var \Symfony\Component\Routing\Route $route */
-    $route = $defaults[RouteObjectInterface::ROUTE_OBJECT];
-
-    $enhancer_ids = $route->getOption('_route_enhancers');
-
-    if (isset($enhancer_ids)) {
-      foreach ($enhancer_ids as $enhancer_id) {
-        $defaults = $this->container->get($enhancer_id)->enhance($defaults, $request);
-      }
-    }
-
-    return $defaults;
-  }
-
-}
diff --git a/core/lib/Drupal/Core/Routing/LazyRouteFilter.php b/core/lib/Drupal/Core/Routing/LazyRouteFilter.php
deleted file mode 100644
index 10f3d517be..0000000000
--- a/core/lib/Drupal/Core/Routing/LazyRouteFilter.php
+++ /dev/null
@@ -1,102 +0,0 @@
-<?php
-
-namespace Drupal\Core\Routing;
-
-use Symfony\Cmf\Component\Routing\NestedMatcher\RouteFilterInterface as BaseRouteFilterInterface;
-use Symfony\Component\DependencyInjection\ContainerAwareInterface;
-use Symfony\Component\DependencyInjection\ContainerAwareTrait;
-use Symfony\Component\DependencyInjection\ContainerInterface;
-use Symfony\Component\HttpFoundation\Request;
-use Symfony\Component\Routing\RouteCollection;
-
-/**
- * A route filter which lazily loads route filters, depending on the route.
- *
- * We lazy initialize route filters, because otherwise all dependencies of all
- * route filters are initialized on every request, which is slow. However, with
- * the use of lazy loading, dependencies are instantiated only when used.
- */
-class LazyRouteFilter implements BaseRouteFilterInterface, ContainerAwareInterface {
-
-  use ContainerAwareTrait;
-
-  /**
-   * Array of route filter service IDs.
-   *
-   * @var array
-   */
-  protected $serviceIds = [];
-
-  /**
-   * The initialized route filters.
-   *
-   * @var \Drupal\Core\Routing\RouteFilterInterface[]
-   */
-  protected $filters = NULL;
-
-  /**
-   * Constructs the LazyRouteEnhancer object.
-   *
-   * @param $service_ids
-   *   Array of route filter service IDs.
-   */
-  public function __construct($service_ids) {
-    $this->serviceIds = $service_ids;
-  }
-
-  /**
-   * For each route, filter down the route collection.
-   *
-   * @param \Symfony\Component\Routing\RouteCollection $route_collection
-   *   A collection of routes to apply filter checks to.
-   */
-  public function setFilters(RouteCollection $route_collection) {
-    /** @var \Symfony\Component\Routing\Route $route **/
-    foreach ($route_collection as $route) {
-      $service_ids = [];
-      foreach ($this->getFilters() as $service_id => $filter) {
-        if ($filter instanceof RouteFilterInterface && $filter->applies($route)) {
-          $service_ids[] = $service_id;
-        }
-      }
-      if ($service_ids) {
-        $route->setOption('_route_filters', array_unique($service_ids));
-      }
-    }
-  }
-
-  /**
-   * For each route, gets a list of applicable enhancers to the route.
-   *
-   * @return \Symfony\Cmf\Component\Routing\Enhancer\RouteEnhancerInterface[]|\Drupal\Core\Routing\Enhancer\RouteEnhancerInterface[]
-   */
-  protected function getFilters() {
-    if (!isset($this->filters)) {
-      foreach ($this->serviceIds as $service_id) {
-        $this->filters[$service_id] = $this->container->get($service_id);
-      }
-    }
-    return $this->filters;
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public function filter(RouteCollection $collection, Request $request) {
-    $filter_ids = [];
-    foreach ($collection->all() as $route) {
-      $filter_ids = array_merge($filter_ids, $route->getOption('_route_filters') ?: []);
-    }
-    $filter_ids = array_unique($filter_ids);
-
-    if (isset($filter_ids)) {
-      foreach ($filter_ids as $filter_id) {
-        if ($filter = $this->container->get($filter_id, ContainerInterface::NULL_ON_INVALID_REFERENCE)) {
-          $collection = $filter->filter($collection, $request);
-        }
-      }
-    }
-    return $collection;
-  }
-
-}
diff --git a/core/lib/Drupal/Core/Routing/MethodFilter.php b/core/lib/Drupal/Core/Routing/MethodFilter.php
index e565a3e0cf..533a4602b4 100644
--- a/core/lib/Drupal/Core/Routing/MethodFilter.php
+++ b/core/lib/Drupal/Core/Routing/MethodFilter.php
@@ -4,13 +4,13 @@
 
 use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\Routing\Exception\MethodNotAllowedException;
-use Symfony\Component\Routing\Route;
 use Symfony\Component\Routing\RouteCollection;
+use Symfony\Cmf\Component\Routing\NestedMatcher\RouteFilterInterface as BaseRouteFilterInterface;
 
 /**
  * Filters routes based on the HTTP method.
  */
-class MethodFilter implements RouteFilterInterface {
+class MethodFilter implements BaseRouteFilterInterface {
 
   /**
    * {@inheritdoc}
@@ -47,11 +47,4 @@ public function filter(RouteCollection $collection, Request $request) {
     throw new MethodNotAllowedException(array_unique($all_supported_methods));
   }
 
-  /**
-   * {@inheritdoc}
-   */
-  public function applies(Route $route) {
-    return !empty($route->getMethods());
-  }
-
 }
diff --git a/core/lib/Drupal/Core/Routing/RequestFormatRouteFilter.php b/core/lib/Drupal/Core/Routing/RequestFormatRouteFilter.php
index 547e6117e7..d05d96584f 100644
--- a/core/lib/Drupal/Core/Routing/RequestFormatRouteFilter.php
+++ b/core/lib/Drupal/Core/Routing/RequestFormatRouteFilter.php
@@ -4,20 +4,13 @@
 
 use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException;
-use Symfony\Component\Routing\Route;
 use Symfony\Component\Routing\RouteCollection;
+use Symfony\Cmf\Component\Routing\NestedMatcher\RouteFilterInterface as BaseRouteFilterInterface;
 
 /**
  * Provides a route filter, which filters by the request format.
  */
-class RequestFormatRouteFilter implements RouteFilterInterface {
-
-  /**
-   * {@inheritdoc}
-   */
-  public function applies(Route $route) {
-    return $route->hasRequirement('_format');
-  }
+class RequestFormatRouteFilter implements BaseRouteFilterInterface {
 
   /**
    * {@inheritdoc}
@@ -27,22 +20,34 @@ public function filter(RouteCollection $collection, Request $request) {
     $default_format = static::getDefaultFormat($collection);
     $format = $request->getRequestFormat($default_format);
 
+    $routes_with_requirement = [];
+    $routes_without_requirement = [];
+    $result_collection = new RouteCollection();
     /** @var \Symfony\Component\Routing\Route $route */
     foreach ($collection as $name => $route) {
-      // If the route has no _format specification, we move it to the end. If it
-      // does, then no match means the route is removed entirely.
-      if ($supported_formats = array_filter(explode('|', $route->getRequirement('_format')))) {
-        if (!in_array($format, $supported_formats)) {
-          $collection->remove($name);
-        }
+      if (!$route->hasRequirement('_format')) {
+        $routes_without_requirement[$name] = $route;
+        continue;
       }
       else {
-        $collection->add($name, $route);
+        $routes_with_requirement[$name] = $route;
       }
     }
 
-    if (count($collection)) {
-      return $collection;
+    foreach ($routes_with_requirement as $name => $route) {
+      // If the route has no _format specification, we move it to the end. If it
+      // does, then no match means the route is removed entirely.
+      if (($supported_formats = array_filter(explode('|', $route->getRequirement('_format')))) && in_array($format, $supported_formats)) {
+        $result_collection->add($name, $route);
+      }
+    }
+
+    foreach ($routes_without_requirement as $name => $route) {
+      $result_collection->add($name, $route);
+    }
+
+    if (count($result_collection)) {
+      return $result_collection;
     }
 
     // We do not throw a
diff --git a/core/lib/Drupal/Core/Routing/RouteFilterInterface.php b/core/lib/Drupal/Core/Routing/RouteFilterInterface.php
index a3ccb4486f..7473f36dde 100644
--- a/core/lib/Drupal/Core/Routing/RouteFilterInterface.php
+++ b/core/lib/Drupal/Core/Routing/RouteFilterInterface.php
@@ -5,8 +5,14 @@
 use Symfony\Cmf\Component\Routing\NestedMatcher\RouteFilterInterface as BaseRouteFilterInterface;
 use Symfony\Component\Routing\Route;
 
+@trigger_error('\Drupal\Core\Routing\Enhancer\RouteFilterInterface is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, you should use \Symfony\Cmf\Component\Routing\Filter\RouteFilterInterface. See https://www.drupal.org/node/2894934', E_USER_DEPRECATED);
+
 /**
  * A route filter service to filter down the collection of route instances.
+ *
+ * @deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead,
+ * you should use \Symfony\Cmf\Component\Routing\Filter\RouteFilterInterface.
+ * See https://www.drupal.org/node/2894934'
  */
 interface RouteFilterInterface extends BaseRouteFilterInterface {
 
diff --git a/core/lib/Drupal/Core/Routing/Router.php b/core/lib/Drupal/Core/Routing/Router.php
index e949c5efb8..ef7bea019d 100644
--- a/core/lib/Drupal/Core/Routing/Router.php
+++ b/core/lib/Drupal/Core/Routing/Router.php
@@ -3,9 +3,10 @@
 namespace Drupal\Core\Routing;
 
 use Drupal\Core\Path\CurrentPathStack;
-use Symfony\Cmf\Component\Routing\Enhancer\RouteEnhancerInterface as BaseRouteEnhancerInterface;
+use Symfony\Cmf\Component\Routing\Enhancer\RouteEnhancerInterface;
+use \Drupal\Core\Routing\Enhancer\RouteEnhancerInterface as LegacyRouteEnhancerInterface;
 use Symfony\Cmf\Component\Routing\LazyRouteCollection;
-use Symfony\Cmf\Component\Routing\NestedMatcher\RouteFilterInterface as BaseRouteFilterInterface;
+use Symfony\Cmf\Component\Routing\RouteObjectInterface;
 use Symfony\Cmf\Component\Routing\RouteProviderInterface as BaseRouteProviderInterface;
 use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\Routing\Exception\MethodNotAllowedException;
@@ -14,6 +15,7 @@
 use Symfony\Component\Routing\Matcher\RequestMatcherInterface;
 use Symfony\Component\Routing\RouteCollection;
 use Symfony\Component\Routing\RouterInterface;
+use Symfony\Cmf\Component\Routing\NestedMatcher\RouteFilterInterface as BaseRouteFilterInterface;
 
 /**
  * Router implementation in Drupal.
@@ -58,13 +60,6 @@ class Router extends UrlMatcher implements RequestMatcherInterface, RouterInterf
   protected $enhancers = [];
 
   /**
-   * Cached sorted list of enhancers.
-   *
-   * @var \Symfony\Cmf\Component\Routing\Enhancer\RouteEnhancerInterface[]
-   */
-  protected $sortedEnhancers;
-
-  /**
    * The list of available route filters.
    *
    * @var \Symfony\Cmf\Component\Routing\NestedMatcher\RouteFilterInterface[]
@@ -72,13 +67,6 @@ class Router extends UrlMatcher implements RequestMatcherInterface, RouterInterf
   protected $filters = [];
 
   /**
-   * Cached sorted list route filters.
-   *
-   * @var \Symfony\Cmf\Component\Routing\NestedMatcher\RouteFilterInterface[]
-   */
-  protected $sortedFilters;
-
-  /**
    * The URL generator.
    *
    * @var \Symfony\Component\Routing\Generator\UrlGeneratorInterface
@@ -102,36 +90,23 @@ public function __construct(BaseRouteProviderInterface $route_provider, CurrentP
   }
 
   /**
-   * Adds a route enhancer to the list of used route enhancers.
-   *
-   * @param \Symfony\Cmf\Component\Routing\Enhancer\RouteEnhancerInterface $route_enhancer
-   *   A route enhancer.
-   * @param int $priority
-   *   (optional) The priority of the enhancer. Higher number enhancers will be
-   *   used first.
+   * Adds a route filter.
    *
-   * @return $this
+   * @param \Symfony\Cmf\Component\Routing\NestedMatcher\RouteFilterInterface $route_filter
+   *   The route filter.
    */
-  public function addRouteEnhancer(BaseRouteEnhancerInterface $route_enhancer, $priority = 0) {
-    $this->enhancers[$priority][] = $route_enhancer;
-    return $this;
+  public function addRouteFilter(BaseRouteFilterInterface $route_filter) {
+    $this->filters[] = $route_filter;
   }
 
   /**
-   * Adds a route filter to the list of used route filters.
-   *
-   * @param \Symfony\Cmf\Component\Routing\NestedMatcher\RouteFilterInterface $route_filter
-   *   A route filter.
-   * @param int $priority
-   *   (optional) The priority of the filter. Higher number filters will be used
-   *   first.
+   * Adds a route enhancer.
    *
-   * @return $this
+   * @param \Symfony\Cmf\Component\Routing\Enhancer\RouteEnhancerInterface $route_enhancer
+   *   The route enhancer.
    */
-  public function addRouteFilter(BaseRouteFilterInterface $route_filter, $priority = 0) {
-    $this->filters[$priority][] = $route_filter;
-
-    return $this;
+  public function addRouteEnhancer(RouteEnhancerInterface $route_enhancer) {
+    $this->enhancers[] = $route_enhancer;
   }
 
   /**
@@ -148,6 +123,9 @@ public function match($pathinfo) {
    */
   public function matchRequest(Request $request) {
     $collection = $this->getInitialRouteCollection($request);
+    if ($collection->count() === 0) {
+      throw new ResourceNotFoundException(sprintf('No routes found for "%s".', $this->currentPath->getPath()));
+    }
     $collection = $this->applyRouteFilters($collection, $request);
 
     if ($ret = $this->matchCollection(rawurldecode($this->currentPath->getPath($request)), $collection)) {
@@ -276,7 +254,10 @@ protected function getInitialRouteCollection(Request $request) {
    *   from route enhancers.
    */
   protected function applyRouteEnhancers($defaults, Request $request) {
-    foreach ($this->getRouteEnhancers() as $enhancer) {
+    foreach ($this->enhancers as $enhancer) {
+      if ($enhancer instanceof LegacyRouteEnhancerInterface && !$enhancer->applies($defaults[RouteObjectInterface::ROUTE_OBJECT)) {
+        continue;
+      }
       $defaults = $enhancer->enhance($defaults, $request);
     }
 
@@ -284,39 +265,6 @@ protected function applyRouteEnhancers($defaults, Request $request) {
   }
 
   /**
-   * Sorts the enhancers and flattens them.
-   *
-   * @return \Symfony\Cmf\Component\Routing\Enhancer\RouteEnhancerInterface[]
-   *   The enhancers ordered by priority.
-   */
-  public function getRouteEnhancers() {
-    if (!isset($this->sortedEnhancers)) {
-      $this->sortedEnhancers = $this->sortRouteEnhancers();
-    }
-
-    return $this->sortedEnhancers;
-  }
-
-  /**
-   * Sort enhancers by priority.
-   *
-   * The highest priority number is the highest priority (reverse sorting).
-   *
-   * @return \Symfony\Cmf\Component\Routing\Enhancer\RouteEnhancerInterface[]
-   *   The sorted enhancers.
-   */
-  protected function sortRouteEnhancers() {
-    $sortedEnhancers = [];
-    krsort($this->enhancers);
-
-    foreach ($this->enhancers as $enhancers) {
-      $sortedEnhancers = array_merge($sortedEnhancers, $enhancers);
-    }
-
-    return $sortedEnhancers;
-  }
-
-  /**
    * Applies all route filters to a given route collection.
    *
    * This method reduces the sets of routes further down, for example by
@@ -333,7 +281,8 @@ protected function sortRouteEnhancers() {
   protected function applyRouteFilters(RouteCollection $collection, Request $request) {
     // Route filters are expected to throw an exception themselves if they
     // end up filtering the list down to 0.
-    foreach ($this->getRouteFilters() as $filter) {
+    foreach ($this->filters as $filter) {
+      // @todo should we respect ::applies()? The problem is that we can't, because no route has been matched yet. So we should probably remove \Drupal\Core\Routing\RouteFilterInterface?
       $collection = $filter->filter($collection, $request);
     }
 
@@ -341,39 +290,6 @@ protected function applyRouteFilters(RouteCollection $collection, Request $reque
   }
 
   /**
-   * Sorts the filters and flattens them.
-   *
-   * @return \Symfony\Cmf\Component\Routing\NestedMatcher\RouteFilterInterface[]
-   *   The filters ordered by priority
-   */
-  public function getRouteFilters() {
-    if (!isset($this->sortedFilters)) {
-      $this->sortedFilters = $this->sortFilters();
-    }
-
-    return $this->sortedFilters;
-  }
-
-  /**
-   * Sort filters by priority.
-   *
-   * The highest priority number is the highest priority (reverse sorting).
-   *
-   * @return \Symfony\Cmf\Component\Routing\NestedMatcher\RouteFilterInterface[]
-   *   The sorted filters.
-   */
-  protected function sortFilters() {
-    $sortedFilters = [];
-    krsort($this->filters);
-
-    foreach ($this->filters as $filters) {
-      $sortedFilters = array_merge($sortedFilters, $filters);
-    }
-
-    return $sortedFilters;
-  }
-
-  /**
    * {@inheritdoc}
    */
   public function getRouteCollection() {
diff --git a/core/modules/field_ui/src/Routing/FieldUiRouteEnhancer.php b/core/modules/field_ui/src/Routing/FieldUiRouteEnhancer.php
index b8307e5c98..eef2caf9c2 100644
--- a/core/modules/field_ui/src/Routing/FieldUiRouteEnhancer.php
+++ b/core/modules/field_ui/src/Routing/FieldUiRouteEnhancer.php
@@ -3,9 +3,9 @@
 namespace Drupal\field_ui\Routing;
 
 use Drupal\Core\Entity\EntityManagerInterface;
-use Drupal\Core\Routing\Enhancer\RouteEnhancerInterface;
+use Symfony\Cmf\Component\Routing\Enhancer\RouteEnhancerInterface;
+use Symfony\Cmf\Component\Routing\RouteObjectInterface;
 use Symfony\Component\HttpFoundation\Request;
-use Symfony\Component\Routing\Route;
 
 /**
  * Enhances Field UI routes by adding proper information about the bundle name.
@@ -33,6 +33,10 @@ public function __construct(EntityManagerInterface $entity_manager) {
    * {@inheritdoc}
    */
   public function enhance(array $defaults, Request $request) {
+    if (!$defaults[RouteObjectInterface::ROUTE_OBJECT]->hasOption('_field_ui')) {
+      return $defaults;
+    }
+
     if (($bundle = $this->entityManager->getDefinition($defaults['entity_type_id'])->getBundleEntityType()) && isset($defaults[$bundle])) {
       // Field UI forms only need the actual name of the bundle they're dealing
       // with, not an upcasted entity object, so provide a simple way for them
@@ -43,11 +47,4 @@ public function enhance(array $defaults, Request $request) {
     return $defaults;
   }
 
-  /**
-   * {@inheritdoc}
-   */
-  public function applies(Route $route) {
-    return ($route->hasOption('_field_ui'));
-  }
-
 }
diff --git a/core/modules/system/tests/modules/accept_header_routing_test/src/Routing/AcceptHeaderMatcher.php b/core/modules/system/tests/modules/accept_header_routing_test/src/Routing/AcceptHeaderMatcher.php
index 1a3c61eafb..9ab0b93bd4 100644
--- a/core/modules/system/tests/modules/accept_header_routing_test/src/Routing/AcceptHeaderMatcher.php
+++ b/core/modules/system/tests/modules/accept_header_routing_test/src/Routing/AcceptHeaderMatcher.php
@@ -2,10 +2,9 @@
 
 namespace Drupal\accept_header_routing_test\Routing;
 
-use Drupal\Core\Routing\RouteFilterInterface;
+use Symfony\Cmf\Component\Routing\NestedMatcher\RouteFilterInterface;
 use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException;
-use Symfony\Component\Routing\Route;
 use Symfony\Component\Routing\RouteCollection;
 
 /**
@@ -59,11 +58,4 @@ public function filter(RouteCollection $collection, Request $request) {
     throw new NotAcceptableHttpException('No route found for the specified formats ' . implode(' ', $acceptable_mime_types));
   }
 
-  /**
-   * {@inheritdoc}
-   */
-  public function applies(Route $route) {
-    return TRUE;
-  }
-
 }
diff --git a/core/tests/Drupal/Tests/Core/Enhancer/EntityRevisionRouteEnhancerTest.php b/core/tests/Drupal/Tests/Core/Enhancer/EntityRevisionRouteEnhancerTest.php
index aa0897b22c..4d1883a447 100644
--- a/core/tests/Drupal/Tests/Core/Enhancer/EntityRevisionRouteEnhancerTest.php
+++ b/core/tests/Drupal/Tests/Core/Enhancer/EntityRevisionRouteEnhancerTest.php
@@ -30,20 +30,16 @@ protected function setUp() {
   }
 
   /**
-   * @covers ::applies
-   * @dataProvider providerTestApplies
+   * @covers ::enhance
    */
-  public function testApplies(Route $route, $expected) {
-    $this->assertEquals($expected, $this->routeEnhancer->applies($route));
-  }
+  public function testEnhanceWithoutParameter() {
+    $route = new Route('/test-path/{entity_test}');
 
-  public function providerTestApplies() {
-    $data = [];
-    $data['no-parameter'] = [new Route('/test-path'), FALSE];
-    $data['none-revision-parameters'] = [new Route('/test-path/{entity_test}', [], [], ['parameters' => ['entity_test' => ['type' => 'entity:entity_test']]]), FALSE];
-    $data['with-revision-parameter'] = [new Route('/test-path/{entity_test_revision}', [], [], ['parameters' => ['entity_test_revision' => ['type' => 'entity_revision:entity_test']]]), TRUE];
+    $request = Request::create('/test-path');
 
-    return $data;
+    $defaults = [];
+    $defaults[RouteObjectInterface::ROUTE_OBJECT] = $route;
+    $this->assertEquals($defaults, $this->routeEnhancer->enhance($defaults, $request));
   }
 
   /**
diff --git a/core/tests/Drupal/Tests/Core/Entity/Enhancer/EntityRouteEnhancerTest.php b/core/tests/Drupal/Tests/Core/Entity/Enhancer/EntityRouteEnhancerTest.php
index 1b6525a93b..5ea28c9d86 100644
--- a/core/tests/Drupal/Tests/Core/Entity/Enhancer/EntityRouteEnhancerTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/Enhancer/EntityRouteEnhancerTest.php
@@ -6,6 +6,7 @@
 use Drupal\Tests\UnitTestCase;
 use Symfony\Cmf\Component\Routing\RouteObjectInterface;
 use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\Routing\Route;
 
 /**
  * @coversDefaultClass \Drupal\Core\Entity\Enhancer\EntityRouteEnhancer
@@ -26,6 +27,7 @@ public function testEnhancer() {
     $defaults = [];
     $defaults['_controller'] = 'Drupal\Tests\Core\Controller\TestController::content';
     $defaults['_entity_form'] = 'entity_test.default';
+    $defaults['_route_object'] = (new Route('/test', $defaults));
     $new_defaults = $route_enhancer->enhance($defaults, $request);
     $this->assertTrue(is_callable($new_defaults['_controller']));
     $this->assertEquals($defaults['_controller'], $new_defaults['_controller'], '_controller did not get overridden.');
@@ -33,12 +35,14 @@ public function testEnhancer() {
     // Set _entity_form and ensure that the form is set.
     $defaults = [];
     $defaults['_entity_form'] = 'entity_test.default';
+    $defaults['_route_object'] = (new Route('/test', $defaults));
     $new_defaults = $route_enhancer->enhance($defaults, $request);
     $this->assertEquals('controller.entity_form:getContentResult', $new_defaults['_controller']);
 
     // Set _entity_list and ensure that the entity list controller is set.
     $defaults = [];
     $defaults['_entity_list'] = 'entity_test.default';
+    $defaults['_route_object'] = (new Route('/test', $defaults));
     $new_defaults = $route_enhancer->enhance($defaults, $request);
     $this->assertEquals('\Drupal\Core\Entity\Controller\EntityListController::listing', $new_defaults['_controller'], 'The entity list controller was not set.');
     $this->assertEquals('entity_test.default', $new_defaults['entity_type']);
@@ -48,6 +52,7 @@ public function testEnhancer() {
     $defaults = [];
     $defaults['_entity_view'] = 'entity_test.full';
     $defaults['entity_test'] = 'Mock entity';
+    $defaults['_route_object'] = (new Route('/test', $defaults));
     $defaults = $route_enhancer->enhance($defaults, $request);
     $this->assertEquals('\Drupal\Core\Entity\Controller\EntityViewController::view', $defaults['_controller'], 'The entity view controller was not set.');
     $this->assertEquals($defaults['_entity'], 'Mock entity');
@@ -62,13 +67,9 @@ public function testEnhancer() {
     // Add a converter.
     $options['parameters']['foo'] = ['type' => 'entity:entity_test'];
     // Set the route.
-    $route = $this->getMockBuilder('Symfony\Component\Routing\Route')
-      ->disableOriginalConstructor()
-      ->getMock();
-
-    $route->expects($this->any())
-      ->method('getOptions')
-      ->will($this->returnValue($options));
+    $route = new Route('/test');
+    $route->setOptions($options);
+    $route->setDefaults($defaults);
 
     $defaults[RouteObjectInterface::ROUTE_OBJECT] = $route;
     $defaults = $route_enhancer->enhance($defaults, $request);
@@ -81,6 +82,7 @@ public function testEnhancer() {
     $defaults = [];
     $defaults['_entity_view'] = 'entity_test';
     $defaults['entity_test'] = 'Mock entity';
+    $defaults['_route_object'] = (new Route('/test', $defaults));
     $defaults = $route_enhancer->enhance($defaults, $request);
     $this->assertEquals('\Drupal\Core\Entity\Controller\EntityViewController::view', $defaults['_controller'], 'The entity view controller was not set.');
     $this->assertEquals($defaults['_entity'], 'Mock entity');
diff --git a/core/tests/Drupal/Tests/Core/Routing/MethodFilterTest.php b/core/tests/Drupal/Tests/Core/Routing/MethodFilterTest.php
index 8a7554dec9..2e411b2b85 100644
--- a/core/tests/Drupal/Tests/Core/Routing/MethodFilterTest.php
+++ b/core/tests/Drupal/Tests/Core/Routing/MethodFilterTest.php
@@ -16,34 +16,6 @@
 class MethodFilterTest extends UnitTestCase {
 
   /**
-   * @covers ::applies
-   * @dataProvider providerApplies
-   */
-  public function testApplies(array $route_methods, $expected_applies) {
-    $route = new Route('/test', [], [], [], '', [], $route_methods);
-    $method_filter = new MethodFilter();
-
-    $this->assertSame($expected_applies, $method_filter->applies($route));
-  }
-
-  /**
-   * Data provider for testApplies().
-   *
-   * @return array
-   */
-  public function providerApplies() {
-    return [
-      'only GET' => [['GET'], TRUE],
-      'only PATCH' => [['PATCH'], TRUE],
-      'only POST' => [['POST'], TRUE],
-      'only DELETE' => [['DELETE'], TRUE],
-      'only HEAD' => [['HEAD'], TRUE],
-      'all' => [['GET', 'PATCH', 'POST', 'DELETE', 'HEAD'], TRUE],
-      'none' => [[], FALSE],
-    ];
-  }
-
-  /**
    * @covers ::filter
    */
   public function testWithAllowedMethod() {
@@ -125,4 +97,22 @@ public function testFilteredMethods() {
     $this->assertEquals($expected_collection, $result_collection);
   }
 
+  /**
+   * Ensures that the incoming and outgoing collections have the same order.
+   *
+   * @covers ::filter
+   */
+  public function testCollectionOrder() {
+    $request = Request::create('/test', 'GET');
+
+    $collection = new RouteCollection();
+    $collection->add('entity.taxonomy_term.canonical', new Route('/test'));
+    $collection->add('views.view.taxonomy_term_page', new Route('/test', [], [], [], '', [], ['GET', 'POST']));
+
+    $method_filter = new MethodFilter();
+    $result_collection = $method_filter->filter($collection, $request);
+
+    $this->assertEquals(['entity.taxonomy_term.canonical', 'views.view.taxonomy_term_page'], array_keys($result_collection->all()));
+  }
+
 }
diff --git a/core/tests/Drupal/Tests/Core/Routing/RequestFormatRouteFilterTest.php b/core/tests/Drupal/Tests/Core/Routing/RequestFormatRouteFilterTest.php
index 4a9e0c6b57..3574ee1950 100644
--- a/core/tests/Drupal/Tests/Core/Routing/RequestFormatRouteFilterTest.php
+++ b/core/tests/Drupal/Tests/Core/Routing/RequestFormatRouteFilterTest.php
@@ -16,25 +16,6 @@
 class RequestFormatRouteFilterTest extends UnitTestCase {
 
   /**
-   * @covers ::applies
-   */
-  public function testAppliesWithoutFormat() {
-    $route_filter = new RequestFormatRouteFilter();
-    $route = new Route('/test');
-    $this->assertFalse($route_filter->applies($route));
-  }
-
-  /**
-   * @covers ::applies
-   */
-  public function testAppliesWithFormat() {
-    $route_filter = new RequestFormatRouteFilter();
-    $route = new Route('/test');
-    $route->setRequirement('_format', 'json');
-    $this->assertTrue($route_filter->applies($route));
-  }
-
-  /**
    * @covers ::filter
    * @dataProvider filterProvider
    */
@@ -65,6 +46,7 @@ public function filterProvider() {
     $sole_route_match_single_format->add('sole_route_single_format', $route_with_format);
 
     return [
+      'nothing requested' => [clone $collection, '', ['test_0']],
       'xml requested' => [clone $collection, 'xml', ['test_2', 'test_0']],
       'json requested' => [clone $collection, 'json', ['test_1', 'test_2', 'test_0']],
       'html format requested' => [clone $collection, 'html', ['test_0']],
