ApiPlatform\Core\Metadata\Property\Factory\CachedPropertyMetadataFactory::create PHP Метод

create() публичный метод

public create ( string $resourceClass, string $property, array $options = [] ) : PropertyMetadata
$resourceClass string
$property string
$options array
Результат ApiPlatform\Core\Metadata\Property\PropertyMetadata
    public function create(string $resourceClass, string $property, array $options = []) : PropertyMetadata
    {
        $cacheKey = self::CACHE_KEY_PREFIX . md5(serialize([$resourceClass, $property, $options]));
        try {
            $cacheItem = $this->cacheItemPool->getItem($cacheKey);
            if ($cacheItem->isHit()) {
                return $cacheItem->get();
            }
        } catch (CacheException $e) {
            // do nothing
        }
        $propertyMetadata = $this->decorated->create($resourceClass, $property, $options);
        if (!isset($cacheItem)) {
            return $propertyMetadata;
        }
        $cacheItem->set($propertyMetadata);
        $this->cacheItemPool->save($cacheItem);
        return $propertyMetadata;
    }

Usage Example

 public function testCreateWithGetCacheItemThrowsCacheException()
 {
     $decoratedPropertyMetadataFactory = $this->prophesize(PropertyMetadataFactoryInterface::class);
     $decoratedPropertyMetadataFactory->create(Dummy::class, 'dummy', [])->willReturn(new PropertyMetadata(null, 'A dummy', true, true, null, null, false, false))->shouldBeCalled();
     $cacheException = $this->prophesize(CacheException::class);
     $cacheException->willExtend(\Exception::class);
     $cacheItemPool = $this->prophesize(CacheItemPoolInterface::class);
     $cacheItemPool->getItem($this->generateCacheKey())->willThrow($cacheException->reveal())->shouldBeCalled();
     $cachedPropertyMetadataFactory = new CachedPropertyMetadataFactory($cacheItemPool->reveal(), $decoratedPropertyMetadataFactory->reveal());
     $resultedPropertyMetadata = $cachedPropertyMetadataFactory->create(Dummy::class, 'dummy');
     $this->assertInstanceOf(PropertyMetadata::class, $resultedPropertyMetadata);
     $this->assertEquals(new PropertyMetadata(null, 'A dummy', true, true, null, null, false, false), $resultedPropertyMetadata);
 }
CachedPropertyMetadataFactory