Psr6CacheClearer.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.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 Symfony\Component\HttpKernel\CacheClearer;
  11. use Psr\Cache\CacheItemPoolInterface;
  12. /**
  13. * @author Nicolas Grekas <p@tchwork.com>
  14. */
  15. class Psr6CacheClearer implements CacheClearerInterface
  16. {
  17. private $pools = array();
  18. public function __construct(array $pools = array())
  19. {
  20. $this->pools = $pools;
  21. }
  22. public function addPool(CacheItemPoolInterface $pool)
  23. {
  24. @trigger_error(sprintf('The %s() method is deprecated since version 3.3 and will be removed in 4.0. Pass an array of pools indexed by name to the constructor instead.', __METHOD__), E_USER_DEPRECATED);
  25. $this->pools[] = $pool;
  26. }
  27. public function hasPool($name)
  28. {
  29. return isset($this->pools[$name]);
  30. }
  31. public function clearPool($name)
  32. {
  33. if (!isset($this->pools[$name])) {
  34. throw new \InvalidArgumentException(sprintf('Cache pool not found: %s.', $name));
  35. }
  36. return $this->pools[$name]->clear();
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function clear($cacheDir)
  42. {
  43. foreach ($this->pools as $pool) {
  44. $pool->clear();
  45. }
  46. }
  47. }