3 namespace Drupal\Core\RouteProcessor;
5 use Drupal\Core\Render\BubbleableMetadata;
6 use Symfony\Component\Routing\Route;
9 * Route processor manager.
11 * Holds an array of route processor objects and uses them to sequentially
12 * process an outbound route, in order of processor priority.
14 class RouteProcessorManager implements OutboundRouteProcessorInterface {
17 * Holds the array of outbound processors to cycle through.
20 * An array whose keys are priorities and whose values are arrays of path
23 protected $outboundProcessors = [];
26 * Holds the array of outbound processors, sorted by priority.
29 * An array of path processor objects.
31 protected $sortedOutbound = [];
34 * Adds an outbound processor object to the $outboundProcessors property.
36 * @param \Drupal\Core\RouteProcessor\OutboundRouteProcessorInterface $processor
37 * The processor object to add.
38 * @param int $priority
39 * The priority of the processor being added.
41 public function addOutbound(OutboundRouteProcessorInterface $processor, $priority = 0) {
42 $this->outboundProcessors[$priority][] = $processor;
43 $this->sortedOutbound = [];
49 public function processOutbound($route_name, Route $route, array &$parameters, BubbleableMetadata $bubbleable_metadata = NULL) {
50 $processors = $this->getOutbound();
51 foreach ($processors as $processor) {
52 $processor->processOutbound($route_name, $route, $parameters, $bubbleable_metadata);
57 * Returns the sorted array of outbound processors.
60 * An array of processor objects.
62 protected function getOutbound() {
63 if (empty($this->sortedOutbound)) {
64 $this->sortedOutbound = $this->sortProcessors();
67 return $this->sortedOutbound;
71 * Sorts the processors according to priority.
73 protected function sortProcessors() {
75 krsort($this->outboundProcessors);
77 foreach ($this->outboundProcessors as $processors) {
78 $sorted = array_merge($sorted, $processors);