ApiPlatform\Core\Metadata\Property\Factory\ExtractorPropertyMetadataFactory::create PHP Method

create() public method

public create ( string $resourceClass, string $property, array $options = [] ) : PropertyMetadata
$resourceClass string
$property string
$options array
return ApiPlatform\Core\Metadata\Property\PropertyMetadata
    public function create(string $resourceClass, string $property, array $options = []) : PropertyMetadata
    {
        $parentPropertyMetadata = null;
        if ($this->decorated) {
            try {
                $parentPropertyMetadata = $this->decorated->create($resourceClass, $property, $options);
            } catch (PropertyNotFoundException $propertyNotFoundException) {
                // Ignore not found exception from decorated factories
            }
        }
        if (!property_exists($resourceClass, $property) || !($propertyMetadata = $this->extractor->getResources()[$resourceClass]['properties'][$property] ?? false)) {
            return $this->handleNotFound($parentPropertyMetadata, $resourceClass, $property);
        }
        if ($parentPropertyMetadata) {
            return $this->update($parentPropertyMetadata, $propertyMetadata);
        }
        return new PropertyMetadata(null, $propertyMetadata['description'], $propertyMetadata['readable'], $propertyMetadata['writable'], $propertyMetadata['readableLink'], $propertyMetadata['writableLink'], $propertyMetadata['required'], $propertyMetadata['identifier'], $propertyMetadata['iri'], null, $propertyMetadata['attributes']);
    }

Usage Example

 /**
  * @dataProvider decoratedPropertyMetadataProvider
  */
 public function testCreateWithParentPropertyMetadataFactoryYaml(PropertyMetadata $expectedPropertyMetadata)
 {
     $configPath = __DIR__ . '/../../../Fixtures/FileConfigurations/resources.yml';
     $decorated = $this->prophesize(PropertyMetadataFactoryInterface::class);
     $decorated->create(FileConfigDummy::class, 'foo', [])->willReturn(new PropertyMetadata(null, null, null, null, true, null, null, false, null, null, ['Foo']))->shouldBeCalled();
     $propertyMetadataFactory = new ExtractorPropertyMetadataFactory(new YamlExtractor([$configPath]), $decorated->reveal());
     $propertyMetadata = $propertyMetadataFactory->create(FileConfigDummy::class, 'foo');
     $this->assertInstanceOf(PropertyMetadata::class, $propertyMetadata);
     $this->assertEquals($expectedPropertyMetadata, $propertyMetadata);
 }
ExtractorPropertyMetadataFactory