vendor/friendsofsymfony/http-cache/src/ProxyClient/Symfony.php line 59

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the FOSHttpCache package.
  4.  *
  5.  * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace FOS\HttpCache\ProxyClient;
  11. use FOS\HttpCache\ProxyClient\Invalidation\ClearCapable;
  12. use FOS\HttpCache\ProxyClient\Invalidation\PurgeCapable;
  13. use FOS\HttpCache\ProxyClient\Invalidation\RefreshCapable;
  14. use FOS\HttpCache\ProxyClient\Invalidation\TagCapable;
  15. use FOS\HttpCache\SymfonyCache\PurgeListener;
  16. use FOS\HttpCache\SymfonyCache\PurgeTagsListener;
  17. /**
  18.  * Symfony HttpCache invalidator.
  19.  *
  20.  * Additional constructor options:
  21.  * - purge_method:         HTTP method that identifies purge requests.
  22.  *
  23.  * @author David de Boer <david@driebit.nl>
  24.  * @author David Buchmann <mail@davidbu.ch>
  25.  */
  26. class Symfony extends HttpProxyClient implements PurgeCapableRefreshCapableTagCapableClearCapable
  27. {
  28.     public const HTTP_METHOD_REFRESH 'GET';
  29.     /**
  30.      * {@inheritdoc}
  31.      */
  32.     public function purge($url, array $headers = [])
  33.     {
  34.         $this->queueRequest($this->options['purge_method'], $url$headers);
  35.         return $this;
  36.     }
  37.     /**
  38.      * {@inheritdoc}
  39.      */
  40.     public function refresh($url, array $headers = [])
  41.     {
  42.         $headers array_merge($headers, ['Cache-Control' => 'no-cache']);
  43.         $this->queueRequest(self::HTTP_METHOD_REFRESH$url$headers);
  44.         return $this;
  45.     }
  46.     protected function configureOptions()
  47.     {
  48.         $resolver parent::configureOptions();
  49.         $resolver->setDefaults([
  50.             'purge_method' => PurgeListener::DEFAULT_PURGE_METHOD,
  51.             'clear_cache_header' => PurgeListener::DEFAULT_CLEAR_CACHE_HEADER,
  52.             'tags_method' => PurgeTagsListener::DEFAULT_TAGS_METHOD,
  53.             'tags_header' => PurgeTagsListener::DEFAULT_TAGS_HEADER,
  54.             'tags_invalidate_path' => '/',
  55.             'header_length' => 7500,
  56.         ]);
  57.         $resolver->setAllowedTypes('purge_method''string');
  58.         $resolver->setAllowedTypes('clear_cache_header''string');
  59.         $resolver->setAllowedTypes('tags_method''string');
  60.         $resolver->setAllowedTypes('tags_header''string');
  61.         $resolver->setAllowedTypes('tags_invalidate_path''string');
  62.         $resolver->setAllowedTypes('header_length''int');
  63.         return $resolver;
  64.     }
  65.     /**
  66.      * {@inheritdoc}
  67.      */
  68.     public function invalidateTags(array $tags)
  69.     {
  70.         $escapedTags $this->escapeTags($tags);
  71.         $chunkSize $this->determineTagsPerHeader($escapedTags',');
  72.         foreach (array_chunk($escapedTags$chunkSize) as $tagchunk) {
  73.             $this->queueRequest(
  74.                 $this->options['tags_method'],
  75.                 $this->options['tags_invalidate_path'],
  76.                 [$this->options['tags_header'] => implode(','$tagchunk)],
  77.                 false
  78.             );
  79.         }
  80.         return $this;
  81.     }
  82.     /**
  83.      * {@inheritdoc}
  84.      *
  85.      * Clearing the cache is implemented with a purge request with a special
  86.      * header to indicate that the whole cache should be removed.
  87.      *
  88.      * @return $this
  89.      */
  90.     public function clear()
  91.     {
  92.         $this->queueRequest(
  93.             $this->options['purge_method'],
  94.             '/',
  95.             [$this->options['clear_cache_header'] => 'true'],
  96.             false
  97.         );
  98.         return $this;
  99.     }
  100. }