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