You are here

public function NeedsRedirectException::__construct in Commerce Core 8.2

Constructs a new NeedsRedirectException object.

Parameters

string $url: The URL to redirect to.

int $status_code: The redirect status code.

string[] $headers: Headers to pass with the redirect.

Overrides EnforcedResponseException::__construct

File

src/Response/NeedsRedirectException.php, line 27

Class

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

Namespace

Drupal\commerce\Response

Code

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);
}