You are here

class NeedsRedirectException in Commerce Core 8.2

Provides an exception that represents the need for an HTTP redirect.

Allows nested forms to perform HTTP redirects in an easy way.

Hierarchy

Expanded class hierarchy of NeedsRedirectException

4 files declare their use of NeedsRedirectException
CheckoutFlowBase.php in modules/checkout/src/Plugin/Commerce/CheckoutFlow/CheckoutFlowBase.php
PaymentCheckoutController.php in modules/payment/src/Controller/PaymentCheckoutController.php
PaymentOffsiteForm.php in modules/payment/src/PluginForm/PaymentOffsiteForm.php
RedirectForm.php in tests/modules/commerce_test/src/Form/RedirectForm.php

File

src/Response/NeedsRedirectException.php, line 15

Namespace

Drupal\commerce\Response
View source
class NeedsRedirectException extends EnforcedResponseException {

  /**
   * Constructs a new NeedsRedirectException object.
   *
   * @param string $url
   *   The URL to redirect to.
   * @param int $status_code
   *   The redirect status code.
   * @param string[] $headers
   *   Headers to pass with the redirect.
   */
  public function __construct(string $url, int $status_code = 302, array $headers = []) {
    if (!UrlHelper::isValid($url)) {
      throw new \InvalidArgumentException('Invalid URL provided.');
    }
    $response = new TrustedRedirectResponse($url, $status_code, $headers);
    $cacheable_metadata = new CacheableMetadata();
    $cacheable_metadata
      ->setCacheMaxAge(0);
    $response
      ->addCacheableDependency($cacheable_metadata);
    parent::__construct($response);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EnforcedResponseException::$response protected property The response to be enforced.
EnforcedResponseException::getResponse public function Return the response to be enforced.
NeedsRedirectException::__construct public function Constructs a new NeedsRedirectException object. Overrides EnforcedResponseException::__construct