You are here

class RequestContext in Drupal 9

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

Holds information about the current request.

Hierarchy

  • class \Drupal\Core\Routing\RequestContext extends \Symfony\Component\Routing\RequestContext

Expanded class hierarchy of RequestContext

10 files declare their use of RequestContext
IFrameUrlHelper.php in core/modules/media/src/IFrameUrlHelper.php
IFrameUrlHelperTest.php in core/modules/media/tests/src/Unit/IFrameUrlHelperTest.php
PathBasedBreadcrumbBuilder.php in core/modules/system/src/PathBasedBreadcrumbBuilder.php
PathValidator.php in core/lib/Drupal/Core/Path/PathValidator.php
PathValidatorTest.php in core/tests/Drupal/KernelTests/Core/Path/PathValidatorTest.php

... See full list

1 string reference to 'RequestContext'
core.services.yml in core/core.services.yml
core/core.services.yml
1 service uses RequestContext
router.request_context in core/core.services.yml
Drupal\Core\Routing\RequestContext

File

core/lib/Drupal/Core/Routing/RequestContext.php, line 12

Namespace

Drupal\Core\Routing
View source
class RequestContext extends SymfonyRequestContext {

  /**
   * The scheme, host and base path, for example "http://example.com/d8".
   *
   * @var string
   */
  protected $completeBaseUrl;

  /**
   * Populates the context from the current request from the request stack.
   *
   * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
   *   The current request stack.
   */
  public function fromRequestStack(RequestStack $request_stack) {
    $this
      ->fromRequest($request_stack
      ->getCurrentRequest());
  }

  /**
   * {@inheritdoc}
   */
  public function fromRequest(Request $request) {
    parent::fromRequest($request);

    // @todo Extract the code in DrupalKernel::initializeRequestGlobals.
    //   See https://www.drupal.org/node/2404601
    if (isset($GLOBALS['base_url'])) {
      $this
        ->setCompleteBaseUrl($GLOBALS['base_url']);
    }
  }

  /**
   * Gets the scheme, host and base path.
   *
   * For example, in an installation in a subdirectory "d8", it should be
   * "https://example.com/d8".
   */
  public function getCompleteBaseUrl() {
    return $this->completeBaseUrl;
  }

  /**
   * Sets the complete base URL for the Request context.
   *
   * @param string $complete_base_url
   *   The complete base URL.
   */
  public function setCompleteBaseUrl($complete_base_url) {
    $this->completeBaseUrl = $complete_base_url;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RequestContext::$completeBaseUrl protected property The scheme, host and base path, for example "http://example.com/d8".
RequestContext::fromRequest public function
RequestContext::fromRequestStack public function Populates the context from the current request from the request stack.
RequestContext::getCompleteBaseUrl public function Gets the scheme, host and base path.
RequestContext::setCompleteBaseUrl public function Sets the complete base URL for the Request context.