You are here

class PathProcessorManager in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/PathProcessor/PathProcessorManager.php \Drupal\Core\PathProcessor\PathProcessorManager

Path processor manager.

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

Hierarchy

Expanded class hierarchy of PathProcessorManager

3 files declare their use of PathProcessorManager
LanguageNegotiationUserAdmin.php in core/modules/user/src/Plugin/LanguageNegotiation/LanguageNegotiationUserAdmin.php
Contains \Drupal\user\Plugin\LanguageNegotiation\LanguageNegotiationUserAdmin.
PathProcessorTest.php in core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php
Contains \Drupal\Tests\Core\PathProcessor\PathProcessorTest.
UrlGeneratorTest.php in core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php
Contains \Drupal\Tests\Core\Routing\UrlGeneratorTest.
1 string reference to 'PathProcessorManager'
core.services.yml in core/core.services.yml
core/core.services.yml
1 service uses PathProcessorManager
path_processor_manager in core/core.services.yml
Drupal\Core\PathProcessor\PathProcessorManager

File

core/lib/Drupal/Core/PathProcessor/PathProcessorManager.php, line 19
Contains \Drupal\Core\PathProcessor\PathProcessorManager.

Namespace

Drupal\Core\PathProcessor
View source
class PathProcessorManager implements InboundPathProcessorInterface, OutboundPathProcessorInterface {

  /**
   * Holds the array of inbound processors to cycle through.
   *
   * @var array
   *   An array whose keys are priorities and whose values are arrays of path
   *   processor objects.
   */
  protected $inboundProcessors = array();

  /**
   * Holds the array of inbound processors, sorted by priority.
   *
   * @var array
   *   An array of path processor objects.
   */
  protected $sortedInbound = array();

  /**
   * 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 = array();

  /**
   * Holds the array of outbound processors, sorted by priority.
   *
   * @var array
   *   An array of path processor objects.
   */
  protected $sortedOutbound = array();

  /**
   * Adds an inbound processor object to the $inboundProcessors property.
   *
   * @param \Drupal\Core\PathProcessor\InboundPathProcessorInterface $processor
   *   The processor object to add.
   * @param int $priority
   *   The priority of the processor being added.
   */
  public function addInbound(InboundPathProcessorInterface $processor, $priority = 0) {
    $this->inboundProcessors[$priority][] = $processor;
    $this->sortedInbound = array();
  }

  /**
   * {@inheritdoc}
   */
  public function processInbound($path, Request $request) {
    $processors = $this
      ->getInbound();
    foreach ($processors as $processor) {
      $path = $processor
        ->processInbound($path, $request);
    }
    return $path;
  }

  /**
   * Returns the sorted array of inbound processors.
   *
   * @return array
   *   An array of processor objects.
   */
  protected function getInbound() {
    if (empty($this->sortedInbound)) {
      $this->sortedInbound = $this
        ->sortProcessors('inboundProcessors');
    }
    return $this->sortedInbound;
  }

  /**
   * Adds an outbound processor object to the $outboundProcessors property.
   *
   * @param \Drupal\Core\PathProcessor\OutboundPathProcessorInterface $processor
   *   The processor object to add.
   * @param int $priority
   *   The priority of the processor being added.
   */
  public function addOutbound(OutboundPathProcessorInterface $processor, $priority = 0) {
    $this->outboundProcessors[$priority][] = $processor;
    $this->sortedOutbound = array();
  }

  /**
   * {@inheritdoc}
   */
  public function processOutbound($path, &$options = array(), Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL) {
    $processors = $this
      ->getOutbound();
    foreach ($processors as $processor) {
      $path = $processor
        ->processOutbound($path, $options, $request, $bubbleable_metadata);
    }
    return $path;
  }

  /**
   * 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('outboundProcessors');
    }
    return $this->sortedOutbound;
  }

  /**
   * Sorts the processors according to priority.
   *
   * @param string $type
   *   The processor type to sort, e.g. 'inboundProcessors'.
   */
  protected function sortProcessors($type) {
    $sorted = array();
    krsort($this->{$type});
    foreach ($this->{$type} as $processors) {
      $sorted = array_merge($sorted, $processors);
    }
    return $sorted;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PathProcessorManager::$inboundProcessors protected property Holds the array of inbound processors to cycle through.
PathProcessorManager::$outboundProcessors protected property Holds the array of outbound processors to cycle through.
PathProcessorManager::$sortedInbound protected property Holds the array of inbound processors, sorted by priority.
PathProcessorManager::$sortedOutbound protected property Holds the array of outbound processors, sorted by priority.
PathProcessorManager::addInbound public function Adds an inbound processor object to the $inboundProcessors property.
PathProcessorManager::addOutbound public function Adds an outbound processor object to the $outboundProcessors property.
PathProcessorManager::getInbound protected function Returns the sorted array of inbound processors.
PathProcessorManager::getOutbound protected function Returns the sorted array of outbound processors.
PathProcessorManager::processInbound public function Processes the inbound path. Overrides InboundPathProcessorInterface::processInbound
PathProcessorManager::processOutbound public function Processes the outbound path. Overrides OutboundPathProcessorInterface::processOutbound
PathProcessorManager::sortProcessors protected function Sorts the processors according to priority.