[Validator] Renamed valueToString() to formatValue(); added missing formatValue() calls
This commit is contained in:
parent
71897d7e35
commit
d6a783f989
@ -40,7 +40,7 @@ abstract class ConstraintValidator implements ConstraintValidatorInterface
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function valueToType($value)
|
protected function formatTypeOf($value)
|
||||||
{
|
{
|
||||||
return is_object($value) ? get_class($value) : gettype($value);
|
return is_object($value) ? get_class($value) : gettype($value);
|
||||||
}
|
}
|
||||||
@ -49,13 +49,13 @@ abstract class ConstraintValidator implements ConstraintValidatorInterface
|
|||||||
* Returns a string representation of the value.
|
* Returns a string representation of the value.
|
||||||
*
|
*
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param bool $formatDates
|
* @param bool $prettyDateTime
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function valueToString($value, $formatDates = false)
|
protected function formatValue($value, $prettyDateTime = false)
|
||||||
{
|
{
|
||||||
if ($formatDates && $value instanceof \DateTime) {
|
if ($prettyDateTime && $value instanceof \DateTime) {
|
||||||
if (class_exists('IntlDateFormatter')) {
|
if (class_exists('IntlDateFormatter')) {
|
||||||
$locale = \Locale::getDefault();
|
$locale = \Locale::getDefault();
|
||||||
$formatter = new \IntlDateFormatter($locale, \IntlDateFormatter::MEDIUM, \IntlDateFormatter::SHORT);
|
$formatter = new \IntlDateFormatter($locale, \IntlDateFormatter::MEDIUM, \IntlDateFormatter::SHORT);
|
||||||
@ -101,14 +101,14 @@ abstract class ConstraintValidator implements ConstraintValidatorInterface
|
|||||||
* Returns a string representation of a list of values.
|
* Returns a string representation of a list of values.
|
||||||
*
|
*
|
||||||
* @param array $values
|
* @param array $values
|
||||||
* @param bool $formatDates
|
* @param bool $prettyDateTime
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function valuesToString(array $values, $formatDates = false)
|
protected function formatValues(array $values, $prettyDateTime = false)
|
||||||
{
|
{
|
||||||
foreach ($values as $key => $value) {
|
foreach ($values as $key => $value) {
|
||||||
$values[$key] = $this->valueToString($value, $formatDates);
|
$values[$key] = $this->formatValue($value, $prettyDateTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
return implode(', ', $values);
|
return implode(', ', $values);
|
||||||
|
@ -32,9 +32,9 @@ abstract class AbstractComparisonValidator extends ConstraintValidator
|
|||||||
|
|
||||||
if (!$this->compareValues($value, $constraint->value)) {
|
if (!$this->compareValues($value, $constraint->value)) {
|
||||||
$this->context->addViolation($constraint->message, array(
|
$this->context->addViolation($constraint->message, array(
|
||||||
'{{ value }}' => $this->valueToString($value, true),
|
'{{ value }}' => $this->formatValue($value, true),
|
||||||
'{{ compared_value }}' => $this->valueToString($constraint->value, true),
|
'{{ compared_value }}' => $this->formatValue($constraint->value, true),
|
||||||
'{{ compared_value_type }}' => $this->valueToType($constraint->value)
|
'{{ compared_value_type }}' => $this->formatTypeOf($constraint->value)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ class BlankValidator extends ConstraintValidator
|
|||||||
{
|
{
|
||||||
if ('' !== $value && null !== $value) {
|
if ('' !== $value && null !== $value) {
|
||||||
$this->context->addViolation($constraint->message, array(
|
$this->context->addViolation($constraint->message, array(
|
||||||
'{{ value }}' => $this->valueToString($value)
|
'{{ value }}' => $this->formatValue($value)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,7 @@ class CardSchemeValidator extends ConstraintValidator
|
|||||||
|
|
||||||
if (!is_numeric($value)) {
|
if (!is_numeric($value)) {
|
||||||
$this->context->addViolation($constraint->message, array(
|
$this->context->addViolation($constraint->message, array(
|
||||||
'{{ value }}' => $this->valueToString($value),
|
'{{ value }}' => $this->formatValue($value),
|
||||||
));
|
));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -127,7 +127,7 @@ class CardSchemeValidator extends ConstraintValidator
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->context->addViolation($constraint->message, array(
|
$this->context->addViolation($constraint->message, array(
|
||||||
'{{ value }}' => $value,
|
'{{ value }}' => $this->formatValue($value),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ class ChoiceValidator extends ConstraintValidator
|
|||||||
foreach ($value as $_value) {
|
foreach ($value as $_value) {
|
||||||
if (!in_array($_value, $choices, $constraint->strict)) {
|
if (!in_array($_value, $choices, $constraint->strict)) {
|
||||||
$this->context->addViolation($constraint->multipleMessage, array(
|
$this->context->addViolation($constraint->multipleMessage, array(
|
||||||
'{{ value }}' => $this->valueToString($_value),
|
'{{ value }}' => $this->formatValue($_value),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -84,7 +84,7 @@ class ChoiceValidator extends ConstraintValidator
|
|||||||
}
|
}
|
||||||
} elseif (!in_array($value, $choices, $constraint->strict)) {
|
} elseif (!in_array($value, $choices, $constraint->strict)) {
|
||||||
$this->context->addViolation($constraint->message, array(
|
$this->context->addViolation($constraint->message, array(
|
||||||
'{{ value }}' => $this->valueToString($value)
|
'{{ value }}' => $this->formatValue($value)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ class CollectionValidator extends ConstraintValidator
|
|||||||
}
|
}
|
||||||
} elseif (!$fieldConstraint instanceof Optional && !$constraint->allowMissingFields) {
|
} elseif (!$fieldConstraint instanceof Optional && !$constraint->allowMissingFields) {
|
||||||
$this->context->addViolationAt('['.$field.']', $constraint->missingFieldsMessage, array(
|
$this->context->addViolationAt('['.$field.']', $constraint->missingFieldsMessage, array(
|
||||||
'{{ field }}' => $field
|
'{{ field }}' => $this->formatValue($field)
|
||||||
), null);
|
), null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -57,7 +57,7 @@ class CollectionValidator extends ConstraintValidator
|
|||||||
foreach ($value as $field => $fieldValue) {
|
foreach ($value as $field => $fieldValue) {
|
||||||
if (!isset($constraint->fields[$field])) {
|
if (!isset($constraint->fields[$field])) {
|
||||||
$this->context->addViolationAt('['.$field.']', $constraint->extraFieldsMessage, array(
|
$this->context->addViolationAt('['.$field.']', $constraint->extraFieldsMessage, array(
|
||||||
'{{ field }}' => $field
|
'{{ field }}' => $this->formatValue($field)
|
||||||
), $fieldValue);
|
), $fieldValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ class CountryValidator extends ConstraintValidator
|
|||||||
|
|
||||||
if (!isset($countries[$value])) {
|
if (!isset($countries[$value])) {
|
||||||
$this->context->addViolation($constraint->message, array(
|
$this->context->addViolation($constraint->message, array(
|
||||||
'{{ value }}' => $value,
|
'{{ value }}' => $this->formatValue($value),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ class CurrencyValidator extends ConstraintValidator
|
|||||||
|
|
||||||
if (!isset($currencies[$value])) {
|
if (!isset($currencies[$value])) {
|
||||||
$this->context->addViolation($constraint->message, array(
|
$this->context->addViolation($constraint->message, array(
|
||||||
'{{ value }}' => $value,
|
'{{ value }}' => $this->formatValue($value),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ class DateValidator extends ConstraintValidator
|
|||||||
|
|
||||||
if (!preg_match(static::PATTERN, $value, $matches) || !checkdate($matches[2], $matches[3], $matches[1])) {
|
if (!preg_match(static::PATTERN, $value, $matches) || !checkdate($matches[2], $matches[3], $matches[1])) {
|
||||||
$this->context->addViolation($constraint->message, array(
|
$this->context->addViolation($constraint->message, array(
|
||||||
'{{ value }}' => $value,
|
'{{ value }}' => $this->formatValue($value),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ class EmailValidator extends ConstraintValidator
|
|||||||
|
|
||||||
if (!$valid) {
|
if (!$valid) {
|
||||||
$this->context->addViolation($constraint->message, array(
|
$this->context->addViolation($constraint->message, array(
|
||||||
'{{ value }}' => $value,
|
'{{ value }}' => $this->formatValue($value),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ class FalseValidator extends ConstraintValidator
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->context->addViolation($constraint->message, array(
|
$this->context->addViolation($constraint->message, array(
|
||||||
'{{ value }}' => $this->valueToString($value),
|
'{{ value }}' => $this->formatValue($value),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,13 +96,17 @@ class FileValidator extends ConstraintValidator
|
|||||||
$path = $value instanceof FileObject ? $value->getPathname() : (string) $value;
|
$path = $value instanceof FileObject ? $value->getPathname() : (string) $value;
|
||||||
|
|
||||||
if (!is_file($path)) {
|
if (!is_file($path)) {
|
||||||
$this->context->addViolation($constraint->notFoundMessage, array('{{ file }}' => $path));
|
$this->context->addViolation($constraint->notFoundMessage, array(
|
||||||
|
'{{ file }}' => $this->formatValue($path)
|
||||||
|
));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_readable($path)) {
|
if (!is_readable($path)) {
|
||||||
$this->context->addViolation($constraint->notReadableMessage, array('{{ file }}' => $path));
|
$this->context->addViolation($constraint->notReadableMessage, array(
|
||||||
|
'{{ file }}' => $this->formatValue($path)
|
||||||
|
));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -129,7 +133,7 @@ class FileValidator extends ConstraintValidator
|
|||||||
'{{ size }}' => $size,
|
'{{ size }}' => $size,
|
||||||
'{{ limit }}' => $limit,
|
'{{ limit }}' => $limit,
|
||||||
'{{ suffix }}' => $suffix,
|
'{{ suffix }}' => $suffix,
|
||||||
'{{ file }}' => $path,
|
'{{ file }}' => $this->formatValue($path),
|
||||||
));
|
));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -161,9 +165,9 @@ class FileValidator extends ConstraintValidator
|
|||||||
|
|
||||||
if (false === $valid) {
|
if (false === $valid) {
|
||||||
$this->context->addViolation($constraint->mimeTypesMessage, array(
|
$this->context->addViolation($constraint->mimeTypesMessage, array(
|
||||||
'{{ type }}' => $this->valueToString($mime),
|
'{{ type }}' => $this->formatValue($mime),
|
||||||
'{{ types }}' => $this->valuesToString($mimeTypes),
|
'{{ types }}' => $this->formatValues($mimeTypes),
|
||||||
'{{ file }}' => $path,
|
'{{ file }}' => $this->formatValue($path),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,12 +36,14 @@ class IbanValidator extends ConstraintValidator
|
|||||||
throw new UnexpectedTypeException($value, 'string');
|
throw new UnexpectedTypeException($value, 'string');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$value = (string) $value;
|
||||||
|
|
||||||
// Remove spaces
|
// Remove spaces
|
||||||
$canonicalized = str_replace(' ', '', $value);
|
$canonicalized = str_replace(' ', '', $value);
|
||||||
|
|
||||||
if (strlen($canonicalized) < 4) {
|
if (strlen($canonicalized) < 4) {
|
||||||
$this->context->addViolation($constraint->message, array(
|
$this->context->addViolation($constraint->message, array(
|
||||||
'{{ value }}' => $value,
|
'{{ value }}' => $this->formatValue($value),
|
||||||
));
|
));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -52,7 +54,7 @@ class IbanValidator extends ConstraintValidator
|
|||||||
if (strlen($canonicalized) < 4 || !ctype_upper($canonicalized{0})
|
if (strlen($canonicalized) < 4 || !ctype_upper($canonicalized{0})
|
||||||
|| !ctype_upper($canonicalized{1}) || !ctype_alnum($canonicalized)) {
|
|| !ctype_upper($canonicalized{1}) || !ctype_alnum($canonicalized)) {
|
||||||
$this->context->addViolation($constraint->message, array(
|
$this->context->addViolation($constraint->message, array(
|
||||||
'{{ value }}' => $value,
|
'{{ value }}' => $this->formatValue($value),
|
||||||
));
|
));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -72,7 +74,7 @@ class IbanValidator extends ConstraintValidator
|
|||||||
|
|
||||||
if (false === $checkSum) {
|
if (false === $checkSum) {
|
||||||
$this->context->addViolation($constraint->message, array(
|
$this->context->addViolation($constraint->message, array(
|
||||||
'{{ value }}' => $value,
|
'{{ value }}' => $this->formatValue($value),
|
||||||
));
|
));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -83,7 +85,7 @@ class IbanValidator extends ConstraintValidator
|
|||||||
// modulo step-wisely instead
|
// modulo step-wisely instead
|
||||||
if (1 !== $this->bigModulo97($checkSum)) {
|
if (1 !== $this->bigModulo97($checkSum)) {
|
||||||
$this->context->addViolation($constraint->message, array(
|
$this->context->addViolation($constraint->message, array(
|
||||||
'{{ value }}' => $value,
|
'{{ value }}' => $this->formatValue($value),
|
||||||
));
|
));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -92,7 +92,7 @@ class IpValidator extends ConstraintValidator
|
|||||||
|
|
||||||
if (!filter_var($value, FILTER_VALIDATE_IP, $flag)) {
|
if (!filter_var($value, FILTER_VALIDATE_IP, $flag)) {
|
||||||
$this->context->addViolation($constraint->message, array(
|
$this->context->addViolation($constraint->message, array(
|
||||||
'{{ value }}' => $value,
|
'{{ value }}' => $this->formatValue($value),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,15 +51,15 @@ class IsbnValidator extends ConstraintValidator
|
|||||||
|
|
||||||
if ($constraint->isbn10 && $constraint->isbn13) {
|
if ($constraint->isbn10 && $constraint->isbn13) {
|
||||||
$this->context->addViolation($constraint->bothIsbnMessage, array(
|
$this->context->addViolation($constraint->bothIsbnMessage, array(
|
||||||
'{{ value }}' => $value,
|
'{{ value }}' => $this->formatValue($value),
|
||||||
));
|
));
|
||||||
} elseif ($constraint->isbn10) {
|
} elseif ($constraint->isbn10) {
|
||||||
$this->context->addViolation($constraint->isbn10Message, array(
|
$this->context->addViolation($constraint->isbn10Message, array(
|
||||||
'{{ value }}' => $value,
|
'{{ value }}' => $this->formatValue($value),
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
$this->context->addViolation($constraint->isbn13Message, array(
|
$this->context->addViolation($constraint->isbn13Message, array(
|
||||||
'{{ value }}' => $value,
|
'{{ value }}' => $this->formatValue($value),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ class IssnValidator extends ConstraintValidator
|
|||||||
|
|
||||||
if (!preg_match($pattern, $value)) {
|
if (!preg_match($pattern, $value)) {
|
||||||
$this->context->addViolation($constraint->message, array(
|
$this->context->addViolation($constraint->message, array(
|
||||||
'{{ value }}' => $value,
|
'{{ value }}' => $this->formatValue($value),
|
||||||
));
|
));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -64,7 +64,7 @@ class IssnValidator extends ConstraintValidator
|
|||||||
|
|
||||||
if (0 !== $checkSum % 11) {
|
if (0 !== $checkSum % 11) {
|
||||||
$this->context->addViolation($constraint->message, array(
|
$this->context->addViolation($constraint->message, array(
|
||||||
'{{ value }}' => $value,
|
'{{ value }}' => $this->formatValue($value),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ class LanguageValidator extends ConstraintValidator
|
|||||||
|
|
||||||
if (!isset($languages[$value])) {
|
if (!isset($languages[$value])) {
|
||||||
$this->context->addViolation($constraint->message, array(
|
$this->context->addViolation($constraint->message, array(
|
||||||
'{{ value }}' => $value,
|
'{{ value }}' => $this->formatValue($value),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ class LengthValidator extends ConstraintValidator
|
|||||||
|
|
||||||
if ($constraint->min == $constraint->max && $length != $constraint->min) {
|
if ($constraint->min == $constraint->max && $length != $constraint->min) {
|
||||||
$this->context->addViolation($constraint->exactMessage, array(
|
$this->context->addViolation($constraint->exactMessage, array(
|
||||||
'{{ value }}' => $stringValue,
|
'{{ value }}' => $this->formatValue($stringValue),
|
||||||
'{{ limit }}' => $constraint->min,
|
'{{ limit }}' => $constraint->min,
|
||||||
), $value, (int) $constraint->min);
|
), $value, (int) $constraint->min);
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ class LengthValidator extends ConstraintValidator
|
|||||||
|
|
||||||
if (null !== $constraint->max && $length > $constraint->max) {
|
if (null !== $constraint->max && $length > $constraint->max) {
|
||||||
$this->context->addViolation($constraint->maxMessage, array(
|
$this->context->addViolation($constraint->maxMessage, array(
|
||||||
'{{ value }}' => $stringValue,
|
'{{ value }}' => $this->formatValue($stringValue),
|
||||||
'{{ limit }}' => $constraint->max,
|
'{{ limit }}' => $constraint->max,
|
||||||
), $value, (int) $constraint->max);
|
), $value, (int) $constraint->max);
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ class LengthValidator extends ConstraintValidator
|
|||||||
|
|
||||||
if (null !== $constraint->min && $length < $constraint->min) {
|
if (null !== $constraint->min && $length < $constraint->min) {
|
||||||
$this->context->addViolation($constraint->minMessage, array(
|
$this->context->addViolation($constraint->minMessage, array(
|
||||||
'{{ value }}' => $stringValue,
|
'{{ value }}' => $this->formatValue($stringValue),
|
||||||
'{{ limit }}' => $constraint->min,
|
'{{ limit }}' => $constraint->min,
|
||||||
), $value, (int) $constraint->min);
|
), $value, (int) $constraint->min);
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ class LocaleValidator extends ConstraintValidator
|
|||||||
|
|
||||||
if (!isset($locales[$value])) {
|
if (!isset($locales[$value])) {
|
||||||
$this->context->addViolation($constraint->message, array(
|
$this->context->addViolation($constraint->message, array(
|
||||||
'{{ value }}' => $value,
|
'{{ value }}' => $this->formatValue($value),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ class LuhnValidator extends ConstraintValidator
|
|||||||
|
|
||||||
if (!ctype_digit($value)) {
|
if (!ctype_digit($value)) {
|
||||||
$this->context->addViolation($constraint->message, array(
|
$this->context->addViolation($constraint->message, array(
|
||||||
'{{ value }}' => $value,
|
'{{ value }}' => $this->formatValue($value),
|
||||||
));
|
));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -80,7 +80,7 @@ class LuhnValidator extends ConstraintValidator
|
|||||||
|
|
||||||
if (0 === $checkSum || 0 !== $checkSum % 10) {
|
if (0 === $checkSum || 0 !== $checkSum % 10) {
|
||||||
$this->context->addViolation($constraint->message, array(
|
$this->context->addViolation($constraint->message, array(
|
||||||
'{{ value }}' => $value,
|
'{{ value }}' => $this->formatValue($value),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ class NotBlankValidator extends ConstraintValidator
|
|||||||
{
|
{
|
||||||
if (false === $value || (empty($value) && '0' != $value)) {
|
if (false === $value || (empty($value) && '0' != $value)) {
|
||||||
$this->context->addViolation($constraint->message, array(
|
$this->context->addViolation($constraint->message, array(
|
||||||
'{{ value }}' => $this->valueToString($value),
|
'{{ value }}' => $this->formatValue($value),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ class NullValidator extends ConstraintValidator
|
|||||||
{
|
{
|
||||||
if (null !== $value) {
|
if (null !== $value) {
|
||||||
$this->context->addViolation($constraint->message, array(
|
$this->context->addViolation($constraint->message, array(
|
||||||
'{{ value }}' => $this->valueToString($value),
|
'{{ value }}' => $this->formatValue($value),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ class RangeValidator extends ConstraintValidator
|
|||||||
|
|
||||||
if (!is_numeric($value)) {
|
if (!is_numeric($value)) {
|
||||||
$this->context->addViolation($constraint->invalidMessage, array(
|
$this->context->addViolation($constraint->invalidMessage, array(
|
||||||
'{{ value }}' => $this->valueToString($value),
|
'{{ value }}' => $this->formatValue($value),
|
||||||
));
|
));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -42,7 +42,7 @@ class RegexValidator extends ConstraintValidator
|
|||||||
|
|
||||||
if ($constraint->match xor preg_match($constraint->pattern, $value)) {
|
if ($constraint->match xor preg_match($constraint->pattern, $value)) {
|
||||||
$this->context->addViolation($constraint->message, array(
|
$this->context->addViolation($constraint->message, array(
|
||||||
'{{ value }}' => $value,
|
'{{ value }}' => $this->formatValue($value),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ class TimeValidator extends ConstraintValidator
|
|||||||
|
|
||||||
if (!preg_match(static::PATTERN, $value)) {
|
if (!preg_match(static::PATTERN, $value)) {
|
||||||
$this->context->addViolation($constraint->message, array(
|
$this->context->addViolation($constraint->message, array(
|
||||||
'{{ value }}' => $value,
|
'{{ value }}' => $this->formatValue($value),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ class TrueValidator extends ConstraintValidator
|
|||||||
|
|
||||||
if (true !== $value && 1 !== $value && '1' !== $value) {
|
if (true !== $value && 1 !== $value && '1' !== $value) {
|
||||||
$this->context->addViolation($constraint->message, array(
|
$this->context->addViolation($constraint->message, array(
|
||||||
'{{ value }}' => $this->valueToString($value),
|
'{{ value }}' => $this->formatValue($value),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ class TypeValidator extends ConstraintValidator
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->context->addViolation($constraint->message, array(
|
$this->context->addViolation($constraint->message, array(
|
||||||
'{{ value }}' => $this->valueToString($value),
|
'{{ value }}' => $this->formatValue($value),
|
||||||
'{{ type }}' => $constraint->type,
|
'{{ type }}' => $constraint->type,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -51,12 +51,11 @@ class UrlValidator extends ConstraintValidator
|
|||||||
}
|
}
|
||||||
|
|
||||||
$value = (string) $value;
|
$value = (string) $value;
|
||||||
|
|
||||||
$pattern = sprintf(static::PATTERN, implode('|', $constraint->protocols));
|
$pattern = sprintf(static::PATTERN, implode('|', $constraint->protocols));
|
||||||
|
|
||||||
if (!preg_match($pattern, $value)) {
|
if (!preg_match($pattern, $value)) {
|
||||||
$this->context->addViolation($constraint->message, array(
|
$this->context->addViolation($constraint->message, array(
|
||||||
'{{ value }}' => $value,
|
'{{ value }}' => $this->formatValue($value),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -147,7 +147,7 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->context->expects($this->once())
|
$this->context->expects($this->once())
|
||||||
->method('addViolationAt')
|
->method('addViolationAt')
|
||||||
->with('[baz]', 'myMessage', array(
|
->with('[baz]', 'myMessage', array(
|
||||||
'{{ field }}' => 'baz'
|
'{{ field }}' => '"baz"'
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->validator->validate($data, new Collection(array(
|
$this->validator->validate($data, new Collection(array(
|
||||||
@ -211,7 +211,7 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->context->expects($this->once())
|
$this->context->expects($this->once())
|
||||||
->method('addViolationAt')
|
->method('addViolationAt')
|
||||||
->with('[foo]', 'myMessage', array(
|
->with('[foo]', 'myMessage', array(
|
||||||
'{{ field }}' => 'foo',
|
'{{ field }}' => '"foo"',
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->validator->validate($data, $constraint);
|
$this->validator->validate($data, $constraint);
|
||||||
@ -331,7 +331,7 @@ abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->context->expects($this->once())
|
$this->context->expects($this->once())
|
||||||
->method('addViolationAt')
|
->method('addViolationAt')
|
||||||
->with('[foo]', 'myMessage', array(
|
->with('[foo]', 'myMessage', array(
|
||||||
'{{ field }}' => 'foo',
|
'{{ field }}' => '"foo"',
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->validator->validate($data, new Collection(array(
|
$this->validator->validate($data, new Collection(array(
|
||||||
|
@ -96,7 +96,7 @@ class DateTimeValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->context->expects($this->once())
|
$this->context->expects($this->once())
|
||||||
->method('addViolation')
|
->method('addViolation')
|
||||||
->with('myMessage', array(
|
->with('myMessage', array(
|
||||||
'{{ value }}' => $dateTime,
|
'{{ value }}' => '"'.$dateTime.'"',
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->validator->validate($dateTime, $constraint);
|
$this->validator->validate($dateTime, $constraint);
|
||||||
|
@ -96,7 +96,7 @@ class DateValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->context->expects($this->once())
|
$this->context->expects($this->once())
|
||||||
->method('addViolation')
|
->method('addViolation')
|
||||||
->with('myMessage', array(
|
->with('myMessage', array(
|
||||||
'{{ value }}' => $date,
|
'{{ value }}' => '"'.$date.'"',
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->validator->validate($date, $constraint);
|
$this->validator->validate($date, $constraint);
|
||||||
|
@ -88,7 +88,7 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->context->expects($this->once())
|
$this->context->expects($this->once())
|
||||||
->method('addViolation')
|
->method('addViolation')
|
||||||
->with('myMessage', array(
|
->with('myMessage', array(
|
||||||
'{{ value }}' => $email,
|
'{{ value }}' => '"'.$email.'"',
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->validator->validate($email, $constraint);
|
$this->validator->validate($email, $constraint);
|
||||||
|
@ -29,7 +29,7 @@ class FileValidatorPathTest extends FileValidatorTest
|
|||||||
$this->context->expects($this->once())
|
$this->context->expects($this->once())
|
||||||
->method('addViolation')
|
->method('addViolation')
|
||||||
->with('myMessage', array(
|
->with('myMessage', array(
|
||||||
'{{ file }}' => 'foobar',
|
'{{ file }}' => '"foobar"',
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->validator->validate('foobar', $constraint);
|
$this->validator->validate('foobar', $constraint);
|
||||||
|
@ -101,7 +101,7 @@ abstract class FileValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
'{{ limit }}' => '10',
|
'{{ limit }}' => '10',
|
||||||
'{{ size }}' => '11',
|
'{{ size }}' => '11',
|
||||||
'{{ suffix }}' => 'bytes',
|
'{{ suffix }}' => 'bytes',
|
||||||
'{{ file }}' => $this->path,
|
'{{ file }}' => '"'.$this->path.'"',
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->validator->validate($this->getFile($this->path), $constraint);
|
$this->validator->validate($this->getFile($this->path), $constraint);
|
||||||
@ -122,7 +122,7 @@ abstract class FileValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
'{{ limit }}' => '1',
|
'{{ limit }}' => '1',
|
||||||
'{{ size }}' => '1.4',
|
'{{ size }}' => '1.4',
|
||||||
'{{ suffix }}' => 'kB',
|
'{{ suffix }}' => 'kB',
|
||||||
'{{ file }}' => $this->path,
|
'{{ file }}' => '"'.$this->path.'"',
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->validator->validate($this->getFile($this->path), $constraint);
|
$this->validator->validate($this->getFile($this->path), $constraint);
|
||||||
@ -143,7 +143,7 @@ abstract class FileValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
'{{ limit }}' => '1',
|
'{{ limit }}' => '1',
|
||||||
'{{ size }}' => '1.4',
|
'{{ size }}' => '1.4',
|
||||||
'{{ suffix }}' => 'MB',
|
'{{ suffix }}' => 'MB',
|
||||||
'{{ file }}' => $this->path,
|
'{{ file }}' => '"'.$this->path.'"',
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->validator->validate($this->getFile($this->path), $constraint);
|
$this->validator->validate($this->getFile($this->path), $constraint);
|
||||||
@ -245,7 +245,7 @@ abstract class FileValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
->with('myMessage', array(
|
->with('myMessage', array(
|
||||||
'{{ type }}' => '"application/pdf"',
|
'{{ type }}' => '"application/pdf"',
|
||||||
'{{ types }}' => '"image/png", "image/jpg"',
|
'{{ types }}' => '"image/png", "image/jpg"',
|
||||||
'{{ file }}' => $this->path,
|
'{{ file }}' => '"'.$this->path.'"',
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->validator->validate($file, $constraint);
|
$this->validator->validate($file, $constraint);
|
||||||
@ -279,7 +279,7 @@ abstract class FileValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
->with('myMessage', array(
|
->with('myMessage', array(
|
||||||
'{{ type }}' => '"application/pdf"',
|
'{{ type }}' => '"application/pdf"',
|
||||||
'{{ types }}' => '"image/*", "image/jpg"',
|
'{{ types }}' => '"image/*", "image/jpg"',
|
||||||
'{{ file }}' => $this->path,
|
'{{ file }}' => '"'.$this->path.'"',
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->validator->validate($file, $constraint);
|
$this->validator->validate($file, $constraint);
|
||||||
|
@ -164,7 +164,7 @@ class IbanValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->context->expects($this->once())
|
$this->context->expects($this->once())
|
||||||
->method('addViolation')
|
->method('addViolation')
|
||||||
->with('myMessage', array(
|
->with('myMessage', array(
|
||||||
'{{ value }}' => $iban,
|
'{{ value }}' => '"'.$iban.'"',
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->validator->validate($iban, $constraint);
|
$this->validator->validate($iban, $constraint);
|
||||||
|
@ -162,7 +162,7 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->context->expects($this->once())
|
$this->context->expects($this->once())
|
||||||
->method('addViolation')
|
->method('addViolation')
|
||||||
->with('myMessage', array(
|
->with('myMessage', array(
|
||||||
'{{ value }}' => $ip,
|
'{{ value }}' => '"'.$ip.'"',
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->validator->validate($ip, $constraint);
|
$this->validator->validate($ip, $constraint);
|
||||||
@ -196,7 +196,7 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->context->expects($this->once())
|
$this->context->expects($this->once())
|
||||||
->method('addViolation')
|
->method('addViolation')
|
||||||
->with('myMessage', array(
|
->with('myMessage', array(
|
||||||
'{{ value }}' => $ip,
|
'{{ value }}' => '"'.$ip.'"',
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->validator->validate($ip, $constraint);
|
$this->validator->validate($ip, $constraint);
|
||||||
@ -224,7 +224,7 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->context->expects($this->once())
|
$this->context->expects($this->once())
|
||||||
->method('addViolation')
|
->method('addViolation')
|
||||||
->with('myMessage', array(
|
->with('myMessage', array(
|
||||||
'{{ value }}' => $ip,
|
'{{ value }}' => '"'.$ip.'"',
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->validator->validate($ip, $constraint);
|
$this->validator->validate($ip, $constraint);
|
||||||
@ -252,7 +252,7 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->context->expects($this->once())
|
$this->context->expects($this->once())
|
||||||
->method('addViolation')
|
->method('addViolation')
|
||||||
->with('myMessage', array(
|
->with('myMessage', array(
|
||||||
'{{ value }}' => $ip,
|
'{{ value }}' => '"'.$ip.'"',
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->validator->validate($ip, $constraint);
|
$this->validator->validate($ip, $constraint);
|
||||||
@ -276,7 +276,7 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->context->expects($this->once())
|
$this->context->expects($this->once())
|
||||||
->method('addViolation')
|
->method('addViolation')
|
||||||
->with('myMessage', array(
|
->with('myMessage', array(
|
||||||
'{{ value }}' => $ip,
|
'{{ value }}' => '"'.$ip.'"',
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->validator->validate($ip, $constraint);
|
$this->validator->validate($ip, $constraint);
|
||||||
@ -314,7 +314,7 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->context->expects($this->once())
|
$this->context->expects($this->once())
|
||||||
->method('addViolation')
|
->method('addViolation')
|
||||||
->with('myMessage', array(
|
->with('myMessage', array(
|
||||||
'{{ value }}' => $ip,
|
'{{ value }}' => '"'.$ip.'"',
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->validator->validate($ip, $constraint);
|
$this->validator->validate($ip, $constraint);
|
||||||
@ -342,7 +342,7 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->context->expects($this->once())
|
$this->context->expects($this->once())
|
||||||
->method('addViolation')
|
->method('addViolation')
|
||||||
->with('myMessage', array(
|
->with('myMessage', array(
|
||||||
'{{ value }}' => $ip,
|
'{{ value }}' => '"'.$ip.'"',
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->validator->validate($ip, $constraint);
|
$this->validator->validate($ip, $constraint);
|
||||||
@ -369,7 +369,7 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->context->expects($this->once())
|
$this->context->expects($this->once())
|
||||||
->method('addViolation')
|
->method('addViolation')
|
||||||
->with('myMessage', array(
|
->with('myMessage', array(
|
||||||
'{{ value }}' => $ip,
|
'{{ value }}' => '"'.$ip.'"',
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->validator->validate($ip, $constraint);
|
$this->validator->validate($ip, $constraint);
|
||||||
@ -393,7 +393,7 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->context->expects($this->once())
|
$this->context->expects($this->once())
|
||||||
->method('addViolation')
|
->method('addViolation')
|
||||||
->with('myMessage', array(
|
->with('myMessage', array(
|
||||||
'{{ value }}' => $ip,
|
'{{ value }}' => '"'.$ip.'"',
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->validator->validate($ip, $constraint);
|
$this->validator->validate($ip, $constraint);
|
||||||
@ -417,7 +417,7 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->context->expects($this->once())
|
$this->context->expects($this->once())
|
||||||
->method('addViolation')
|
->method('addViolation')
|
||||||
->with('myMessage', array(
|
->with('myMessage', array(
|
||||||
'{{ value }}' => $ip,
|
'{{ value }}' => '"'.$ip.'"',
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->validator->validate($ip, $constraint);
|
$this->validator->validate($ip, $constraint);
|
||||||
@ -441,7 +441,7 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->context->expects($this->once())
|
$this->context->expects($this->once())
|
||||||
->method('addViolation')
|
->method('addViolation')
|
||||||
->with('myMessage', array(
|
->with('myMessage', array(
|
||||||
'{{ value }}' => $ip,
|
'{{ value }}' => '"'.$ip.'"',
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->validator->validate($ip, $constraint);
|
$this->validator->validate($ip, $constraint);
|
||||||
@ -465,7 +465,7 @@ class IpValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->context->expects($this->once())
|
$this->context->expects($this->once())
|
||||||
->method('addViolation')
|
->method('addViolation')
|
||||||
->with('myMessage', array(
|
->with('myMessage', array(
|
||||||
'{{ value }}' => $ip,
|
'{{ value }}' => '"'.$ip.'"',
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->validator->validate($ip, $constraint);
|
$this->validator->validate($ip, $constraint);
|
||||||
|
@ -167,7 +167,7 @@ class LengthValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->context->expects($this->once())
|
$this->context->expects($this->once())
|
||||||
->method('addViolation')
|
->method('addViolation')
|
||||||
->with('myMessage', $this->identicalTo(array(
|
->with('myMessage', $this->identicalTo(array(
|
||||||
'{{ value }}' => (string) $value,
|
'{{ value }}' => '"'.$value.'"',
|
||||||
'{{ limit }}' => 4,
|
'{{ limit }}' => 4,
|
||||||
)), $this->identicalTo($value), 4);
|
)), $this->identicalTo($value), 4);
|
||||||
|
|
||||||
@ -191,7 +191,7 @@ class LengthValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->context->expects($this->once())
|
$this->context->expects($this->once())
|
||||||
->method('addViolation')
|
->method('addViolation')
|
||||||
->with('myMessage', $this->identicalTo(array(
|
->with('myMessage', $this->identicalTo(array(
|
||||||
'{{ value }}' => (string) $value,
|
'{{ value }}' => '"'.$value.'"',
|
||||||
'{{ limit }}' => 4,
|
'{{ limit }}' => 4,
|
||||||
)), $this->identicalTo($value), 4);
|
)), $this->identicalTo($value), 4);
|
||||||
|
|
||||||
@ -216,7 +216,7 @@ class LengthValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->context->expects($this->once())
|
$this->context->expects($this->once())
|
||||||
->method('addViolation')
|
->method('addViolation')
|
||||||
->with('myMessage', $this->identicalTo(array(
|
->with('myMessage', $this->identicalTo(array(
|
||||||
'{{ value }}' => (string) $value,
|
'{{ value }}' => '"'.$value.'"',
|
||||||
'{{ limit }}' => 4,
|
'{{ limit }}' => 4,
|
||||||
)), $this->identicalTo($value), 4);
|
)), $this->identicalTo($value), 4);
|
||||||
|
|
||||||
|
@ -234,4 +234,19 @@ class RangeValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$this->validator->validate(21, $constraint);
|
$this->validator->validate(21, $constraint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testNonNumeric()
|
||||||
|
{
|
||||||
|
$this->context->expects($this->once())
|
||||||
|
->method('addViolation')
|
||||||
|
->with('myMessage', array(
|
||||||
|
'{{ value }}' => '"abcd"',
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->validator->validate('abcd', new Range(array(
|
||||||
|
'min' => 10,
|
||||||
|
'max' => 20,
|
||||||
|
'invalidMessage' => 'myMessage',
|
||||||
|
)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ class RegexValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->context->expects($this->once())
|
$this->context->expects($this->once())
|
||||||
->method('addViolation')
|
->method('addViolation')
|
||||||
->with('myMessage', array(
|
->with('myMessage', array(
|
||||||
'{{ value }}' => $value,
|
'{{ value }}' => '"'.$value.'"',
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->validator->validate($value, $constraint);
|
$this->validator->validate($value, $constraint);
|
||||||
|
@ -96,7 +96,7 @@ class TimeValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->context->expects($this->once())
|
$this->context->expects($this->once())
|
||||||
->method('addViolation')
|
->method('addViolation')
|
||||||
->with('myMessage', array(
|
->with('myMessage', array(
|
||||||
'{{ value }}' => $time,
|
'{{ value }}' => '"'.$time.'"',
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->validator->validate($time, $constraint);
|
$this->validator->validate($time, $constraint);
|
||||||
|
@ -131,7 +131,7 @@ class UrlValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->context->expects($this->once())
|
$this->context->expects($this->once())
|
||||||
->method('addViolation')
|
->method('addViolation')
|
||||||
->with('myMessage', array(
|
->with('myMessage', array(
|
||||||
'{{ value }}' => $url,
|
'{{ value }}' => '"'.$url.'"',
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->validator->validate($url, $constraint);
|
$this->validator->validate($url, $constraint);
|
||||||
|
Reference in New Issue
Block a user