ApiPlatform\Core\Bridge\Symfony\Validator\Metadata\Property\ValidatorPropertyMetadataFactory::create PHP Метод

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

public create ( string $resourceClass, string $name, array $options = [] ) : PropertyMetadata
$resourceClass string
$name string
$options array
Результат ApiPlatform\Core\Metadata\Property\PropertyMetadata
    public function create(string $resourceClass, string $name, array $options = []) : PropertyMetadata
    {
        $propertyMetadata = $this->decorated->create($resourceClass, $name, $options);
        if (null !== $propertyMetadata->isRequired()) {
            return $propertyMetadata;
        }
        $validatorClassMetadata = $this->validatorMetadataFactory->getMetadataFor($resourceClass);
        foreach ($validatorClassMetadata->getPropertyMetadata($name) as $validatorPropertyMetadata) {
            if (isset($options['validation_groups'])) {
                return $propertyMetadata->withRequired($this->isRequiredByGroups($validatorPropertyMetadata, $options));
            }
            foreach ($validatorPropertyMetadata->findConstraints($validatorClassMetadata->getDefaultGroup()) as $constraint) {
                if ($this->isRequired($constraint)) {
                    return $propertyMetadata->withRequired(true);
                }
            }
            return $propertyMetadata->withRequired(false);
        }
        return $propertyMetadata->withRequired(false);
    }

Usage Example

 public function testCreateWithRequiredByDecorated()
 {
     $propertyMetadata = new PropertyMetadata(null, 'A dummy date', true, true, null, null, true, false);
     $expectedPropertyMetadata = clone $propertyMetadata;
     $decoratedPropertyMetadataFactory = $this->prophesize(PropertyMetadataFactoryInterface::class);
     $decoratedPropertyMetadataFactory->create(DummyValidatedEntity::class, 'dummyDate', [])->willReturn($propertyMetadata)->shouldBeCalled();
     $validatorMetadataFactory = $this->prophesize(MetadataFactoryInterface::class);
     $validatorPropertyMetadataFactory = new ValidatorPropertyMetadataFactory($validatorMetadataFactory->reveal(), $decoratedPropertyMetadataFactory->reveal());
     $resultedPropertyMetadata = $validatorPropertyMetadataFactory->create(DummyValidatedEntity::class, 'dummyDate');
     $this->assertInstanceOf(PropertyMetadata::class, $resultedPropertyMetadata);
     $this->assertEquals($expectedPropertyMetadata, $resultedPropertyMetadata);
 }