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

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

public create ( string $resourceClass, array $options = [] ) : PropertyNameCollection
$resourceClass string
$options array
Результат ApiPlatform\Core\Metadata\Property\PropertyNameCollection
    public function create(string $resourceClass, array $options = []) : PropertyNameCollection
    {
        $propertyNames = [];
        // Inherited from parent
        foreach ($this->decorated->create($resourceClass, $options) as $propertyName) {
            $propertyNames[$propertyName] = true;
        }
        foreach ($this->resourceNameCollection->create() as $knownResourceClass) {
            if ($resourceClass === $knownResourceClass) {
                continue;
            }
            if (is_subclass_of($knownResourceClass, $resourceClass)) {
                foreach ($this->create($knownResourceClass) as $propertyName) {
                    $propertyNames[$propertyName] = true;
                }
            }
        }
        return new PropertyNameCollection(array_keys($propertyNames));
    }

Usage Example

 public function testCreate()
 {
     $resourceNameCollectionFactory = $this->prophesize(ResourceNameCollectionFactoryInterface::class);
     $resourceNameCollectionFactory->create()->willReturn(new ResourceNameCollection([DummyTableInheritance::class, DummyTableInheritanceChild::class]))->shouldBeCalled();
     $propertyNameCollectionFactory = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
     $propertyNameCollectionFactory->create(DummyTableInheritance::class, [])->willReturn(new PropertyNameCollection(['name']))->shouldBeCalled();
     $propertyNameCollectionFactory->create(DummyTableInheritanceChild::class, [])->willReturn(new PropertyNameCollection(['nickname']))->shouldBeCalled();
     $factory = new InheritedPropertyNameCollectionFactory($resourceNameCollectionFactory->reveal(), $propertyNameCollectionFactory->reveal());
     $metadata = $factory->create(DummyTableInheritance::class);
     $this->assertEquals($metadata, new PropertyNameCollection(['name', 'nickname']));
 }
InheritedPropertyNameCollectionFactory