vendor/symfony/cache/Adapter/NullAdapter.php line 40

  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\Cache\Adapter;
  11. use Psr\Cache\CacheItemInterface;
  12. use Symfony\Component\Cache\CacheItem;
  13. use Symfony\Contracts\Cache\CacheInterface;
  14. /**
  15.  * @author Titouan Galopin <galopintitouan@gmail.com>
  16.  */
  17. class NullAdapter implements AdapterInterfaceCacheInterface
  18. {
  19.     private static $createCacheItem;
  20.     public function __construct()
  21.     {
  22.         self::$createCacheItem ??= \Closure::bind(
  23.             static function ($key) {
  24.                 $item = new CacheItem();
  25.                 $item->key $key;
  26.                 $item->isHit false;
  27.                 return $item;
  28.             },
  29.             null,
  30.             CacheItem::class
  31.         );
  32.     }
  33.     public function get(string $key, callable $callbackfloat $beta null, array &$metadata null): mixed
  34.     {
  35.         $save true;
  36.         return $callback((self::$createCacheItem)($key), $save);
  37.     }
  38.     public function getItem(mixed $key): CacheItem
  39.     {
  40.         return (self::$createCacheItem)($key);
  41.     }
  42.     public function getItems(array $keys = []): iterable
  43.     {
  44.         return $this->generateItems($keys);
  45.     }
  46.     public function hasItem(mixed $key): bool
  47.     {
  48.         return false;
  49.     }
  50.     public function clear(string $prefix ''): bool
  51.     {
  52.         return true;
  53.     }
  54.     public function deleteItem(mixed $key): bool
  55.     {
  56.         return true;
  57.     }
  58.     public function deleteItems(array $keys): bool
  59.     {
  60.         return true;
  61.     }
  62.     public function save(CacheItemInterface $item): bool
  63.     {
  64.         return true;
  65.     }
  66.     public function saveDeferred(CacheItemInterface $item): bool
  67.     {
  68.         return true;
  69.     }
  70.     public function commit(): bool
  71.     {
  72.         return true;
  73.     }
  74.     public function delete(string $key): bool
  75.     {
  76.         return $this->deleteItem($key);
  77.     }
  78.     private function generateItems(array $keys): \Generator
  79.     {
  80.         $f self::$createCacheItem;
  81.         foreach ($keys as $key) {
  82.             yield $key => $f($key);
  83.         }
  84.     }
  85. }