vendor/api-platform/core/src/Metadata/Resource/Factory/CachedResourceNameCollectionFactory.php line 42

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the API Platform project.
  4.  *
  5.  * (c) Kévin Dunglas <dunglas@gmail.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. declare(strict_types=1);
  11. namespace ApiPlatform\Metadata\Resource\Factory;
  12. use ApiPlatform\Metadata\Resource\ResourceNameCollection;
  13. use ApiPlatform\Util\CachedTrait;
  14. use Psr\Cache\CacheItemPoolInterface;
  15. /**
  16.  * Caches resource name collection.
  17.  *
  18.  * @author Teoh Han Hui <teohhanhui@gmail.com>
  19.  */
  20. final class CachedResourceNameCollectionFactory implements ResourceNameCollectionFactoryInterface
  21. {
  22.     use CachedTrait;
  23.     public const CACHE_KEY 'resource_name_collection';
  24.     private $decorated;
  25.     public function __construct(CacheItemPoolInterface $cacheItemPoolResourceNameCollectionFactoryInterface $decorated)
  26.     {
  27.         $this->cacheItemPool $cacheItemPool;
  28.         $this->decorated $decorated;
  29.     }
  30.     /**
  31.      * {@inheritdoc}
  32.      */
  33.     public function create(): ResourceNameCollection
  34.     {
  35.         return $this->getCached(self::CACHE_KEY, function () {
  36.             return $this->decorated->create();
  37.         });
  38.     }
  39. }