diff --git a/core/authorize.php b/core/authorize.php index e0b7c4f192..9ffe8e2b7d 100644 --- a/core/authorize.php +++ b/core/authorize.php @@ -27,7 +27,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Drupal\Core\Site\Settings; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\Routing\Route; // Change the directory to the Drupal root. diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index b6bc1e1c0b..d610fdd25c 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -32,7 +32,7 @@ use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\Url; use Drupal\language\Entity\ConfigurableLanguage; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; diff --git a/core/lib/Drupal/Core/Access/AccessManager.php b/core/lib/Drupal/Core/Access/AccessManager.php index d2b7e55f99..36dec5b65c 100644 --- a/core/lib/Drupal/Core/Access/AccessManager.php +++ b/core/lib/Drupal/Core/Access/AccessManager.php @@ -11,7 +11,7 @@ use Drupal\Component\Utility\ArgumentsResolverInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Exception\RouteNotFoundException; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; /** * Attaches access check services to routes and runs them on request. diff --git a/core/lib/Drupal/Core/Entity/Enhancer/EntityRouteEnhancer.php b/core/lib/Drupal/Core/Entity/Enhancer/EntityRouteEnhancer.php index f383fbc986..aa0b41a2fa 100644 --- a/core/lib/Drupal/Core/Entity/Enhancer/EntityRouteEnhancer.php +++ b/core/lib/Drupal/Core/Entity/Enhancer/EntityRouteEnhancer.php @@ -4,7 +4,7 @@ use Drupal\Core\Routing\EnhancerInterface; use Symfony\Component\HttpFoundation\Request; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\Routing\Route; /** diff --git a/core/lib/Drupal/Core/EventSubscriber/OptionsRequestSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/OptionsRequestSubscriber.php index 9520283a98..18982a6d6e 100644 --- a/core/lib/Drupal/Core/EventSubscriber/OptionsRequestSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/OptionsRequestSubscriber.php @@ -2,7 +2,7 @@ namespace Drupal\Core\EventSubscriber; -use Symfony\Cmf\Component\Routing\RouteProviderInterface; +use Drupal\Core\Routing\RouteProviderInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Event\RequestEvent; @@ -20,14 +20,14 @@ class OptionsRequestSubscriber implements EventSubscriberInterface { /** * The route provider. * - * @var \Symfony\Cmf\Component\Routing\RouteProviderInterface + * @var \Drupal\Core\Routing\RouteProviderInterface */ protected $routeProvider; /** * Creates a new OptionsRequestSubscriber instance. * - * @param \Symfony\Cmf\Component\Routing\RouteProviderInterface $route_provider + * @param \Drupal\Core\Routing\RouteProviderInterface $route_provider * The route provider. */ public function __construct(RouteProviderInterface $route_provider) { diff --git a/core/lib/Drupal/Core/EventSubscriber/SpecialAttributesRouteSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/SpecialAttributesRouteSubscriber.php index 0f40c5a58e..67b2fba2b6 100644 --- a/core/lib/Drupal/Core/EventSubscriber/SpecialAttributesRouteSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/SpecialAttributesRouteSubscriber.php @@ -4,7 +4,7 @@ use Drupal\Core\Routing\RouteBuildEvent; use Drupal\Core\Routing\RouteSubscriberBase; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\Routing\RouteCollection; /** diff --git a/core/lib/Drupal/Core/ParamConverter/ParamConverterManager.php b/core/lib/Drupal/Core/ParamConverter/ParamConverterManager.php index 944bd5304c..c3ca6ba879 100644 --- a/core/lib/Drupal/Core/ParamConverter/ParamConverterManager.php +++ b/core/lib/Drupal/Core/ParamConverter/ParamConverterManager.php @@ -2,7 +2,7 @@ namespace Drupal\Core\ParamConverter; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\Routing\RouteCollection; /** diff --git a/core/lib/Drupal/Core/Path/PathValidator.php b/core/lib/Drupal/Core/Path/PathValidator.php index efce47305a..58976df177 100644 --- a/core/lib/Drupal/Core/Path/PathValidator.php +++ b/core/lib/Drupal/Core/Path/PathValidator.php @@ -9,7 +9,7 @@ use Drupal\Core\Routing\RequestContext; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Url; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\Routing\Exception\MethodNotAllowedException; diff --git a/core/lib/Drupal/Core/Routing/Enhancer/EntityRevisionRouteEnhancer.php b/core/lib/Drupal/Core/Routing/Enhancer/EntityRevisionRouteEnhancer.php index d54338f449..bdd52cbdd3 100644 --- a/core/lib/Drupal/Core/Routing/Enhancer/EntityRevisionRouteEnhancer.php +++ b/core/lib/Drupal/Core/Routing/Enhancer/EntityRevisionRouteEnhancer.php @@ -3,7 +3,7 @@ namespace Drupal\Core\Routing\Enhancer; use Drupal\Core\Routing\EnhancerInterface; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Route; diff --git a/core/lib/Drupal/Core/Routing/Enhancer/FormRouteEnhancer.php b/core/lib/Drupal/Core/Routing/Enhancer/FormRouteEnhancer.php index c812178d29..9e9df9f71d 100644 --- a/core/lib/Drupal/Core/Routing/Enhancer/FormRouteEnhancer.php +++ b/core/lib/Drupal/Core/Routing/Enhancer/FormRouteEnhancer.php @@ -3,7 +3,7 @@ namespace Drupal\Core\Routing\Enhancer; use Drupal\Core\Routing\EnhancerInterface; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Route; diff --git a/core/lib/Drupal/Core/Routing/Enhancer/ParamConversionEnhancer.php b/core/lib/Drupal/Core/Routing/Enhancer/ParamConversionEnhancer.php index aa2b8c830c..507366bc7c 100644 --- a/core/lib/Drupal/Core/Routing/Enhancer/ParamConversionEnhancer.php +++ b/core/lib/Drupal/Core/Routing/Enhancer/ParamConversionEnhancer.php @@ -5,7 +5,7 @@ use Drupal\Core\ParamConverter\ParamConverterManagerInterface; use Drupal\Core\ParamConverter\ParamNotConvertedException; use Drupal\Core\Routing\EnhancerInterface; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; diff --git a/core/lib/Drupal/Core/Routing/EnhancerInterface.php b/core/lib/Drupal/Core/Routing/EnhancerInterface.php index 3ddee66752..3439a4a172 100644 --- a/core/lib/Drupal/Core/Routing/EnhancerInterface.php +++ b/core/lib/Drupal/Core/Routing/EnhancerInterface.php @@ -2,11 +2,25 @@ namespace Drupal\Core\Routing; -use Symfony\Cmf\Component\Routing\Enhancer\RouteEnhancerInterface; +use Symfony\Component\HttpFoundation\Request; /** * A route enhance service to determine route enhance rules. */ -interface EnhancerInterface extends RouteEnhancerInterface { +interface EnhancerInterface { + + /** + * Updates the defaults for a route definition based on the request. + * + * @param array $defaults + * The defaults, maps to '_defaults' in the route definition YAML. + * @param \Symfony\Component\HttpFoundation\Request $request + * The Request instance. + * + * @return array + * The modified defaults. Each enhancer MUST return the + * $defaults but may add or remove values. + */ + public function enhance(array $defaults, Request $request); } diff --git a/core/lib/Drupal/Core/Routing/FilterInterface.php b/core/lib/Drupal/Core/Routing/FilterInterface.php index 73c9f83a26..ad446a6994 100644 --- a/core/lib/Drupal/Core/Routing/FilterInterface.php +++ b/core/lib/Drupal/Core/Routing/FilterInterface.php @@ -2,11 +2,31 @@ namespace Drupal\Core\Routing; -use Symfony\Cmf\Component\Routing\NestedMatcher\RouteFilterInterface; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\Routing\RouteCollection; /** * A route filter service to filter down the collection of route instances. */ -interface FilterInterface extends RouteFilterInterface { +interface FilterInterface { + + /** + * Filters the route collection against a request and returns all matching + * routes. + * + * @param \Symfony\Component\Routing\RouteCollection $collection + * The collection against which to match. + * @param \Symfony\Component\HttpFoundation\Request $request + * A Request object against which to match. + * + * @return \Symfony\Component\Routing\RouteCollection + * A non-empty RouteCollection of matched routes + * + * @throws ResourceNotFoundException + * If none of the routes in $collection matches $request. This is a + * performance optimization to not continue the match process when a match + * will no longer be possible. + */ + public function filter(RouteCollection $collection, Request $request); } diff --git a/core/lib/Drupal/Core/Routing/LazyRouteCollection.php b/core/lib/Drupal/Core/Routing/LazyRouteCollection.php new file mode 100644 index 0000000000..5f9706efe7 --- /dev/null +++ b/core/lib/Drupal/Core/Routing/LazyRouteCollection.php @@ -0,0 +1,68 @@ +provider = $provider; + } + + /** + * {@inheritdoc} + */ + public function getIterator() { + return new \ArrayIterator($this->all()); + } + + /** + * Gets the number of Routes in this collection. + * + * @return int + * The number of routes + */ + public function count() { + return count($this->all()); + } + + /** + * Returns all routes in this collection. + * + * @return \Symfony\Component\Routing\Route[] + * An array of routes + */ + public function all() { + return $this->provider->getRoutesByNames(NULL); + } + + /** + * Gets a route by name. + * + * @param string $name + * The route name + * + * @return \Symfony\Component\Routing\Route|null + * A Route instance or null when not found + */ + public function get($name) { + try { + return $this->provider->getRouteByName($name); + } + catch (RouteNotFoundException $e) { + return; + } + } + +} diff --git a/core/lib/Drupal/Core/Routing/RouteMatch.php b/core/lib/Drupal/Core/Routing/RouteMatch.php index 10c444758f..e00be3554f 100644 --- a/core/lib/Drupal/Core/Routing/RouteMatch.php +++ b/core/lib/Drupal/Core/Routing/RouteMatch.php @@ -2,7 +2,6 @@ namespace Drupal\Core\Routing; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Route; diff --git a/core/lib/Drupal/Core/Routing/RouteObjectInterface.php b/core/lib/Drupal/Core/Routing/RouteObjectInterface.php new file mode 100644 index 0000000000..e7afacd624 --- /dev/null +++ b/core/lib/Drupal/Core/Routing/RouteObjectInterface.php @@ -0,0 +1,29 @@ +connection->select($this->tableName, 'router') + ->fields('router', ['name', 'route']); + $routes = $select->execute()->fetchAllKeyed(); + + $result = []; + foreach ($routes as $name => $route) { + $result[$name] = unserialize($route); + } + + return $result; } /** @@ -422,9 +429,25 @@ public static function getSubscribedEvents() { } /** - * {@inheritdoc} + * Returns a chunk of routes. + * + * Should only be used in conjunction with an iterator. + * + * @param int $offset + * The query offset. + * @param int $length + * The number of records. + * + * @return \Symfony\Component\Routing\Route[] + * Routes keyed by the route name. + * + * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. No direct + * replacement is provided. + * + * @see https://www.drupal.org/node/3151009 */ public function getRoutesPaged($offset, $length = NULL) { + @trigger_error(__METHOD__ . '() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. No direct replacement is provided. See https://www.drupal.org/node/3151009', E_USER_DEPRECATED); $select = $this->connection->select($this->tableName, 'router') ->fields('router', ['name', 'route']); @@ -443,9 +466,18 @@ public function getRoutesPaged($offset, $length = NULL) { } /** - * {@inheritdoc} + * Gets the total count of routes provided by the router. + * + * @return int + * Number of routes. + * + * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. No direct + * replacement is provided. + * + * @see https://www.drupal.org/node/3151009 */ public function getRoutesCount() { + @trigger_error(__METHOD__ . '() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. No direct replacement is provided. See https://www.drupal.org/node/3151009', E_USER_DEPRECATED); return $this->connection->query("SELECT COUNT(*) FROM {" . $this->connection->escapeTable($this->tableName) . "}")->fetchField(); } diff --git a/core/lib/Drupal/Core/Routing/RouteProviderInterface.php b/core/lib/Drupal/Core/Routing/RouteProviderInterface.php index f53593a82e..2517559f9f 100644 --- a/core/lib/Drupal/Core/Routing/RouteProviderInterface.php +++ b/core/lib/Drupal/Core/Routing/RouteProviderInterface.php @@ -2,14 +2,79 @@ namespace Drupal\Core\Routing; -use Symfony\Cmf\Component\Routing\RouteProviderInterface as RouteProviderBaseInterface; +use Symfony\Component\HttpFoundation\Request; /** * Extends the router provider interface * * @see \Symfony\Cmf\Component\Routing */ -interface RouteProviderInterface extends RouteProviderBaseInterface { +interface RouteProviderInterface { + + /** + * Finds routes that may potentially match the request. + * + * This may return a mixed list of class instances, but all routes returned + * must extend the core Symfony route. The classes may also implement + * RouteObjectInterface to link to a content document. + * + * This method may not throw an exception based on implementation specific + * restrictions on the url. That case is considered a not found - returning + * an empty array. Exceptions are only used to abort the whole request in + * case something is seriously broken, like the storage backend being down. + * + * Note that implementations may not implement an optimal matching + * algorithm, simply a reasonable first pass. That allows for potentially + * very large route sets to be filtered down to likely candidates, which + * may then be filtered in memory more completely. + * + * @param \Symfony\Component\HttpFoundation\Request $request + * A request against which to match + * + * @return \Symfony\Component\Routing\RouteCollection + * All Routes that could potentially match $request. + * Empty collection if nothing can match + */ + public function getRouteCollectionForRequest(Request $request); + + /** + * Find the route using the provided route name. + * + * @param string $name + * The route name to fetch + * + * @return \Symfony\Component\Routing\Route + * The Symfony route object. + * + * @throws \Symfony\Component\Routing\Exception\RouteNotFoundException + * If a matching route cannot be found. + */ + public function getRouteByName($name); + + /** + * Find many routes by their names using the provided list of names. + * + * Note that this method may not throw an exception if some of the routes + * are not found or are not actually Route instances. It will just return the + * list of those Route instances it found. + * + * This method exists in order to allow performance optimizations. The + * simple implementation could be to just repeatedly call + * $this->getRouteByName() while catching and ignoring eventual exceptions. + * + * If $names is null, this method SHOULD return a collection of all routes + * known to this provider. If there are many routes to be expected, usage of + * a lazy loading collection is recommended. A provider MAY only return a + * subset of routes to e.g. support paging or other concepts. + * + * @param array|null $names + * The list of names to retrieve, In case of null, the provider will + * determine what routes to return + * + * @return \Symfony\Component\Routing\Route[] + * Iterable list with the keys being the names from the $names array + */ + public function getRoutesByNames($names); /** * Get all routes which match a certain pattern. diff --git a/core/lib/Drupal/Core/Routing/RouteProviderLazyBuilder.php b/core/lib/Drupal/Core/Routing/RouteProviderLazyBuilder.php index a2cb8c5785..d5a55a9a3a 100644 --- a/core/lib/Drupal/Core/Routing/RouteProviderLazyBuilder.php +++ b/core/lib/Drupal/Core/Routing/RouteProviderLazyBuilder.php @@ -2,14 +2,13 @@ namespace Drupal\Core\Routing; -use Symfony\Cmf\Component\Routing\PagedRouteProviderInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\Request; /** * A Route Provider front-end for all Drupal-stored routes. */ -class RouteProviderLazyBuilder implements PreloadableRouteProviderInterface, PagedRouteProviderInterface, EventSubscriberInterface { +class RouteProviderLazyBuilder implements PreloadableRouteProviderInterface, EventSubscriberInterface { /** * The route provider service. @@ -122,16 +121,41 @@ public function reset() { } /** - * {@inheritdoc} + * Returns a chunk of routes. + * + * Should only be used in conjunction with an iterator. + * + * @param int $offset + * The query offset. + * @param int $length + * The number of records. + * + * @return \Symfony\Component\Routing\Route[] + * Routes keyed by the route name. + * + * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. No direct + * replacement is provided. + * + * @see https://www.drupal.org/node/3151009 */ public function getRoutesPaged($offset, $length = NULL) { + @trigger_error(__METHOD__ . '() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. No direct replacement is provided. See https://www.drupal.org/node/3151009', E_USER_DEPRECATED); return $this->getRouteProvider()->getRoutesPaged($offset, $length); } /** - * {@inheritdoc} + * Gets the total count of routes provided by the router. + * + * @return int + * Number of routes. + * + * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. No direct + * replacement is provided. + * + * @see https://www.drupal.org/node/3151009 */ public function getRoutesCount() { + @trigger_error(__METHOD__ . '() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. No direct replacement is provided. See https://www.drupal.org/node/3151009', E_USER_DEPRECATED); return $this->getRouteProvider()->getRoutesCount(); } diff --git a/core/lib/Drupal/Core/Routing/Router.php b/core/lib/Drupal/Core/Routing/Router.php index d1586e42b1..8b649a3ec2 100644 --- a/core/lib/Drupal/Core/Routing/Router.php +++ b/core/lib/Drupal/Core/Routing/Router.php @@ -3,8 +3,6 @@ namespace Drupal\Core\Routing; use Drupal\Core\Path\CurrentPathStack; -use Symfony\Cmf\Component\Routing\LazyRouteCollection; -use Symfony\Cmf\Component\Routing\RouteProviderInterface as BaseRouteProviderInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Exception\MethodNotAllowedException; use Symfony\Component\Routing\Exception\ResourceNotFoundException; @@ -29,22 +27,13 @@ * regex. See ::matchCollection(). * 4. Enhance the list of route attributes, for example loading entity objects. * See ::applyRouteEnhancers(). - * - * This implementation uses ideas of the following routers: - * - \Symfony\Cmf\Component\Routing\DynamicRouter - * - \Drupal\Core\Routing\UrlMatcher - * - \Symfony\Cmf\Component\Routing\NestedMatcher\NestedMatcher - * - * @see \Symfony\Cmf\Component\Routing\DynamicRouter - * @see \Drupal\Core\Routing\UrlMatcher - * @see \Symfony\Cmf\Component\Routing\NestedMatcher\NestedMatcher */ class Router extends UrlMatcher implements RequestMatcherInterface, RouterInterface { /** * The route provider responsible for the first-pass match. * - * @var \Symfony\Cmf\Component\Routing\RouteProviderInterface + * @var \Drupal\Core\Routing\RouteProviderInterface */ protected $routeProvider; @@ -72,14 +61,14 @@ class Router extends UrlMatcher implements RequestMatcherInterface, RouterInterf /** * Constructs a new Router. * - * @param \Symfony\Cmf\Component\Routing\RouteProviderInterface $route_provider + * @param \Drupal\Core\Routing\RouteProviderInterface $route_provider * 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(BaseRouteProviderInterface $route_provider, CurrentPathStack $current_path, BaseUrlGeneratorInterface $url_generator) { + public function __construct(RouteProviderInterface $route_provider, CurrentPathStack $current_path, BaseUrlGeneratorInterface $url_generator) { parent::__construct($current_path); $this->routeProvider = $route_provider; $this->urlGenerator = $url_generator; diff --git a/core/lib/Drupal/Core/Routing/UrlGeneratorInterface.php b/core/lib/Drupal/Core/Routing/UrlGeneratorInterface.php index e63383df5f..bbc91de1d1 100644 --- a/core/lib/Drupal/Core/Routing/UrlGeneratorInterface.php +++ b/core/lib/Drupal/Core/Routing/UrlGeneratorInterface.php @@ -2,14 +2,14 @@ namespace Drupal\Core\Routing; -use Symfony\Cmf\Component\Routing\VersatileGeneratorInterface; +use Symfony\Component\Routing\Generator\UrlGeneratorInterface as SymfonyUrlGeneratorInterface; /** * Defines an interface for generating a url from a route or system path. * * Provides additional methods and options not present in the base interface. */ -interface UrlGeneratorInterface extends VersatileGeneratorInterface { +interface UrlGeneratorInterface extends SymfonyUrlGeneratorInterface { /** * Gets the internal path (system path) for a route. diff --git a/core/lib/Drupal/Core/Routing/UrlMatcher.php b/core/lib/Drupal/Core/Routing/UrlMatcher.php index 9056903368..bc9a63f5f6 100644 --- a/core/lib/Drupal/Core/Routing/UrlMatcher.php +++ b/core/lib/Drupal/Core/Routing/UrlMatcher.php @@ -4,8 +4,9 @@ use Drupal\Core\Path\CurrentPathStack; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; -use Symfony\Cmf\Component\Routing\NestedMatcher\UrlMatcher as BaseUrlMatcher; +use Symfony\Component\Routing\Matcher\UrlMatcher as BaseUrlMatcher; /** * Drupal-specific URL Matcher; handles the Drupal "system path" mapping. @@ -41,4 +42,17 @@ public function finalMatch(RouteCollection $collection, Request $request) { return $this->match($this->currentPath->getPath($request)); } + /** + * {@inheritdoc} + */ + protected function getAttributes(Route $route, $name, array $attributes) { + 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()); + } + } diff --git a/core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php b/core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php index a10af1e48c..5047975076 100644 --- a/core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php +++ b/core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php @@ -21,7 +21,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Yaml\Yaml as SymfonyYaml; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\Routing\Route; /** diff --git a/core/lib/Drupal/Core/Update/UpdateKernel.php b/core/lib/Drupal/Core/Update/UpdateKernel.php index 2b74dabb67..edcee19960 100644 --- a/core/lib/Drupal/Core/Update/UpdateKernel.php +++ b/core/lib/Drupal/Core/Update/UpdateKernel.php @@ -6,7 +6,7 @@ use Drupal\Core\Session\AnonymousUserSession; use Drupal\Core\Site\Settings; use Drupal\Core\StackMiddleware\ReverseProxyMiddleware; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; diff --git a/core/lib/Drupal/Core/Url.php b/core/lib/Drupal/Core/Url.php index 82c2c600b3..09b988f413 100644 --- a/core/lib/Drupal/Core/Url.php +++ b/core/lib/Drupal/Core/Url.php @@ -10,7 +10,7 @@ use Drupal\Core\Routing\UrlGeneratorInterface; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Utility\UnroutedUrlAssemblerInterface; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\Request; /** diff --git a/core/modules/field_ui/src/Routing/FieldUiRouteEnhancer.php b/core/modules/field_ui/src/Routing/FieldUiRouteEnhancer.php index c7e51950e8..dac2ca0d47 100644 --- a/core/modules/field_ui/src/Routing/FieldUiRouteEnhancer.php +++ b/core/modules/field_ui/src/Routing/FieldUiRouteEnhancer.php @@ -3,7 +3,7 @@ namespace Drupal\field_ui\Routing; use Drupal\Core\Routing\EnhancerInterface; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Route; diff --git a/core/modules/jsonapi/src/ParamConverter/EntityUuidConverter.php b/core/modules/jsonapi/src/ParamConverter/EntityUuidConverter.php index abc10cff4f..1b4ef83e43 100644 --- a/core/modules/jsonapi/src/ParamConverter/EntityUuidConverter.php +++ b/core/modules/jsonapi/src/ParamConverter/EntityUuidConverter.php @@ -7,7 +7,7 @@ use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\ParamConverter\EntityConverter; use Drupal\jsonapi\Routing\Routes; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException; use Symfony\Component\Routing\Route; diff --git a/core/modules/jsonapi/src/Revisions/ResourceVersionRouteEnhancer.php b/core/modules/jsonapi/src/Revisions/ResourceVersionRouteEnhancer.php index 50cb8b8c5d..8da175894c 100644 --- a/core/modules/jsonapi/src/Revisions/ResourceVersionRouteEnhancer.php +++ b/core/modules/jsonapi/src/Revisions/ResourceVersionRouteEnhancer.php @@ -8,7 +8,7 @@ use Drupal\Core\Http\Exception\CacheableHttpException; use Drupal\Core\Routing\EnhancerInterface; use Drupal\jsonapi\Routing\Routes; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; diff --git a/core/modules/jsonapi/src/Routing/Routes.php b/core/modules/jsonapi/src/Routing/Routes.php index e592f007ae..7ba8338112 100644 --- a/core/modules/jsonapi/src/Routing/Routes.php +++ b/core/modules/jsonapi/src/Routing/Routes.php @@ -8,7 +8,7 @@ use Drupal\jsonapi\ParamConverter\ResourceTypeConverter; use Drupal\jsonapi\ResourceType\ResourceType; use Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; diff --git a/core/modules/jsonapi/tests/src/Unit/EventSubscriber/ResourceResponseValidatorTest.php b/core/modules/jsonapi/tests/src/Unit/EventSubscriber/ResourceResponseValidatorTest.php index 6f45d5ecd9..2dcafb191d 100644 --- a/core/modules/jsonapi/tests/src/Unit/EventSubscriber/ResourceResponseValidatorTest.php +++ b/core/modules/jsonapi/tests/src/Unit/EventSubscriber/ResourceResponseValidatorTest.php @@ -12,7 +12,7 @@ use Drupal\Tests\UnitTestCase; use Prophecy\Argument; use Psr\Log\LoggerInterface; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\Request; /** diff --git a/core/modules/jsonapi/tests/src/Unit/Routing/RoutesTest.php b/core/modules/jsonapi/tests/src/Unit/Routing/RoutesTest.php index 4a70512a0d..e6c08a6559 100644 --- a/core/modules/jsonapi/tests/src/Unit/Routing/RoutesTest.php +++ b/core/modules/jsonapi/tests/src/Unit/Routing/RoutesTest.php @@ -8,7 +8,7 @@ use Drupal\jsonapi\ResourceType\ResourceTypeRepository; use Drupal\jsonapi\Routing\Routes; use Drupal\Tests\UnitTestCase; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** diff --git a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationContentEntity.php b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationContentEntity.php index a28506caeb..87e12c7d4b 100644 --- a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationContentEntity.php +++ b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationContentEntity.php @@ -10,7 +10,7 @@ use Drupal\Core\Url; use Drupal\language\LanguageNegotiationMethodBase; use Drupal\language\LanguageSwitcherInterface; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Route; diff --git a/core/modules/language/tests/src/Functional/LanguageNegotiationContentEntityTest.php b/core/modules/language/tests/src/Functional/LanguageNegotiationContentEntityTest.php index 7c973368a3..9695cd5769 100644 --- a/core/modules/language/tests/src/Functional/LanguageNegotiationContentEntityTest.php +++ b/core/modules/language/tests/src/Functional/LanguageNegotiationContentEntityTest.php @@ -9,7 +9,7 @@ use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationContentEntity; use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl; use Drupal\Tests\BrowserTestBase; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Route; diff --git a/core/modules/language/tests/src/Kernel/EntityUrlLanguageTest.php b/core/modules/language/tests/src/Kernel/EntityUrlLanguageTest.php index 03669cc3cd..9e60aa721c 100644 --- a/core/modules/language/tests/src/Kernel/EntityUrlLanguageTest.php +++ b/core/modules/language/tests/src/Kernel/EntityUrlLanguageTest.php @@ -7,7 +7,7 @@ use Drupal\language\Entity\ConfigurableLanguage; use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationContentEntity; use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Route; diff --git a/core/modules/menu_link_content/tests/src/Kernel/MenuLinkContentCacheabilityBubblingTest.php b/core/modules/menu_link_content/tests/src/Kernel/MenuLinkContentCacheabilityBubblingTest.php index 9701bcf8d1..1b9ae65ffe 100644 --- a/core/modules/menu_link_content/tests/src/Kernel/MenuLinkContentCacheabilityBubblingTest.php +++ b/core/modules/menu_link_content/tests/src/Kernel/MenuLinkContentCacheabilityBubblingTest.php @@ -10,7 +10,7 @@ use Drupal\menu_link_content\Entity\MenuLinkContent; use Drupal\Tests\user\Traits\UserCreationTrait; use Drupal\user\Entity\User; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Route; diff --git a/core/modules/system/src/Tests/Routing/MockRouteProvider.php b/core/modules/system/src/Tests/Routing/MockRouteProvider.php index 5612ddd75b..7c34358dec 100644 --- a/core/modules/system/src/Tests/Routing/MockRouteProvider.php +++ b/core/modules/system/src/Tests/Routing/MockRouteProvider.php @@ -30,7 +30,7 @@ public function __construct(RouteCollection $routes) { } /** - * Implements \Symfony\Cmf\Component\Routing\RouteProviderInterface::getRouteCollectionForRequest(). + * Implements \Drupal\Core\Routing\RouteProviderInterface::getRouteCollectionForRequest(). * * Simply return all routes to prevent * \Symfony\Component\Routing\Exception\ResourceNotFoundException. diff --git a/core/modules/system/tests/modules/router_test_directory/src/TestControllers.php b/core/modules/system/tests/modules/router_test_directory/src/TestControllers.php index fe228a336b..e8e0604e3a 100644 --- a/core/modules/system/tests/modules/router_test_directory/src/TestControllers.php +++ b/core/modules/system/tests/modules/router_test_directory/src/TestControllers.php @@ -5,7 +5,7 @@ use Drupal\Core\Cache\CacheableResponse; use Drupal\Core\ParamConverter\ParamNotConvertedException; use Drupal\user\UserInterface; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Laminas\Diactoros\Response\HtmlResponse; diff --git a/core/modules/system/tests/src/Functional/Theme/ThemeTest.php b/core/modules/system/tests/src/Functional/Theme/ThemeTest.php index 1c65277f27..0cd5dc479b 100644 --- a/core/modules/system/tests/src/Functional/Theme/ThemeTest.php +++ b/core/modules/system/tests/src/Functional/Theme/ThemeTest.php @@ -4,7 +4,7 @@ use Drupal\Component\Serialization\Json; use Drupal\Tests\BrowserTestBase; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Route; diff --git a/core/modules/system/tests/src/Kernel/Block/SystemMenuBlockTest.php b/core/modules/system/tests/src/Kernel/Block/SystemMenuBlockTest.php index 6ac0e03d38..b6ea41a179 100644 --- a/core/modules/system/tests/src/Kernel/Block/SystemMenuBlockTest.php +++ b/core/modules/system/tests/src/Kernel/Block/SystemMenuBlockTest.php @@ -10,7 +10,7 @@ use Drupal\system\Tests\Routing\MockRouteProvider; use Drupal\Tests\Core\Menu\MenuLinkMock; use Drupal\user\Entity\User; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; diff --git a/core/modules/system/tests/src/Unit/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php b/core/modules/system/tests/src/Unit/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php index df5d756801..0b0c1e4aaa 100644 --- a/core/modules/system/tests/src/Unit/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php +++ b/core/modules/system/tests/src/Unit/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php @@ -17,7 +17,7 @@ use Drupal\Core\Utility\LinkGeneratorInterface; use Drupal\system\PathBasedBreadcrumbBuilder; use Drupal\Tests\UnitTestCase; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; diff --git a/core/modules/user/src/Plugin/LanguageNegotiation/LanguageNegotiationUserAdmin.php b/core/modules/user/src/Plugin/LanguageNegotiation/LanguageNegotiationUserAdmin.php index 4a829906ae..fec14c3262 100644 --- a/core/modules/user/src/Plugin/LanguageNegotiation/LanguageNegotiationUserAdmin.php +++ b/core/modules/user/src/Plugin/LanguageNegotiation/LanguageNegotiationUserAdmin.php @@ -7,7 +7,7 @@ use Drupal\Core\Routing\AdminContext; use Drupal\Core\Routing\StackedRouteMatchInterface; use Drupal\language\LanguageNegotiationMethodBase; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; diff --git a/core/modules/views/tests/src/Unit/Routing/ViewPageControllerTest.php b/core/modules/views/tests/src/Unit/Routing/ViewPageControllerTest.php index 26d9ce7e11..2250acf7b3 100644 --- a/core/modules/views/tests/src/Unit/Routing/ViewPageControllerTest.php +++ b/core/modules/views/tests/src/Unit/Routing/ViewPageControllerTest.php @@ -5,7 +5,7 @@ use Drupal\Core\Routing\RouteMatch; use Drupal\Tests\UnitTestCase; use Drupal\views\Routing\ViewPageController; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Route; diff --git a/core/modules/views_ui/src/ViewUI.php b/core/modules/views_ui/src/ViewUI.php index 056c7ea0c3..d1d7387abe 100644 --- a/core/modules/views_ui/src/ViewUI.php +++ b/core/modules/views_ui/src/ViewUI.php @@ -16,7 +16,7 @@ use Drupal\views\Plugin\views\query\Sql; use Drupal\views\Entity\View; use Drupal\views\ViewEntityInterface; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; diff --git a/core/tests/Drupal/KernelTests/Core/RouteProcessor/RouteNoneTest.php b/core/tests/Drupal/KernelTests/Core/RouteProcessor/RouteNoneTest.php index 922eefa25b..457602945c 100644 --- a/core/tests/Drupal/KernelTests/Core/RouteProcessor/RouteNoneTest.php +++ b/core/tests/Drupal/KernelTests/Core/RouteProcessor/RouteNoneTest.php @@ -6,7 +6,7 @@ use Drupal\Core\GeneratedUrl; use Drupal\Core\Render\BubbleableMetadata; use Drupal\KernelTests\KernelTestBase; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Route; diff --git a/core/tests/Drupal/KernelTests/Core/RouteProcessor/RouteProcessorCurrentIntegrationTest.php b/core/tests/Drupal/KernelTests/Core/RouteProcessor/RouteProcessorCurrentIntegrationTest.php index 235af6e144..4da27e3669 100644 --- a/core/tests/Drupal/KernelTests/Core/RouteProcessor/RouteProcessorCurrentIntegrationTest.php +++ b/core/tests/Drupal/KernelTests/Core/RouteProcessor/RouteProcessorCurrentIntegrationTest.php @@ -6,7 +6,7 @@ use Drupal\Core\GeneratedUrl; use Drupal\Core\Render\BubbleableMetadata; use Drupal\KernelTests\KernelTestBase; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Route; diff --git a/core/tests/Drupal/KernelTests/Core/Routing/RouteProviderTest.php b/core/tests/Drupal/KernelTests/Core/Routing/RouteProviderTest.php index 0d4252944d..7ed0eee76b 100644 --- a/core/tests/Drupal/KernelTests/Core/Routing/RouteProviderTest.php +++ b/core/tests/Drupal/KernelTests/Core/Routing/RouteProviderTest.php @@ -291,6 +291,33 @@ public function testDuplicateRoutePaths($path, $number, $expected_route_name = N } } + /** + * Confirms RouteProvider::getAllRoutes() extracts information correctly from the database. + */ + public function testGetAllRoutes() { + $connection = Database::getConnection(); + $provider = new RouteProvider($connection, $this->state, $this->currentPath, $this->cache, $this->pathProcessor, $this->cacheTagsInvalidator, 'test_routes'); + + $this->fixtures->createTables($connection); + + $dumper = new MatcherDumper($connection, $this->state, 'test_routes'); + $dumper->addRoutes($this->fixtures->SampleRouteCollection()); + $dumper->dump(); + + $sample_routes = $this->fixtures->staticSampleRouteCollection(); + $expected_route_count = count($sample_routes); + + $returned_routes = $provider->getAllRoutes(); + $route_count = count($returned_routes); + + $this->assertEqual($expected_route_count, count($returned_routes)); + + foreach($returned_routes as $route_name=>$route) { + $this->assertTrue(array_key_exists($route_name, $sample_routes)); + $this->assertEquals($route->getPath(), $sample_routes[$route_name]['path']); + } + } + /** * Confirms that a trailing slash on the request does not result in a 404. */ @@ -705,6 +732,9 @@ public function testGetRoutesByPatternWithLongPatterns() { /** * Tests getRoutesPaged(). + * + * @group legacy + * @expectedDeprecation Drupal\Core\Routing\RouteProvider::getRoutesPaged() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. No direct replacement is provided. See https://www.drupal.org/node/3151009 */ public function testGetRoutesPaged() { $connection = Database::getConnection(); @@ -730,6 +760,23 @@ public function testGetRoutesPaged() { $this->assertEqual(array_keys($routes), array_slice(array_keys($fixture_routes), 1, 2)); } + /** + * Tests getRoutesCount(). + * + * @group legacy + * @expectedDeprecation Drupal\Core\Routing\RouteProvider::getRoutesCount() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. No direct replacement is provided. See https://www.drupal.org/node/3151009 + */ + public function testGetRoutesCount() { + $connection = Database::getConnection(); + $provider = new RouteProvider($connection, $this->state, $this->currentPath, $this->cache, $this->pathProcessor, $this->cacheTagsInvalidator, 'test_routes'); + + $this->fixtures->createTables($connection); + $dumper = new MatcherDumper($connection, $this->state, 'test_routes'); + $dumper->addRoutes($this->fixtures->sampleRouteCollection()); + $dumper->dump(); + $this->assertEqual($provider->getRoutesCount(), 5); + } + } class TestRouteProvider extends RouteProvider { diff --git a/core/tests/Drupal/KernelTests/KernelTestBase.php b/core/tests/Drupal/KernelTests/KernelTestBase.php index b1ebad5e32..5d13f51683 100644 --- a/core/tests/Drupal/KernelTests/KernelTestBase.php +++ b/core/tests/Drupal/KernelTests/KernelTestBase.php @@ -28,7 +28,7 @@ use Symfony\Component\HttpFoundation\Request; use org\bovigo\vfs\vfsStream; use org\bovigo\vfs\visitor\vfsStreamPrintVisitor; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\Routing\Route; /** diff --git a/core/tests/Drupal/KernelTests/RouteProvider.php b/core/tests/Drupal/KernelTests/RouteProvider.php index 4034da8896..f075dbae0d 100644 --- a/core/tests/Drupal/KernelTests/RouteProvider.php +++ b/core/tests/Drupal/KernelTests/RouteProvider.php @@ -3,20 +3,19 @@ namespace Drupal\KernelTests; use Drupal\Core\Routing\PreloadableRouteProviderInterface; -use Symfony\Cmf\Component\Routing\PagedRouteProviderInterface; use Symfony\Component\HttpFoundation\Request; /** * Rebuilds the router when the provider is instantiated. */ -class RouteProvider implements PreloadableRouteProviderInterface, PagedRouteProviderInterface { +class RouteProvider implements PreloadableRouteProviderInterface { use \Drupal\Core\DependencyInjection\DependencySerializationTrait; /** * Loads the real route provider from the container and rebuilds the router. * - * @return \Drupal\Core\Routing\PreloadableRouteProviderInterface|\Symfony\Cmf\Component\Routing\PagedRouteProviderInterface|\Symfony\Component\EventDispatcher\EventSubscriberInterface + * @return \Drupal\Core\Routing\PreloadableRouteProviderInterface|\Symfony\Component\EventDispatcher\EventSubscriberInterface * The route provider. */ protected function lazyLoadItself() { @@ -92,18 +91,4 @@ public function reset() { return $this->lazyLoadItself()->reset(); } - /** - * {@inheritdoc} - */ - public function getRoutesPaged($offset, $length = NULL) { - return $this->lazyLoadItself()->getRoutesPaged($offset, $length); - } - - /** - * {@inheritdoc} - */ - public function getRoutesCount() { - return $this->lazyLoadItself()->getRoutesCount(); - } - } diff --git a/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php b/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php index e1ea933640..69ede129af 100644 --- a/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php @@ -17,7 +17,7 @@ use Drupal\Core\Access\DefaultAccessCheck; use Drupal\Tests\UnitTestCase; use Drupal\router_test\Access\DefinedTestAccessCheck; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\Routing\Exception\RouteNotFoundException; use Symfony\Component\Routing\Route; diff --git a/core/tests/Drupal/Tests/Core/Authentication/AuthenticationManagerTest.php b/core/tests/Drupal/Tests/Core/Authentication/AuthenticationManagerTest.php index 8269796781..d580d8204e 100644 --- a/core/tests/Drupal/Tests/Core/Authentication/AuthenticationManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Authentication/AuthenticationManagerTest.php @@ -12,7 +12,7 @@ use Drupal\Core\Authentication\AuthenticationProviderFilterInterface; use Drupal\Core\Authentication\AuthenticationProviderInterface; use Drupal\Tests\UnitTestCase; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Route; diff --git a/core/tests/Drupal/Tests/Core/Enhancer/EntityRevisionRouteEnhancerTest.php b/core/tests/Drupal/Tests/Core/Enhancer/EntityRevisionRouteEnhancerTest.php index db481e8c8e..a250594ee2 100644 --- a/core/tests/Drupal/Tests/Core/Enhancer/EntityRevisionRouteEnhancerTest.php +++ b/core/tests/Drupal/Tests/Core/Enhancer/EntityRevisionRouteEnhancerTest.php @@ -5,7 +5,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Routing\Enhancer\EntityRevisionRouteEnhancer; use Drupal\Tests\UnitTestCase; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Route; diff --git a/core/tests/Drupal/Tests/Core/Enhancer/ParamConversionEnhancerTest.php b/core/tests/Drupal/Tests/Core/Enhancer/ParamConversionEnhancerTest.php index e46b934d10..148f846cd1 100644 --- a/core/tests/Drupal/Tests/Core/Enhancer/ParamConversionEnhancerTest.php +++ b/core/tests/Drupal/Tests/Core/Enhancer/ParamConversionEnhancerTest.php @@ -4,7 +4,7 @@ use Drupal\Core\Routing\Enhancer\ParamConversionEnhancer; use Drupal\Tests\UnitTestCase; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Route; diff --git a/core/tests/Drupal/Tests/Core/Entity/Enhancer/EntityRouteEnhancerTest.php b/core/tests/Drupal/Tests/Core/Entity/Enhancer/EntityRouteEnhancerTest.php index 8eed80ac0d..297628262c 100644 --- a/core/tests/Drupal/Tests/Core/Entity/Enhancer/EntityRouteEnhancerTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Enhancer/EntityRouteEnhancerTest.php @@ -4,7 +4,7 @@ use Drupal\Core\Entity\Enhancer\EntityRouteEnhancer; use Drupal\Tests\UnitTestCase; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Route; diff --git a/core/tests/Drupal/Tests/Core/EventSubscriber/OptionsRequestSubscriberTest.php b/core/tests/Drupal/Tests/Core/EventSubscriber/OptionsRequestSubscriberTest.php index ee158c8424..6a2e7b6fd7 100644 --- a/core/tests/Drupal/Tests/Core/EventSubscriber/OptionsRequestSubscriberTest.php +++ b/core/tests/Drupal/Tests/Core/EventSubscriber/OptionsRequestSubscriberTest.php @@ -4,7 +4,7 @@ use Drupal\Core\EventSubscriber\OptionsRequestSubscriber; use Drupal\Tests\UnitTestCase; -use Symfony\Cmf\Component\Routing\RouteProviderInterface; +use Drupal\Core\Routing\RouteProviderInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; diff --git a/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php b/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php index 0aa466bddc..16b18a7663 100644 --- a/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php +++ b/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php @@ -6,7 +6,7 @@ use Drupal\Core\Routing\RouteBuildEvent; use Drupal\Tests\UnitTestCase; use PHPUnit\Framework\Error\Warning; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; diff --git a/core/tests/Drupal/Tests/Core/Menu/MenuActiveTrailTest.php b/core/tests/Drupal/Tests/Core/Menu/MenuActiveTrailTest.php index 4b8e8134f9..cf0483cc5d 100644 --- a/core/tests/Drupal/Tests/Core/Menu/MenuActiveTrailTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/MenuActiveTrailTest.php @@ -5,7 +5,7 @@ use Drupal\Core\Menu\MenuActiveTrail; use Drupal\Core\Routing\CurrentRouteMatch; use Drupal\Tests\UnitTestCase; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; diff --git a/core/tests/Drupal/Tests/Core/ParamConverter/ParamConverterManagerTest.php b/core/tests/Drupal/Tests/Core/ParamConverter/ParamConverterManagerTest.php index 7c0feba2fe..d755a78395 100644 --- a/core/tests/Drupal/Tests/Core/ParamConverter/ParamConverterManagerTest.php +++ b/core/tests/Drupal/Tests/Core/ParamConverter/ParamConverterManagerTest.php @@ -5,7 +5,7 @@ use Drupal\Core\ParamConverter\ParamConverterManager; use Drupal\Core\ParamConverter\ParamNotConvertedException; use Drupal\Tests\UnitTestCase; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; diff --git a/core/tests/Drupal/Tests/Core/Path/PathValidatorTest.php b/core/tests/Drupal/Tests/Core/Path/PathValidatorTest.php index d595193eb6..ae94ab15e2 100644 --- a/core/tests/Drupal/Tests/Core/Path/PathValidatorTest.php +++ b/core/tests/Drupal/Tests/Core/Path/PathValidatorTest.php @@ -5,7 +5,7 @@ use Drupal\Core\ParamConverter\ParamNotConvertedException; use Drupal\Core\Path\PathValidator; use Drupal\Tests\UnitTestCase; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\Routing\Exception\MethodNotAllowedException; diff --git a/core/tests/Drupal/Tests/Core/Routing/AccessAwareRouterTest.php b/core/tests/Drupal/Tests/Core/Routing/AccessAwareRouterTest.php index a52f9735a3..1908fbe031 100644 --- a/core/tests/Drupal/Tests/Core/Routing/AccessAwareRouterTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/AccessAwareRouterTest.php @@ -6,7 +6,7 @@ use Drupal\Core\Routing\AccessAwareRouter; use Drupal\Core\Routing\AccessAwareRouterInterface; use Drupal\Tests\UnitTestCase; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\Routing\Route; @@ -23,9 +23,9 @@ class AccessAwareRouterTest extends UnitTestCase { protected $route; /** - * @var \Symfony\Cmf\Component\Routing\ChainRouter|\PHPUnit\Framework\MockObject\MockObject + * @var \Drupal\Core\Routing\Router|\PHPUnit\Framework\MockObject\MockObject */ - protected $chainRouter; + protected $coreRouter; /** * @var \Drupal\Core\Access\AccessManagerInterface|\PHPUnit\Framework\MockObject\MockObject @@ -40,7 +40,7 @@ class AccessAwareRouterTest extends UnitTestCase { /** * @var \Drupal\Core\Routing\AccessAwareRouter */ - protected $router; + protected $accessAwareRouter; /** * {@inheritdoc} @@ -56,13 +56,13 @@ protected function setUp(): void { * Sets up a chain router with matchRequest. */ protected function setupRouter() { - $this->chainRouter = $this->getMockBuilder('Symfony\Cmf\Component\Routing\ChainRouter') + $this->router = $this->getMockBuilder('Drupal\Core\Routing\Router') ->disableOriginalConstructor() ->getMock(); - $this->chainRouter->expects($this->once()) + $this->router->expects($this->once()) ->method('matchRequest') ->will($this->returnValue([RouteObjectInterface::ROUTE_OBJECT => $this->route])); - $this->router = new AccessAwareRouter($this->chainRouter, $this->accessManager, $this->currentUser); + $this->accessAwareRouter = new AccessAwareRouter($this->router, $this->accessManager, $this->currentUser); } /** @@ -76,7 +76,7 @@ public function testMatchRequestAllowed() { ->method('checkRequest') ->with($request) ->willReturn($access_result); - $parameters = $this->router->matchRequest($request); + $parameters = $this->accessAwareRouter->matchRequest($request); $expected = [ RouteObjectInterface::ROUTE_OBJECT => $this->route, AccessAwareRouterInterface::ACCESS_RESULT => $access_result, @@ -97,7 +97,7 @@ public function testMatchRequestDenied() { ->with($request) ->willReturn($access_result); $this->expectException(AccessDeniedHttpException::class); - $this->router->matchRequest($request); + $this->accessAwareRouter->matchRequest($request); } /** @@ -114,7 +114,7 @@ public function testCheckAccessResultWithReason() { ->willReturn($access_result); $this->expectException(AccessDeniedHttpException::class); $this->expectExceptionMessage($reason); - $this->router->matchRequest($request); + $this->accessAwareRouter->matchRequest($request); } /** @@ -125,17 +125,17 @@ public function testCheckAccessResultWithReason() { public function testCall() { $mock_router = $this->createMock('Symfony\Component\Routing\RouterInterface'); - $this->chainRouter = $this->getMockBuilder('Symfony\Cmf\Component\Routing\ChainRouter') + $this->router = $this->getMockBuilder('Drupal\Core\Routing\Router') ->disableOriginalConstructor() ->setMethods(['add']) ->getMock(); - $this->chainRouter->expects($this->once()) + $this->router->expects($this->once()) ->method('add') ->with($mock_router) ->willReturnSelf(); - $this->router = new AccessAwareRouter($this->chainRouter, $this->accessManager, $this->currentUser); + $this->accessAwareRouter = new AccessAwareRouter($this->router, $this->accessManager, $this->currentUser); - $this->router->add($mock_router); + $this->accessAwareRouter->add($mock_router); } } diff --git a/core/tests/Drupal/Tests/Core/Routing/CurrentRouteMatchTest.php b/core/tests/Drupal/Tests/Core/Routing/CurrentRouteMatchTest.php index ec3861cf36..77ce024059 100644 --- a/core/tests/Drupal/Tests/Core/Routing/CurrentRouteMatchTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/CurrentRouteMatchTest.php @@ -3,7 +3,7 @@ namespace Drupal\Tests\Core\Routing; use Drupal\Core\Routing\CurrentRouteMatch; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; diff --git a/core/tests/Drupal/Tests/Core/Routing/LazyRouteCollectionTest.php b/core/tests/Drupal/Tests/Core/Routing/LazyRouteCollectionTest.php new file mode 100644 index 0000000000..eb450ea03c --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Routing/LazyRouteCollectionTest.php @@ -0,0 +1,94 @@ +routeProvider = $this->createMock(RouteProviderInterface::class); + $this->testRoutes = [ + 'route_1' => new Route('/route-1'), + 'route_2' => new Route('/route-2'), + ]; + } + + /** + * @covers ::getIterator + * @covers ::all + */ + public function testGetIterator() { + $this->routeProvider->expects($this->exactly(2)) + ->method('getRoutesByNames') + ->with(NULL) + ->will($this->returnValue($this->testRoutes)); + $lazyRouteCollection = new LazyRouteCollection($this->routeProvider); + $this->assertEquals($this->testRoutes, iterator_to_array($lazyRouteCollection->getIterator())); + $this->assertEquals($this->testRoutes, $lazyRouteCollection->all()); + } + + /** + * @covers ::count + */ + public function testCount() { + $this->routeProvider + ->method('getRoutesByNames') + ->with(NULL) + ->will($this->returnValue($this->testRoutes)); + $lazyRouteCollection = new LazyRouteCollection($this->routeProvider); + $this->assertEquals(2, $lazyRouteCollection->count()); + } + + /** + * Search for a both a findable and a unfindable route. + * + * @covers ::get + */ + public function testGetName() { + // Hit. + $this->routeProvider + ->method('getRouteByName') + ->with('route_1') + ->will($this->returnValue($this->testRoutes['route_1'])); + $lazyRouteCollection = new LazyRouteCollection($this->routeProvider); + $this->assertEquals($lazyRouteCollection->get('route_1'), $this->testRoutes['route_1']); + + // Miss. + $this->routeProvider + ->method('getRouteByName') + ->with('does_not_exists') + ->will($this->throwException(new RouteNotFoundException())); + + $lazyRouteCollectionFail = new LazyRouteCollection($this->routeProvider); + $this->assertNull($lazyRouteCollectionFail->get('does_not_exists')); + } + +} diff --git a/core/tests/Drupal/Tests/Core/Routing/RouteMatchTest.php b/core/tests/Drupal/Tests/Core/Routing/RouteMatchTest.php index 0a3c65cbe9..a5bfcb33da 100644 --- a/core/tests/Drupal/Tests/Core/Routing/RouteMatchTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/RouteMatchTest.php @@ -3,7 +3,7 @@ namespace Drupal\Tests\Core\Routing; use Drupal\Core\Routing\RouteMatch; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Route; diff --git a/core/tests/Drupal/Tests/Core/UrlTest.php b/core/tests/Drupal/Tests/Core/UrlTest.php index 45a869af75..99cec218b1 100644 --- a/core/tests/Drupal/Tests/Core/UrlTest.php +++ b/core/tests/Drupal/Tests/Core/UrlTest.php @@ -14,7 +14,7 @@ use Drupal\Core\Routing\RouteMatch; use Drupal\Core\Url; use Drupal\Tests\UnitTestCase; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Exception\InvalidParameterException;