CacheableSecuredRedirectResponse.php

Same filename in other branches
  1. 8.9.x core/lib/Drupal/Core/Routing/CacheableSecuredRedirectResponse.php
  2. 10 core/lib/Drupal/Core/Routing/CacheableSecuredRedirectResponse.php
  3. 11.x core/lib/Drupal/Core/Routing/CacheableSecuredRedirectResponse.php

Namespace

Drupal\Core\Routing

File

core/lib/Drupal/Core/Routing/CacheableSecuredRedirectResponse.php

View source
<?php

namespace Drupal\Core\Routing;

use Drupal\Component\HttpFoundation\SecuredRedirectResponse;
use Drupal\Core\Cache\CacheableResponseInterface;
use Drupal\Core\Cache\CacheableResponseTrait;
use Symfony\Component\HttpFoundation\RedirectResponse;

/**
 * Provides a common base class for cacheable safe redirects.
 */
abstract class CacheableSecuredRedirectResponse extends SecuredRedirectResponse implements CacheableResponseInterface {
    use CacheableResponseTrait;
    
    /**
     * {@inheritdoc}
     */
    protected function fromResponse(RedirectResponse $response) {
        parent::fromResponse($response);
        $metadata = $this->getCacheableMetadata();
        if ($response instanceof CacheableResponseInterface) {
            $metadata->addCacheableDependency($response->getCacheableMetadata());
        }
        else {
            $metadata->setCacheMaxAge(0);
        }
    }

}

Classes

Title Deprecated Summary
CacheableSecuredRedirectResponse Provides a common base class for cacheable safe redirects.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.