You are here

class RequestStack in Service Container 7.2

Same name and namespace in other branches
  1. 7 lib/Symfony/Component/HttpFoundation/RequestStack.php \Symfony\Component\HttpFoundation\RequestStack

Request stack that controls the lifecycle of requests.

@author Benjamin Eberlei <kontakt@beberlei.de>

Hierarchy

Expanded class hierarchy of RequestStack

2 files declare their use of RequestStack
LoggerChannel.php in src/Logger/LoggerChannel.php
Contains \Drupal\service_container\Logger\LoggerChannel.
LoggerChannelInterface.php in lib/Drupal/Core/Logger/LoggerChannelInterface.php
Contains \Drupal\Core\Logger\LoggerChannelInterface.

File

lib/Symfony/Component/HttpFoundation/RequestStack.php, line 19

Namespace

Symfony\Component\HttpFoundation
View source
class RequestStack {

  /**
   * @var Request[]
   */
  private $requests = array();

  /**
   * Pushes a Request on the stack.
   *
   * This method should generally not be called directly as the stack
   * management should be taken care of by the application itself.
   */
  public function push(Request $request) {
    $this->requests[] = $request;
  }

  /**
   * Pops the current request from the stack.
   *
   * This operation lets the current request go out of scope.
   *
   * This method should generally not be called directly as the stack
   * management should be taken care of by the application itself.
   *
   * @return Request|null
   */
  public function pop() {
    if (!$this->requests) {
      return;
    }
    return array_pop($this->requests);
  }

  /**
   * @return Request|null
   */
  public function getCurrentRequest() {
    return end($this->requests) ?: null;
  }

  /**
   * Gets the master Request.
   *
   * Be warned that making your code aware of the master request
   * might make it un-compatible with other features of your framework
   * like ESI support.
   *
   * @return Request|null
   */
  public function getMasterRequest() {
    if (!$this->requests) {
      return;
    }
    return $this->requests[0];
  }

  /**
   * Returns the parent request of the current.
   *
   * Be warned that making your code aware of the parent request
   * might make it un-compatible with other features of your framework
   * like ESI support.
   *
   * If current Request is the master request, it returns null.
   *
   * @return Request|null
   */
  public function getParentRequest() {
    $pos = count($this->requests) - 2;
    if (!isset($this->requests[$pos])) {
      return;
    }
    return $this->requests[$pos];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RequestStack::$requests private property
RequestStack::getCurrentRequest public function
RequestStack::getMasterRequest public function Gets the master Request.
RequestStack::getParentRequest public function Returns the parent request of the current.
RequestStack::pop public function Pops the current request from the stack.
RequestStack::push public function Pushes a Request on the stack.