Same name and namespace in other branches
- 8.9.x core/lib/Drupal/Core/Routing/TrustedRedirectResponse.php \Drupal\Core\Routing\TrustedRedirectResponse
- 9 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\Core\Routing\CacheableSecuredRedirectResponse extends \Drupal\Component\HttpFoundation\SecuredRedirectResponse implements CacheableResponseInterface uses CacheableResponseTrait
- class \Drupal\Core\Routing\TrustedRedirectResponse uses LocalAwareRedirectResponseTrait
Expanded class hierarchy of TrustedRedirectResponse
3 files declare their use of TrustedRedirectResponse
- Cookie.php in core/
modules/ user/ src/ Authentication/ Provider/ Cookie.php - TrustedRedirectResponseTest.php in core/
tests/ Drupal/ Tests/ Core/ Routing/ TrustedRedirectResponseTest.php - UserAuthTest.php in core/
modules/ user/ tests/ src/ Unit/ UserAuthTest.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);
}
}