W3cubDocs

/Symfony 4.1

ValidatorTypeGuesser

class ValidatorTypeGuesser implements FormTypeGuesserInterface

Methods

__construct(MetadataFactoryInterface $metadataFactory)
TypeGuess|null guessType(string $class, string $property)

Returns a field guess for a property name of a class.

ValueGuess guessRequired(string $class, string $property)

Returns a guess whether a property of a class is required.

ValueGuess|null guessMaxLength(string $class, string $property)

Returns a guess about the field's maximum length.

ValueGuess|null guessPattern(string $class, string $property)

Returns a guess about the field's pattern.

TypeGuess|null guessTypeForConstraint(Constraint $constraint)

Guesses a field class name for a given constraint.

ValueGuess|null guessRequiredForConstraint(Constraint $constraint)

Guesses whether a field is required based on the given constraint.

ValueGuess|null guessMaxLengthForConstraint(Constraint $constraint)

Guesses a field's maximum length based on the given constraint.

ValueGuess|null guessPatternForConstraint(Constraint $constraint)

Guesses a field's pattern based on the given constraint.

Guess|null guess(string $class, string $property, Closure $closure, mixed $defaultValue = null)

Iterates over the constraints of a property, executes a constraints on them and returns the best guess.

Details

__construct(MetadataFactoryInterface $metadataFactory)

Parameters

MetadataFactoryInterface $metadataFactory

TypeGuess|null guessType(string $class, string $property)

Returns a field guess for a property name of a class.

Parameters

string $class The fully qualified class name
string $property The name of the property to guess for

Return Value

TypeGuess|null A guess for the field's type and options

ValueGuess guessRequired(string $class, string $property)

Returns a guess whether a property of a class is required.

Parameters

string $class The fully qualified class name
string $property The name of the property to guess for

Return Value

ValueGuess A guess for the field's required setting

ValueGuess|null guessMaxLength(string $class, string $property)

Returns a guess about the field's maximum length.

Parameters

string $class The fully qualified class name
string $property The name of the property to guess for

Return Value

ValueGuess|null A guess for the field's maximum length

ValueGuess|null guessPattern(string $class, string $property)

Returns a guess about the field's pattern.

  • When you have a min value, you guess a min length of this min (LOW_CONFIDENCE) , lines below
  • If this value is a float type, this is wrong so you guess null with MEDIUM_CONFIDENCE to override the previous guess. Example: You want a float greater than 5, 4.512313 is not valid but length(4.512314) > length(5)

Parameters

string $class The fully qualified class name
string $property The name of the property to guess for

Return Value

ValueGuess|null A guess for the field's required pattern

TypeGuess|null guessTypeForConstraint(Constraint $constraint)

Guesses a field class name for a given constraint.

Parameters

Constraint $constraint

Return Value

TypeGuess|null The guessed field class and options

ValueGuess|null guessRequiredForConstraint(Constraint $constraint)

Guesses whether a field is required based on the given constraint.

Parameters

Constraint $constraint

Return Value

ValueGuess|null The guess whether the field is required

ValueGuess|null guessMaxLengthForConstraint(Constraint $constraint)

Guesses a field's maximum length based on the given constraint.

Parameters

Constraint $constraint

Return Value

ValueGuess|null The guess for the maximum length

ValueGuess|null guessPatternForConstraint(Constraint $constraint)

Guesses a field's pattern based on the given constraint.

Parameters

Constraint $constraint

Return Value

ValueGuess|null The guess for the pattern

protected Guess|null guess(string $class, string $property, Closure $closure, mixed $defaultValue = null)

Iterates over the constraints of a property, executes a constraints on them and returns the best guess.

Parameters

string $class The class to read the constraints from
string $property The property for which to find constraints
Closure $closure The closure that returns a guess for a given constraint
mixed $defaultValue The default value assumed if no other value can be guessed

Return Value

Guess|null The guessed value with the highest confidence

© 2004–2017 Fabien Potencier
Licensed under the MIT License.
https://api.symfony.com/4.1/Symfony/Component/Form/Extension/Validator/ValidatorTypeGuesser.html