diff --git a/core/authorize.php b/core/authorize.php index e0b7c4f192fab2c49e3ceb31709ef44d9e069b01..9ffe8e2b7d3e03d3ff0c435cc1aa42685ef98ca8 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 b6bc1e1c0bb3706114889ee3ce7b732921d56482..d610fdd25c03011a9934bd7022dad5462e6ad1f1 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 d2b7e55f99ab70c120bd0dc0779383f59c9ae52e..36dec5b65c615be244d604e970d553d1901d7eb0 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 f383fbc986404c45f6744d18cb95ca0bea4d955c..aa0b41a2fa9e1536b538beda2d2c78e5f0a7657b 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 9520283a9898b37c01e914317f716a93f435be18..18982a6d6e4bf80de05b9196e18cd7bd32dcc3a7 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 0f40c5a58ebade7e75f046bf2ec775055ba0be3f..67b2fba2b6c50fce1b5b259726743c0292608943 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 944bd5304c9d802dd031898167a87b0ccba099dc..c3ca6ba879ea0deb96a6dad47d648e9328575448 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 efce47305a20fe394601f281b3dcb1725a1d9c41..58976df17756b06bdbf8e73b3a510cbb6424e648 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 d54338f449146678507e476d6269c4d326bd8ac4..bdd52cbdd30d643f908503d47dd446f5ff2d349e 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 c812178d29248616a1c83416cd995aa6c6bb51bc..9e9df9f71dd24e12f8d306d928b7cc42701d8faa 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 aa2b8c830c861786f7184e04deb1b45dba7b990c..507366bc7c05bf1915d3bbe1608b55c63adc835f 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 3ddee667526ffca88c9d9f96547cbce5c855f1d1..3439a4a17201aaea9ea695189e2ef691a03fb1b4 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 73c9f83a265c217e6a7ca8880b44478dcd667501..ad446a69940f0d6733d57d0d54e4534ec83ec966 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 0000000000000000000000000000000000000000..5f9706efe7fa2dba330c2d7b7e0ce6562bc595c4 --- /dev/null +++ b/core/lib/Drupal/Core/Routing/LazyRouteCollection.php @@ -0,0 +1,68 @@ +<?php + +namespace Drupal\Core\Routing; + +use Symfony\Component\Routing\Exception\RouteNotFoundException; +use Symfony\Component\Routing\RouteCollection; + +class LazyRouteCollection extends RouteCollection { + /** + * The route provider for this generator. + * + * @var \Symfony\Component\Routing\RouteProviderInterface + */ + protected $provider; + + /** + * Constructs a LazyRouteCollection. + */ + public function __construct(RouteProviderInterface $provider) { + $this->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 10c444758fef5dc4b18df246769ee11ba8f97734..e00be3554f6bf420db65987fe4abd92bd896cea0 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 0000000000000000000000000000000000000000..e7afacd62431a5983c97072cc0067100140eaa74 --- /dev/null +++ b/core/lib/Drupal/Core/Routing/RouteObjectInterface.php @@ -0,0 +1,29 @@ +<?php + +namespace Drupal\Core\Routing; + +/** + * Provides constants used for retrieving matched routes. + */ +interface RouteObjectInterface { + + /** + * Key for the route name. + * + * @var string + */ + const ROUTE_NAME = '_route'; + + /** + * Key for the route object. + * + * @var string + */ + const ROUTE_OBJECT = '_route_object'; + + /** + * Key for the controller. + */ + const CONTROLLER_NAME = '_controller'; + +} diff --git a/core/lib/Drupal/Core/Routing/RouteProvider.php b/core/lib/Drupal/Core/Routing/RouteProvider.php index c372b7bdac56280077561db054e54249bfb267e3..4920dbafbdfcac136e058163c0a0ca2fe8d74068 100644 --- a/core/lib/Drupal/Core/Routing/RouteProvider.php +++ b/core/lib/Drupal/Core/Routing/RouteProvider.php @@ -10,8 +10,6 @@ use Drupal\Core\Path\CurrentPathStack; use Drupal\Core\PathProcessor\InboundPathProcessorInterface; use Drupal\Core\State\StateInterface; -use Symfony\Cmf\Component\Routing\PagedRouteCollection; -use Symfony\Cmf\Component\Routing\PagedRouteProviderInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Exception\RouteNotFoundException; @@ -21,7 +19,7 @@ /** * A Route Provider front-end for all Drupal-stored routes. */ -class RouteProvider implements CacheableRouteProviderInterface, PreloadableRouteProviderInterface, PagedRouteProviderInterface, EventSubscriberInterface { +class RouteProvider implements CacheableRouteProviderInterface, PreloadableRouteProviderInterface, EventSubscriberInterface { /** * The database connection from which to read route information. @@ -401,7 +399,16 @@ protected function routeProviderRouteCompare(array $a, array $b) { * {@inheritdoc} */ public function getAllRoutes() { - return new PagedRouteCollection($this); + $select = $this->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 f53593a82e1826fcd743b2b109a4044d5890492b..cc6632a1166a145414d2ef178d3ed352ac99251d 100644 --- a/core/lib/Drupal/Core/Routing/RouteProviderInterface.php +++ b/core/lib/Drupal/Core/Routing/RouteProviderInterface.php @@ -2,6 +2,7 @@ namespace Drupal\Core\Routing; +use Symfony\Component\HttpFoundation\Request; use Symfony\Cmf\Component\Routing\RouteProviderInterface as RouteProviderBaseInterface; /** @@ -11,6 +12,71 @@ */ interface RouteProviderInterface extends RouteProviderBaseInterface { + /** + * 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 a2cb8c57851330c28545bd05fa136b6f36d52bf1..d5a55a9a3a5cf161537babddd8d02b073ee30624 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 d1586e42b165bdb5a8eb42d7d674bdf046c758f5..8b649a3ec2a2285e2b0996cf4ffc1a3402ce8b15 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 e63383df5f89c5b529d98a91c8510b3cdc34f3ae..bbc91de1d195cf71e7f2a5326ad393cde2301550 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 90569033687cd6123d6ccd9c2512ad6fe504e9ed..bc9a63f5f6ee5b9a3c8f3d4edc084156d0d9af8b 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 a10af1e48c33a7a7ca9f8fb72894423851ea0be0..5047975076155302a4b5793db2544bb27e50b5ee 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 2b74dabb67be3e17a9a0c886e4913fd8cd8eae57..edcee199607b321490da31810bfe70c83231bb4f 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 82c2c600b3760f78d49170ca79f6c01f40409b95..09b988f413ecc665589d54a26df8e40a892ae491 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 c7e51950e8ae6a7b42426a12eb10bc7f5c1af10a..dac2ca0d473c46861c5fdaed468fa214dffe65a6 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 abc10cff4fc216a15bac637af8aa7fa1fd877464..1b4ef83e436cbadb6dcdb918aeedf52662fbf796 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 50cb8b8c5d71e64c89d700616159bf0d9f37d46c..8da175894cec289b6ed523ea99d8eaadeb3325f9 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 e592f007aef63bbed7abaccf5e6b571cb3a3500f..7ba8338112cda74c007ab4a6038d4e3487f34879 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 6f45d5ecd93332ad45f252eeca7316aeb1d30ede..2dcafb191df2ea7e1ba546ad990b40a453342692 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 4a70512a0d88b4cf706fce8918e786cd52b8a160..e6c08a655955422ccacf02dfca5d567772212265 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 a28506caebeba5df7348d8864ffdceaf4429427a..87e12c7d4b9edaf128a1a08f619e9631d317bac3 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 7c973368a399f509d5ec35724d0abdb45bcf81e6..9695cd57696790f07951edaa7e1a4850b6e75ce6 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 03669cc3cdfe012747ae3932beef4f1c0249d3e0..9e60aa721cd749c96074cc86b43b320d7d81fda1 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 9701bcf8d1149033d62d2c7c323f19635da7b130..1b9ae65ffe3418cc8bb80e2826206bccbff6f840 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 5612ddd75bf59add0c4830bbddde450519e1690f..7c34358dec6bda64a4425e734733c9f8c1d395f9 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 fe228a336b649f64a2fb56ca12ba4839c347e75d..e8e0604e3ad44ca90ba9b2c0c02c2d4ae28c1403 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 1c65277f2705a41facd940afb3c3f7f618242533..0cd5dc479be2ef4297355c1a4f3b61bdf184cbc1 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 6ac0e03d38876ee1961faa6498706ee2920bf91c..b6ea41a1790bd9f97c07cad2d67f967e23090953 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 df5d756801f948831f8cb34c6f838e3ec009db31..0b0c1e4aaad13227b70b96d965af8c975c57ea76 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 4a829906ae9696166e32ae261d33318ece494231..fec14c3262b13b3c77212dc2dfca8ca374a699b8 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 26d9ce7e110f2c69cd05db449b3d4c3bb0d5909a..2250acf7b3758906d3fd597377c5f479faf0e9a2 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 056c7ea0c359d45bd2dd8a7087d3f9017dc57adc..d1d7387abecbefe29c4bf760a42a1d19b7803f9f 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 922eefa25b5e56b8b03581e61313d216ad0a16f6..457602945c760ae4b0d15d835ecbada747d4671b 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 235af6e144f4b10721b3f74cb089304aef942576..4da27e3669cfb9283427b0bb16eacba5f13ca0ca 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 e21a0ce9c018856ade819af306d77cc598f445d4..41f9ca5ef08493f378d220342c29820566c7f771 100644 --- a/core/tests/Drupal/KernelTests/Core/Routing/RouteProviderTest.php +++ b/core/tests/Drupal/KernelTests/Core/Routing/RouteProviderTest.php @@ -293,6 +293,32 @@ 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(); + + $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. */ @@ -707,6 +733,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(); @@ -732,6 +761,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 b1ebad5e32b601bfa9af0559b1b0c44902cafe82..5d13f516837393acadee7af551724a284b82c192 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 4034da8896e06642cbc713edc171fe9fe78b3c7a..f075dbae0d78710c30fd5d2de01b6ec46945c00d 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 e1ea93364046daf2a714a5f452d838efb369ed45..69ede129af76949f6a43f57ede4fb537fb5271b6 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 8269796781eca0f44dda553786a4570477558d29..d580d8204e34df82470b6dd31b335b0c718fe0c1 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 db481e8c8e07c09006d1f1d068c652aa5279820c..a250594ee23197d1ef6ca1ea9dc8c3e5621c2b6f 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 e46b934d10f1fceca0cfb838e83c6c2fe813a23a..148f846cd170cfa0f319d53110918a7bd8a2f2fb 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 8eed80ac0d1ae44ce1522cc4e93f8bad6bf6610d..297628262cc84e9d31a58f941cfe535b8be7e47d 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 ee158c842423064cb790d57acec0c76e40ebe514..6a2e7b6fd7903e3e411689d77c02c2ba790e52b1 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 0aa466bddc48893db289ac8727b489c816f80f63..16b18a76636ea83ddc364d110edc969157c8b255 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 4b8e8134f9049cefbb8530b62c7233a1f4fddcde..cf0483cc5d19feeab87a61059157252a4f5aea33 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 7c0feba2fe6b659959a3d49ee7c2fb125aa93c1b..d755a783953946ac2ce6487221926d69f78680d1 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 d595193eb69dd35f40cacfae5ff7813c6a55b659..ae94ab15e2ffb7537c9ae2c1ef4fb12091dbc0d3 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 a52f9735a3741dcabbd3ae975b6f8d3d6124e2e4..1908fbe03175c121eee640f157bad178046699bb 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 ec3861cf36d2b780a39ddc666e37ac3861f87f2b..77ce02405936736e23f9d2273ce4b471cf98fd81 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 0000000000000000000000000000000000000000..88aa9470433d9ce72fa226e1a188a0c25725d99c --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Routing/LazyRouteCollectionTest.php @@ -0,0 +1,94 @@ +<?php + +namespace Drupal\Tests\Core\Routing; + +use Drupal\Tests\UnitTestCase; +use Drupal\Core\Routing\LazyRouteCollection; +use Drupal\Core\Routing\RouteProviderInterface; +use Symfony\Component\Routing\Exception\RouteNotFoundException; +use Symfony\Component\Routing\Route; + +/** + * @coversDefaultClass \Drupal\Core\Routing\LazyRouteCollection + * + * @group Routing + */ +class LazyRouteCollectionTest extends UnitTestCase { + + /** + * The route provider. + * + * @var \Drupal\Core\Routing\RouteProviderInterface + */ + private $routeProvider; + + /** + * Array of routes indexed by name. + * + * @var array + */ + private $testRoutes; + + /** + * {@inheritdoc} + */ + public function setUp(): void { + parent::setUp(); + $this->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 an existing and a non-existing 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_exist') + ->will($this->throwException(new RouteNotFoundException())); + + $lazyRouteCollectionFail = new LazyRouteCollection($this->routeProvider); + $this->assertNull($lazyRouteCollectionFail->get('does_not_exist')); + } + +} diff --git a/core/tests/Drupal/Tests/Core/Routing/RouteMatchTest.php b/core/tests/Drupal/Tests/Core/Routing/RouteMatchTest.php index 0a3c65cbe9fbe386122b557771d84d2babb10a39..a5bfcb33dab7634c6b972b1d956cc6c371aa6b4c 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 45a869af75f814e7c1f41ed1dd1e3dc22d3c3ffc..99cec218b10a426f714bd54c93e8dadc622a79cc 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;