class TrustedRedirectResponse
Same name in other branches
- 9 core/lib/Drupal/Core/Routing/TrustedRedirectResponse.php \Drupal\Core\Routing\TrustedRedirectResponse
- 8.9.x core/lib/Drupal/Core/Routing/TrustedRedirectResponse.php \Drupal\Core\Routing\TrustedRedirectResponse
- 11.x 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 extends \Drupal\Component\HttpFoundation\SecuredRedirectResponse implements \Drupal\Core\Cache\CacheableResponseInterface uses \Drupal\Core\Cache\CacheableResponseTrait
- class \Drupal\Core\Routing\TrustedRedirectResponse extends \Drupal\Core\Routing\CacheableSecuredRedirectResponse uses \Drupal\Core\Routing\LocalAwareRedirectResponseTrait
- class \Drupal\Core\Routing\CacheableSecuredRedirectResponse extends \Drupal\Component\HttpFoundation\SecuredRedirectResponse implements \Drupal\Core\Cache\CacheableResponseInterface uses \Drupal\Core\Cache\CacheableResponseTrait
Expanded class hierarchy of TrustedRedirectResponse
5 files declare their use of TrustedRedirectResponse
- Cookie.php in core/
modules/ user/ src/ Authentication/ Provider/ Cookie.php - RedirectResponseSubscriberTest.php in core/
tests/ Drupal/ Tests/ Core/ EventSubscriber/ RedirectResponseSubscriberTest.php - SystemTestController.php in core/
modules/ system/ tests/ modules/ system_test/ src/ Controller/ SystemTestController.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);
}
}
Members
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.