You are here

class CurrentPathStack in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Path/CurrentPathStack.php \Drupal\Core\Path\CurrentPathStack

Represents the current path for the current request.

Note: You should not rely on paths but rather on route names / parameters or other indicators like context. For some fundamental parts, like routing or path processing, there is unfortunately no way around dealing with paths.

Hierarchy

Expanded class hierarchy of CurrentPathStack

11 files declare their use of CurrentPathStack
ActiveLinkResponseFilter.php in core/lib/Drupal/Core/EventSubscriber/ActiveLinkResponseFilter.php
Contains \Drupal\Core\EventSubscriber\ActiveLinkResponseFilter.
PathBasedBreadcrumbBuilder.php in core/modules/system/src/PathBasedBreadcrumbBuilder.php
Contains \Drupal\system\PathBasedBreadcrumbBuilder.
PathSubscriber.php in core/lib/Drupal/Core/EventSubscriber/PathSubscriber.php
Contains \Drupal\Core\EventSubscriber\PathSubscriber.
Raw.php in core/modules/views/src/Plugin/views/argument_default/Raw.php
Contains \Drupal\views\Plugin\views\argument_default\Raw.
RawTest.php in core/modules/views/tests/src/Unit/Plugin/argument_default/RawTest.php
Contains \Drupal\Tests\views\Unit\Plugin\argument_default\RawTest.

... See full list

1 string reference to 'CurrentPathStack'
core.services.yml in core/core.services.yml
core/core.services.yml
1 service uses CurrentPathStack
path.current in core/core.services.yml
Drupal\Core\Path\CurrentPathStack

File

core/lib/Drupal/Core/Path/CurrentPathStack.php, line 18
Contains \Drupal\Core\Path\CurrentPathStack.

Namespace

Drupal\Core\Path
View source
class CurrentPathStack {

  /**
   * Static cache of paths.
   *
   * @var \SplObjectStorage
   */
  protected $paths;

  /**
   * The request stack.
   *
   * @var \Symfony\Component\HttpFoundation\RequestStack
   */
  protected $requestStack;

  /**
   * Constructs a new CurrentPathStack instance.
   *
   * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
   *   The request stack.
   */
  public function __construct(RequestStack $request_stack) {
    $this->requestStack = $request_stack;
    $this->paths = new \SplObjectStorage();
  }

  /**
   * Returns the path of the current request.
   *
   * @param \Symfony\Component\HttpFoundation\Request $request
   *   (optional) The request.
   *
   * @return string
   *   Returns the path, without leading slashes.
   */
  public function getPath($request = NULL) {
    if (!isset($request)) {
      $request = $this->requestStack
        ->getCurrentRequest();
    }
    if (!isset($this->paths[$request])) {
      $this->paths[$request] = $request
        ->getPathInfo();
    }
    return $this->paths[$request];
  }

  /**
   * Sets the current path.
   *
   * @param string $path
   *   The path.
   * @param \Symfony\Component\HttpFoundation\Request $request
   *   (optional) The request.
   *
   * @return $this
   */
  public function setPath($path, $request = NULL) {
    if (!isset($request)) {
      $request = $this->requestStack
        ->getCurrentRequest();
    }
    $this->paths[$request] = $path;
    return $this;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CurrentPathStack::$paths protected property Static cache of paths.
CurrentPathStack::$requestStack protected property The request stack.
CurrentPathStack::getPath public function Returns the path of the current request.
CurrentPathStack::setPath public function Sets the current path.
CurrentPathStack::__construct public function Constructs a new CurrentPathStack instance.