public function updateProperty(\ReflectionProperty $reflectionProperty, Schema $property)
    {
        $annotations = $this->annotationsReader->getPropertyAnnotations($reflectionProperty);

        foreach ($annotations as $annotation) {
            if ($annotation instanceof Assert\NotBlank || $annotation instanceof Assert\NotNull) {
                // The field is required
                if (null === $this->schema) {
                    continue;
                }

                $propertyName = $this->getSchemaPropertyName($property);
                if (null === $propertyName) {
                    continue;
                }

                $existingRequiredFields = $this->schema->getRequired() ?? [];
                $existingRequiredFields[] = $propertyName;

                $this->schema->setRequired(array_values(array_unique($existingRequiredFields)));
            } elseif ($annotation instanceof Assert\Length) {
                $property->setMinLength($annotation->min);
                $property->setMaxLength($annotation->max);
            } elseif ($annotation instanceof Assert\Regex) {
                $this->appendPattern($property, $annotation->getHtmlPattern());
            } elseif ($annotation instanceof Assert\Count) {
                $property->setMinItems($annotation->min);
                $property->setMaxItems($annotation->max);
            } elseif ($annotation instanceof Assert\Choice) {
                $property->setEnum($annotation->callback ? call_user_func(is_array($annotation->callback) ? $annotation->callback : [$reflectionProperty->class, $annotation->callback]) : $annotation->choices);
            } elseif ($annotation instanceof Assert\Expression) {
                $this->appendPattern($property, $annotation->message);
            } elseif ($annotation instanceof Assert\Range) {
                $property->setMinimum($annotation->min);
                $property->setMaximum($annotation->max);
            } elseif ($annotation instanceof Assert\LessThan) {
                $property->setExclusiveMaximum($annotation->value);
            } elseif ($annotation instanceof Assert\LessThanOrEqual) {
                $property->setMaximum($annotation->value);
            }
        }
    }
public function updateProperty(\ReflectionProperty $reflectionProperty, Schema $property)
    {
        $annotations = $this->annotationsReader->getPropertyAnnotations($reflectionProperty);

        foreach ($annotations as $annotation) {
            if ($annotation instanceof Assert\NotBlank || $annotation instanceof Assert\NotNull) {
                // The field is required
                if (null === $this->schema) {
                    continue;
                }

                $propertyName = $this->getSchemaPropertyName($property);
                if (null === $propertyName) {
                    continue;
                }

                $existingRequiredFields = $this->schema->getRequired() ?? [];
                $existingRequiredFields[] = $propertyName;

                $this->schema->setRequired(array_values(array_unique($existingRequiredFields)));
            } elseif ($annotation instanceof Assert\Length) {
                $property->setMinLength($annotation->min);
                $property->setMaxLength($annotation->max);
            } elseif ($annotation instanceof Assert\Regex) {
                $this->appendPattern($property, $annotation->getHtmlPattern());
            } elseif ($annotation instanceof Assert\Count) {
                $property->setMinItems($annotation->min);
                $property->setMaxItems($annotation->max);
            } elseif ($annotation instanceof Assert\Choice) {
                $property->setEnum($annotation->callback ? call_user_func(is_array($annotation->callback) ? $annotation->callback : [$reflectionProperty->class, $annotation->callback]) : $annotation->choices);
            } elseif ($annotation instanceof Assert\Expression) {
                $this->appendPattern($property, $annotation->message);
            } elseif ($annotation instanceof Assert\Range) {
                $property->setMinimum($annotation->min);
                $property->setMaximum($annotation->max);
            } elseif ($annotation instanceof Assert\LessThan) {
                $property->setExclusiveMaximum($annotation->value);
            } elseif ($annotation instanceof Assert\LessThanOrEqual) {
                $property->setMaximum($annotation->value);
            }
        }
    }
public function updateProperty ( \ ReflectionProperty $ reflectionProperty , Schema $ property ) { $ annotations = $ this -> annotationsReader -> getPropertyAnnotations ( $ reflectionProperty ) ; foreach ( $ annotations as $ annotation ) { if ( $ annotation instanceof Assert \ NotBlank || $ annotation instanceof Assert \ NotNull ) { // The field is required if ( null === $ this -> schema ) { continue ; } $ propertyName = $ this -> getSchemaPropertyName ( $ property ) ; if ( null === $ propertyName ) { continue ; } $ existingRequiredFields = $ this -> schema -> getRequired ( ) ?? [ ] ; $ existingRequiredFields [ ] = $ propertyName ; $ this -> schema -> setRequired ( array_values ( array_unique ( $ existingRequiredFields ) ) ) ; } elseif ( $ annotation instanceof Assert \ Length ) { $ property -> setMinLength ( $ annotation -> min ) ; $ property -> setMaxLength ( $ annotation -> max ) ; } elseif ( $ annotation instanceof Assert \ Regex ) { $ this -> appendPattern ( $ property , $ annotation -> getHtmlPattern ( ) ) ; } elseif ( $ annotation instanceof Assert \ Count ) { $ property -> setMinItems ( $ annotation -> min ) ; $ property -> setMaxItems ( $ annotation -> max ) ; } elseif ( $ annotation instanceof Assert \ Choice ) { $ property -> setEnum ( $ annotation -> callback ? call_user_func ( is_array ( $ annotation -> callback ) ? $ annotation -> callback : [ $ reflectionProperty -> class , $ annotation -> callback ] ) : $ annotation -> choices ) ; } elseif ( $ annotation instanceof Assert \ Expression ) { $ this -> appendPattern ( $ property , $ annotation -> message ) ; } elseif ( $ annotation instanceof Assert \ Range ) { $ property -> setMinimum ( $ annotation -> min ) ; $ property -> setMaximum ( $ annotation -> max ) ; } elseif ( $ annotation instanceof Assert \ LessThan ) { $ property -> setExclusiveMaximum ( $ annotation -> value ) ; } elseif ( $ annotation instanceof Assert \ LessThanOrEqual ) { $ property -> setMaximum ( $ annotation -> value ) ; } } }
Update the given property and schema with defined Symfony constraints.
Update the given property and schema with defined Symfony constraints .