diff --git a/core/core.services.yml b/core/core.services.yml index c2e8893..3e2feb6 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -624,11 +624,6 @@ services: class: Drupal\Core\EventSubscriber\AjaxSubscriber tags: - { name: event_subscriber } - lazy_route_enhancer: - class: Drupal\Core\Routing\Enhancer\RouteEnhancerInterface - arguments: - tags: - - { name: lazy_route_enhancer, priority: 5000 } route_enhancer.param_conversion: class: Drupal\Core\Routing\Enhancer\ParamConversionEnhancer arguments: ['@paramconverter_manager'] diff --git a/core/lib/Drupal/Core/Entity/Enhancer/EntityRouteEnhancer.php b/core/lib/Drupal/Core/Entity/Enhancer/EntityRouteEnhancer.php index fd88894..7d1c643 100644 --- a/core/lib/Drupal/Core/Entity/Enhancer/EntityRouteEnhancer.php +++ b/core/lib/Drupal/Core/Entity/Enhancer/EntityRouteEnhancer.php @@ -7,8 +7,8 @@ namespace Drupal\Core\Entity\Enhancer; -use Drupal\Core\Routing\Enhancer\RouteEnhancerInterface; use Symfony\Component\HttpFoundation\Request; +use Symfony\Cmf\Component\Routing\Enhancer\RouteEnhancerInterface; use Symfony\Cmf\Component\Routing\RouteObjectInterface; /** diff --git a/core/lib/Drupal/Core/Routing/AcceptHeaderMatcher.php b/core/lib/Drupal/Core/Routing/AcceptHeaderMatcher.php index 1218fa6..e985815 100644 --- a/core/lib/Drupal/Core/Routing/AcceptHeaderMatcher.php +++ b/core/lib/Drupal/Core/Routing/AcceptHeaderMatcher.php @@ -9,7 +9,7 @@ use Drupal\Component\Utility\String; use Drupal\Core\ContentNegotiation; -use Symfony\Cmf\Component\Routing\NestedMatcher\RouteFilterInterface; +use Drupal\Core\Routing\RouteFilterInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException; use Symfony\Component\Routing\RouteCollection; diff --git a/core/lib/Drupal/Core/Routing/ContentTypeHeaderMatcher.php b/core/lib/Drupal/Core/Routing/ContentTypeHeaderMatcher.php index c76036d..8940ad6 100644 --- a/core/lib/Drupal/Core/Routing/ContentTypeHeaderMatcher.php +++ b/core/lib/Drupal/Core/Routing/ContentTypeHeaderMatcher.php @@ -7,7 +7,7 @@ namespace Drupal\Core\Routing; -use Symfony\Cmf\Component\Routing\NestedMatcher\RouteFilterInterface; +use Drupal\Core\Routing\RouteFilterInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException; use Symfony\Component\Routing\RouteCollection; diff --git a/core/lib/Drupal/Core/Routing/Enhancer/AuthenticationEnhancer.php b/core/lib/Drupal/Core/Routing/Enhancer/AuthenticationEnhancer.php index 5a7e8a0..5e4b478 100644 --- a/core/lib/Drupal/Core/Routing/Enhancer/AuthenticationEnhancer.php +++ b/core/lib/Drupal/Core/Routing/Enhancer/AuthenticationEnhancer.php @@ -12,6 +12,7 @@ use Drupal\Core\Session\AccountProxyInterface; use Drupal\Core\Session\AnonymousUserSession; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\Routing\Route; use Symfony\Cmf\Component\Routing\RouteObjectInterface; /** @@ -75,4 +76,12 @@ public function enhance(array $defaults, Request $request) { } return $defaults; } + + /** + * {@inheritdoc} + */ + public function applies(Route $route) { + return TRUE; + } + } diff --git a/core/lib/Drupal/Core/Routing/Enhancer/ParamConversionEnhancer.php b/core/lib/Drupal/Core/Routing/Enhancer/ParamConversionEnhancer.php index 0dcf07d..19f796f 100644 --- a/core/lib/Drupal/Core/Routing/Enhancer/ParamConversionEnhancer.php +++ b/core/lib/Drupal/Core/Routing/Enhancer/ParamConversionEnhancer.php @@ -17,6 +17,7 @@ use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\KernelEvents; +use Symfony\Component\Routing\Route; /** * Provides a route enhancer that handles parameter conversion. @@ -91,15 +92,9 @@ public static function getSubscribedEvents() { } /** - * Determines if enhancers apply to a route. - * - * @param \Symfony\Component\Routing\Route $route - * The route to consider attaching to. - * - * @return bool - * TRUE if the check applies to the passed route, False otherwise. + * {@inheritdoc} */ - protected function applies(Route $route) { - return True; + public function applies(Route $route) { + return $route->hasOption('parameters'); } } diff --git a/core/lib/Drupal/Core/Routing/LazyRouteEnhancer.php b/core/lib/Drupal/Core/Routing/LazyRouteEnhancer.php index fc90087..2e46d52 100644 --- a/core/lib/Drupal/Core/Routing/LazyRouteEnhancer.php +++ b/core/lib/Drupal/Core/Routing/LazyRouteEnhancer.php @@ -15,7 +15,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\RouteCollection; -class LazyRouteEnhancer implements BaseRouteEnhancerInterface, ContainerAwareInterface{ +class LazyRouteEnhancer implements BaseRouteEnhancerInterface, ContainerAwareInterface { use ContainerAwareTrait; @@ -63,6 +63,8 @@ public function setEnhancers(RouteCollection $route_collection) { } /** + * For each route, gets a list of applicable enhancer to the route. + * * @return \Symfony\Cmf\Component\Routing\Enhancer\RouteEnhancerInterface[]|\Drupal\Core\Routing\Enhancer\RouteEnhancerInterface[] */ protected function getEnhancers() { @@ -90,29 +92,4 @@ public function enhance(array $defaults, Request $request) { } } - /** - * Determines if enhancers apply to a route. - * - * @param \Symfony\Component\Routing\Route $route - * The route to consider attaching to. - * - * @return bool - * TRUE if the check applies to the passed route, False otherwise. - */ - protected function applies(Route $route) { - $enhancer = array(); - - foreach ($this->serviceIds[$enhancer] as $service_id) { - if (empty($this->$enhancer[$service_id])) { - $this->loadCheck($service_id); - } - - if ($this->$enhancer[$service_id]->applies($route)) { - $enhancer = $service_id; - } - } - - return $enhancer; - } - } diff --git a/core/lib/Drupal/Core/Routing/LazyRouteFilter.php b/core/lib/Drupal/Core/Routing/LazyRouteFilter.php new file mode 100644 index 0000000..f0a3e5b --- /dev/null +++ b/core/lib/Drupal/Core/Routing/LazyRouteFilter.php @@ -0,0 +1,98 @@ +serviceIds[$filter] = $filter; + + return $this; + } + + /** + * For each route, filter down the route collection. + * + * @param \Symfony\Component\Routing\RouteCollection $route_collection + * A collection of routes to apply filter checks to. + */ + + public function setFilters(RouteCollection $route_collection) { + /** @var \Symfony\Component\Routing\Route $route **/ + foreach ($route_collection as $route) { + $service_ids = []; + foreach ($this->getFilters() as $service_id => $filter) { + if ($filter instanceof RouteFilterInterface && $filter->applies($route)) { + $service_ids[] = $service_id; + } + } + if ($service_ids) { + $route->setOption('_route_filters', array_unique($service_ids)); + } + } + } + + /** + * For each route, gets a list of applicable enhancer to the route. + * + * @return \Symfony\Cmf\Component\Routing\Enhancer\RouteEnhancerInterface[]|\Drupal\Core\Routing\Enhancer\RouteEnhancerInterface[] + */ + protected function getFilters() { + if (!isset($this->filters)) { + foreach ($this->serviceIds as $service_id) { + $this->filters[$service_id] = $this->container->get($service_id); + } + } + return $this->filters; + } + + /** + * {@inheritdoc} + */ + public function filter(array $defaults, Request $request) { + /** @var \Symfony\Component\Routing\Route $route */ + $route = $request->attributes->get(RouteObjectInterface::ROUTE_OBJECT); + + $filter_ids = $route->getOption('_route_enhancers'); + + if (isset($filter_ids)) { + foreach ($filter_ids as $filter_id) { + $this->container->get($filter_id)->filter($defaults, $request); + } + } + } + +} + diff --git a/core/lib/Drupal/Core/Routing/RouteFilterInterface.php b/core/lib/Drupal/Core/Routing/RouteFilterInterface.php new file mode 100644 index 0000000..537316d --- /dev/null +++ b/core/lib/Drupal/Core/Routing/RouteFilterInterface.php @@ -0,0 +1,29 @@ +