class RouteProcessorManager

Same name in other branches
  1. 9 core/lib/Drupal/Core/RouteProcessor/RouteProcessorManager.php \Drupal\Core\RouteProcessor\RouteProcessorManager
  2. 10 core/lib/Drupal/Core/RouteProcessor/RouteProcessorManager.php \Drupal\Core\RouteProcessor\RouteProcessorManager
  3. 11.x core/lib/Drupal/Core/RouteProcessor/RouteProcessorManager.php \Drupal\Core\RouteProcessor\RouteProcessorManager

Route processor manager.

Holds an array of route processor objects and uses them to sequentially process an outbound route, in order of processor priority.

Hierarchy

Expanded class hierarchy of RouteProcessorManager

1 file declares its use of RouteProcessorManager
RouteProcessorManagerTest.php in core/tests/Drupal/Tests/Core/RouteProcessor/RouteProcessorManagerTest.php
1 string reference to 'RouteProcessorManager'
core.services.yml in core/core.services.yml
core/core.services.yml
1 service uses RouteProcessorManager
route_processor_manager in core/core.services.yml
Drupal\Core\RouteProcessor\RouteProcessorManager

File

core/lib/Drupal/Core/RouteProcessor/RouteProcessorManager.php, line 14

Namespace

Drupal\Core\RouteProcessor
View source
class RouteProcessorManager implements OutboundRouteProcessorInterface {
    
    /**
     * Holds the array of outbound processors to cycle through.
     *
     * @var array
     *   An array whose keys are priorities and whose values are arrays of path
     *   processor objects.
     */
    protected $outboundProcessors = [];
    
    /**
     * Holds the array of outbound processors, sorted by priority.
     *
     * @var array
     *   An array of path processor objects.
     */
    protected $sortedOutbound = [];
    
    /**
     * Adds an outbound processor object to the $outboundProcessors property.
     *
     * @param \Drupal\Core\RouteProcessor\OutboundRouteProcessorInterface $processor
     *   The processor object to add.
     * @param int $priority
     *   The priority of the processor being added.
     */
    public function addOutbound(OutboundRouteProcessorInterface $processor, $priority = 0) {
        $this->outboundProcessors[$priority][] = $processor;
        $this->sortedOutbound = [];
    }
    
    /**
     * {@inheritdoc}
     */
    public function processOutbound($route_name, Route $route, array &$parameters, BubbleableMetadata $bubbleable_metadata = NULL) {
        $processors = $this->getOutbound();
        foreach ($processors as $processor) {
            $processor->processOutbound($route_name, $route, $parameters, $bubbleable_metadata);
        }
    }
    
    /**
     * Returns the sorted array of outbound processors.
     *
     * @return array
     *   An array of processor objects.
     */
    protected function getOutbound() {
        if (empty($this->sortedOutbound)) {
            $this->sortedOutbound = $this->sortProcessors();
        }
        return $this->sortedOutbound;
    }
    
    /**
     * Sorts the processors according to priority.
     */
    protected function sortProcessors() {
        $sorted = [];
        krsort($this->outboundProcessors);
        foreach ($this->outboundProcessors as $processors) {
            $sorted = array_merge($sorted, $processors);
        }
        return $sorted;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
RouteProcessorManager::$outboundProcessors protected property Holds the array of outbound processors to cycle through.
RouteProcessorManager::$sortedOutbound protected property Holds the array of outbound processors, sorted by priority.
RouteProcessorManager::addOutbound public function Adds an outbound processor object to the $outboundProcessors property.
RouteProcessorManager::getOutbound protected function Returns the sorted array of outbound processors.
RouteProcessorManager::processOutbound public function Processes the outbound route. Overrides OutboundRouteProcessorInterface::processOutbound
RouteProcessorManager::sortProcessors protected function Sorts the processors according to priority.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.