ApiPlatform\Core\Metadata\Property\Factory\InheritedPropertyMetadataFactory::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
    {
        $propertyMetadata = $this->decorated->create($resourceClass, $property, $options);
        foreach ($this->resourceNameCollection->create() as $knownResourceClass) {
            if ($resourceClass === $knownResourceClass) {
                continue;
            }
            if (is_subclass_of($knownResourceClass, $resourceClass)) {
                $propertyMetadata = $this->create($knownResourceClass, $property, $options);
                return $propertyMetadata->withChildInherited($knownResourceClass);
            }
        }
        return $propertyMetadata;
    }

Usage Example

 public function testCreate()
 {
     $resourceNameCollectionFactory = $this->prophesize(ResourceNameCollectionFactoryInterface::class);
     $resourceNameCollectionFactory->create()->willReturn(new ResourceNameCollection([DummyTableInheritance::class, DummyTableInheritanceChild::class]))->shouldBeCalled();
     $type = new Type(Type::BUILTIN_TYPE_STRING);
     $nicknameMetadata = new PropertyMetadata($type, 'nickname', true, true, false, false, true, false, 'http://example.com/foo', null, ['foo' => 'bar']);
     $propertyMetadataFactory = $this->prophesize(PropertyMetadataFactoryInterface::class);
     $propertyMetadataFactory->create(DummyTableInheritance::class, 'nickname', [])->willReturn($nicknameMetadata)->shouldBeCalled();
     $propertyMetadataFactory->create(DummyTableInheritanceChild::class, 'nickname', [])->willReturn($nicknameMetadata)->shouldBeCalled();
     $factory = new InheritedPropertyMetadataFactory($resourceNameCollectionFactory->reveal(), $propertyMetadataFactory->reveal());
     $metadata = $factory->create(DummyTableInheritance::class, 'nickname');
     $shouldBe = new PropertyMetadata($type, 'nickname', true, true, false, false, true, false, 'http://example.com/foo', DummyTableInheritanceChild::class, ['foo' => 'bar']);
     $this->assertEquals($metadata, $shouldBe);
 }
InheritedPropertyMetadataFactory