ApiPlatform\Core\Metadata\Property\Factory\SerializerPropertyMetadataFactory::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);
        // in case of a property inherited (in a child class), we need it's properties
        // to be mapped against serialization groups instead of the parent ones.
        if (null !== ($childResourceClass = $propertyMetadata->isChildInherited())) {
            $resourceClass = $childResourceClass;
        }
        list($normalizationGroups, $denormalizationGroups) = $this->getEffectiveSerializerGroups($options, $resourceClass);
        $propertyMetadata = $this->transformReadWrite($propertyMetadata, $resourceClass, $property, $normalizationGroups, $denormalizationGroups);
        $propertyMetadata = $this->transformLinkStatus($propertyMetadata, $normalizationGroups, $denormalizationGroups);
        return $propertyMetadata;
    }

Usage Example

 public function testCreateInherited()
 {
     $resourceMetadataFactoryProphecy = $this->prophesize(ResourceMetadataFactoryInterface::class);
     $resourceMetadataFactoryProphecy->create(DummyTableInheritanceChild::class)->willReturn(new ResourceMetadata())->shouldBeCalled();
     $resourceMetadataFactory = $resourceMetadataFactoryProphecy->reveal();
     $serializerClassMetadataFactoryProphecy = $this->prophesize(SerializerClassMetadataFactoryInterface::class);
     $dummySerializerClassMetadata = new SerializerClassMetadata(DummyTableInheritanceChild::class);
     $serializerClassMetadataFactoryProphecy->getMetadataFor(DummyTableInheritanceChild::class)->willReturn($dummySerializerClassMetadata)->shouldBeCalled();
     $serializerClassMetadataFactory = $serializerClassMetadataFactoryProphecy->reveal();
     $decoratedProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
     $fooPropertyMetadata = (new PropertyMetadata())->withType(new Type(Type::BUILTIN_TYPE_ARRAY, true))->withChildInherited(DummyTableInheritanceChild::class);
     $decoratedProphecy->create(DummyTableInheritance::class, 'nickname', [])->willReturn($fooPropertyMetadata)->shouldBeCalled();
     $decorated = $decoratedProphecy->reveal();
     $serializerPropertyMetadataFactory = new SerializerPropertyMetadataFactory($resourceMetadataFactory, $serializerClassMetadataFactory, $decorated);
     $actual = $serializerPropertyMetadataFactory->create(DummyTableInheritance::class, 'nickname');
     $this->assertInstanceOf(PropertyMetadata::class, $actual);
     $this->assertEquals($actual->isChildInherited(), DummyTableInheritanceChild::class);
 }