Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Form] added method
guessPattern
to FormTypeGuesserInterface
rephrase changelog
- Loading branch information
Showing
9 changed files
with
97 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,12 +68,12 @@ public function guessMaxLength($class, $property) | |
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function guessMinLength($class, $property) | ||
public function guessPattern($class, $property) | ||
{ | ||
$guesser = $this; | ||
|
||
return $this->guess($class, $property, function (Constraint $constraint) use ($guesser) { | ||
return $guesser->guessMinLengthForConstraint($constraint); | ||
return $guesser->guessPatternForConstraint($constraint); | ||
}); | ||
} | ||
|
||
|
@@ -205,32 +205,35 @@ public function guessMaxLengthForConstraint(Constraint $constraint) | |
} | ||
|
||
/** | ||
* Guesses a field's minimum length based on the given constraint | ||
* | ||
* Guesses a field's pattern based on the given constraint | ||
* | ||
* @param Constraint $constraint The constraint to guess for | ||
* | ||
* @return Guess The guess for the minimum length | ||
* @return Guess The guess for the pattern | ||
*/ | ||
public function guessMinLengthForConstraint(Constraint $constraint) | ||
public function guessPatternForConstraint(Constraint $constraint) | ||
{ | ||
switch (get_class($constraint)) { | ||
case 'Symfony\Component\Validator\Constraints\MinLength': | ||
return new ValueGuess($constraint->limit, Guess::HIGH_CONFIDENCE); | ||
return new ValueGuess(sprintf('.{%s,}', (string) $constraint->limit), Guess::LOW_CONFIDENCE); | ||
|
||
case 'Symfony\Component\Validator\Constraints\SizeLength': | ||
return new ValueGuess($constraint->min, Guess::HIGH_CONFIDENCE); | ||
return new ValueGuess(sprintf('.{%s,%s}', (string) $constraint->min, (string) $constraint->max), Guess::LOW_CONFIDENCE); | ||
|
||
case 'Symfony\Component\Validator\Constraints\Regex': | ||
return new ValueGuess($constraint->pattern, Guess::HIGH_CONFIDENCE ); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
stof
Member
|
||
|
||
case 'Symfony\Component\Validator\Constraints\Min': | ||
return new ValueGuess(sprintf('.{%s,}', strlen((string) $constraint->limit)), Guess::LOW_CONFIDENCE); | ||
|
||
case 'Symfony\Component\Validator\Constraints\Size': | ||
return new ValueGuess(sprintf('.{%s,%s}', strlen((string) $constraint->min), strlen((string) $constraint->max)), Guess::LOW_CONFIDENCE); | ||
|
||
case 'Symfony\Component\Validator\Constraints\Type': | ||
if (in_array($constraint->type, array('double', 'float', 'numeric', 'real'))) { | ||
return new ValueGuess(null, Guess::MEDIUM_CONFIDENCE); | ||
} | ||
break; | ||
|
||
case 'Symfony\Component\Validator\Constraints\Min': | ||
return new ValueGuess(strlen((string) $constraint->limit), Guess::LOW_CONFIDENCE); | ||
|
||
case 'Symfony\Component\Validator\Constraints\Size': | ||
return new ValueGuess(strlen((string) $constraint->min), Guess::LOW_CONFIDENCE); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Isn't there a trailing space?