CacheableSecuredRedirectResponse.php 855 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. namespace Drupal\Core\Routing;
  3. use Drupal\Component\HttpFoundation\SecuredRedirectResponse;
  4. use Drupal\Core\Cache\CacheableResponseInterface;
  5. use Drupal\Core\Cache\CacheableResponseTrait;
  6. use Symfony\Component\HttpFoundation\RedirectResponse;
  7. /**
  8. * Provides a common base class for cacheable safe redirects.
  9. */
  10. abstract class CacheableSecuredRedirectResponse extends SecuredRedirectResponse implements CacheableResponseInterface {
  11. use CacheableResponseTrait;
  12. /**
  13. * {@inheritdoc}
  14. */
  15. protected function fromResponse(RedirectResponse $response) {
  16. parent::fromResponse($response);
  17. $metadata = $this->getCacheableMetadata();
  18. if ($response instanceof CacheableResponseInterface) {
  19. $metadata->addCacheableDependency($response->getCacheableMetadata());
  20. }
  21. else {
  22. $metadata->setCacheMaxAge(0);
  23. }
  24. }
  25. }