class TrustedRedirectResponse in Drupal 8
Same name and namespace in other branches
- 9 core/lib/Drupal/Core/Routing/TrustedRedirectResponse.php \Drupal\Core\Routing\TrustedRedirectResponse
- 10 core/lib/Drupal/Core/Routing/TrustedRedirectResponse.php \Drupal\Core\Routing\TrustedRedirectResponse
Provides a redirect response which contains trusted URLs.
Use this class in case you know that you want to redirect to an external URL.
Hierarchy
- class \Drupal\Component\HttpFoundation\SecuredRedirectResponse extends \Symfony\Component\HttpFoundation\RedirectResponse
- class \Drupal\Core\Routing\CacheableSecuredRedirectResponse implements CacheableResponseInterface uses CacheableResponseTrait
- class \Drupal\Core\Routing\TrustedRedirectResponse uses LocalAwareRedirectResponseTrait
- class \Drupal\Core\Routing\CacheableSecuredRedirectResponse implements CacheableResponseInterface uses CacheableResponseTrait
Expanded class hierarchy of TrustedRedirectResponse
2 files declare their use of TrustedRedirectResponse
- RedirectResponseSubscriberTest.php in core/
tests/ Drupal/ Tests/ Core/ EventSubscriber/ RedirectResponseSubscriberTest.php - TrustedRedirectResponseTest.php in core/
tests/ Drupal/ Tests/ Core/ Routing/ TrustedRedirectResponseTest.php
File
- core/
lib/ Drupal/ Core/ Routing/ TrustedRedirectResponse.php, line 10
Namespace
Drupal\Core\RoutingView source
class TrustedRedirectResponse extends CacheableSecuredRedirectResponse {
use LocalAwareRedirectResponseTrait;
/**
* A list of trusted URLs, which are safe to redirect to.
*
* @var string[]
*/
protected $trustedUrls = [];
/**
* {@inheritdoc}
*/
public function __construct($url, $status = 302, $headers = []) {
$this->trustedUrls[$url] = TRUE;
parent::__construct($url, $status, $headers);
}
/**
* Sets the target URL to a trusted URL.
*
* @param string $url
* A trusted URL.
*
* @return $this
*/
public function setTrustedTargetUrl($url) {
$this->trustedUrls[$url] = TRUE;
return $this
->setTargetUrl($url);
}
/**
* {@inheritdoc}
*/
protected function isSafe($url) {
return !empty($this->trustedUrls[$url]) || $this
->isLocal($url);
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CacheableResponseTrait:: |
protected | property | The cacheability metadata. | |
CacheableResponseTrait:: |
public | function | ||
CacheableResponseTrait:: |
public | function | ||
CacheableSecuredRedirectResponse:: |
protected | function |
Copies over the values from the given response. Overrides SecuredRedirectResponse:: |
|
LocalAwareRedirectResponseTrait:: |
protected | property | The request context. | |
LocalAwareRedirectResponseTrait:: |
protected | function | Returns the request context. | |
LocalAwareRedirectResponseTrait:: |
protected | function | Determines whether a path is local. | |
LocalAwareRedirectResponseTrait:: |
public | function | Sets the request context. | |
SecuredRedirectResponse:: |
public static | function | Copies an existing redirect response into a safe one. | |
SecuredRedirectResponse:: |
public | function | Sets the redirect target of this response. | |
TrustedRedirectResponse:: |
protected | property | A list of trusted URLs, which are safe to redirect to. | |
TrustedRedirectResponse:: |
protected | function |
Returns whether the URL is considered as safe to redirect to. Overrides SecuredRedirectResponse:: |
|
TrustedRedirectResponse:: |
public | function | Sets the target URL to a trusted URL. | |
TrustedRedirectResponse:: |
public | function | Creates a redirect response so that it conforms to the rules defined for a redirect status code. |