vendor/api-platform/core/src/Metadata/Property/Factory/CachedPropertyNameCollectionFactory.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\Core\Metadata\Property\Factory;
  12. use ApiPlatform\Core\Cache\CachedTrait;
  13. use ApiPlatform\Core\Metadata\Property\PropertyNameCollection;
  14. use Psr\Cache\CacheItemPoolInterface;
  15. /**
  16.  * Caches property name collection.
  17.  *
  18.  * @author Teoh Han Hui <teohhanhui@gmail.com>
  19.  */
  20. final class CachedPropertyNameCollectionFactory implements PropertyNameCollectionFactoryInterface
  21. {
  22.     use CachedTrait;
  23.     public const CACHE_KEY_PREFIX 'property_name_collection_';
  24.     private $decorated;
  25.     public function __construct(CacheItemPoolInterface $cacheItemPoolPropertyNameCollectionFactoryInterface $decorated)
  26.     {
  27.         $this->cacheItemPool $cacheItemPool;
  28.         $this->decorated $decorated;
  29.     }
  30.     /**
  31.      * {@inheritdoc}
  32.      */
  33.     public function create(string $resourceClass, array $options = []): PropertyNameCollection
  34.     {
  35.         $cacheKey self::CACHE_KEY_PREFIX.md5(serialize([$resourceClass$options]));
  36.         return $this->getCached($cacheKey, function () use ($resourceClass$options) {
  37.             return $this->decorated->create($resourceClass$options);
  38.         });
  39.     }
  40. }