vendor/api-platform/core/src/Operation/Factory/CachedSubresourceOperationFactory.php line 44

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\Core\Operation\Factory;
  12. use ApiPlatform\Core\Cache\CachedTrait;
  13. use Psr\Cache\CacheItemPoolInterface;
  14. /**
  15.  * @internal
  16.  */
  17. final class CachedSubresourceOperationFactory implements SubresourceOperationFactoryInterface
  18. {
  19.     use CachedTrait;
  20.     public const CACHE_KEY_PREFIX 'subresource_operations_';
  21.     private $decorated;
  22.     public function __construct(CacheItemPoolInterface $cacheItemPoolSubresourceOperationFactoryInterface $decorated)
  23.     {
  24.         $this->cacheItemPool $cacheItemPool;
  25.         $this->decorated $decorated;
  26.     }
  27.     /**
  28.      * {@inheritdoc}
  29.      */
  30.     public function create(string $resourceClass): array
  31.     {
  32.         $cacheKey self::CACHE_KEY_PREFIX.md5($resourceClass);
  33.         return $this->getCached($cacheKey, function () use ($resourceClass) {
  34.             return $this->decorated->create($resourceClass);
  35.         });
  36.     }
  37. }