8000 [Validator] Code property can't be populated to ConstraintViolation by aeoris · Pull Request #7276 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Validator] Code property can't be populated to ConstraintViolation #7276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Pass the invalid value to addViolation and added some tests
  • Loading branch information
aeoris committed Mar 6, 2013
commit 28ff374dd083c9eefb73a9618bada27f54b3dd06
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class BlankValidator extends ConstraintValidator
public function validate($value, Constraint $constraint)
{
if ('' !== $value && null !== $value) {
$this->context->addViolation($constraint->message, array('{{ value }}' => $value), null, null, $constraint->code);
$this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint->code);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function validate($value, Constraint $constraint)
}

if (!is_numeric($value)) {
$this->context->addViolation($constraint->message, array(), null, null, $constraint->code);
$this->context->addViolation($constraint->message, array(), $value, null, $constraint->code);

return;
}
Expand All @@ -124,6 +124,6 @@ public function validate($value, Constraint $constraint)
}
}

$this->context->addViolation($constraint->message, array(), null, null, $constraint->code);
$this->context->addViolation($constraint->message, array(), $value, null, $constraint->code);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function validate($value, Constraint $constraint)
if ($constraint->multiple) {
foreach ($value as $_value) {
if (!in_array($_value, $choices, $constraint->strict)) {
$this->context->addViolation($constraint->multipleMessage, array('{{ value }}' => $_value), null, null, $constraint->code);
$this->context->addViolation($constraint->multipleMessage, array('{{ value }}' => $_value), $_value, null, $constraint->code);
}
}

Expand All @@ -77,7 +77,7 @@ public function validate($value, Constraint $constraint)
return;
}
} elseif (!in_array($value, $choices, $constraint->strict)) {
$this->context->addViolation($constraint->message, array('{{ value }}' => $value), null, null, $constraint->code);
$this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint->code);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function validate($value, Constraint $constraint)
} elseif (!$fieldConstraint instanceof Optional && !$constraint->allowMissingFields) {
$this->context->addViolationAt('['.$field.']', $constraint->missingFieldsMessage, array(
'{{ field }}' => $field
), null, $constraint->code);
), $field, $constraint->code);
}
}

Expand All @@ -59,7 +59,7 @@ public function validate($value, Constraint $constraint)
if (!isset($constraint->fields[$field])) {
$this->context->addViolationAt('['.$field.']', $constraint->extraFieldsMessage, array(
'{{ field }}' => $field
), $fieldValue, null, $constraint->code);
), $field, null, $constraint->code);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function validate($value, Constraint $constraint)
$value = (string) $value;

if (!in_array($value, \Symfony\Component\Locale\Locale::getCountries())) {
$this->context->addViolation($constraint->message, array('{{ value }}' => $value), null, null, $constraint->code);
$this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint->code);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function validate($value, Constraint $constraint)
$value = (string) $value;

if (!preg_match(static::PATTERN, $value, $matches) || !checkdate($matches[2], $matches[3], $matches[1])) {
$this->context->addViolation($constraint->message, array('{{ value }}' => $value), null, null, $constraint->code);
$this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint->code);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function validate($value, Constraint $constraint)
}

if (!$valid) {
$this->context->addViolation($constraint->message, array('{{ value }}' => $value), null, null, $constraint->code);
$this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint->code);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ public function validate($value, Constraint $constraint)
return;
}

$this->context->addViolation($constraint->message, array(), null, null, $constraint->code);
$this->context->addViolation($constraint->message, array(), $value, null, $constraint->code);
}
}
24 changes: 12 additions & 12 deletions src/Symfony/Component/Validator/Constraints/FileValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,35 +42,35 @@ public function validate($value, Constraint $constraint)
$this->context->addViolation($constraint->uploadIniSizeErrorMessage, array(
'{{ limit }}' => $maxSize,
'{{ suffix }}' => 'bytes',
), null, null, $constraint->code);
), $value, null, $constraint->code);

return;
case UPLOAD_ERR_FORM_SIZE:
$this->context->addViolation($constraint->uploadFormSizeErrorMessage, array(), null, null, $constraint->code);
$this->context->addViolation($constraint->uploadFormSizeErrorMessage, array(), $value, null, $constraint->code);

return;
case UPLOAD_ERR_PARTIAL:
$this->context->addViolation($constraint->uploadPartialErrorMessage, array(), null, null, $constraint->code);
$this->context->addViolation($constraint->uploadPartialErrorMessage, array(), $value, null, $constraint->code);

return;
case UPLOAD_ERR_NO_FILE:
$this->context->addViolation($constraint->uploadNoFileErrorMessage, array(), null, null, $constraint->code);
$this->context->addViolation($constraint->uploadNoFileErrorMessage, array(), $value, null, $constraint->code);

return;
case UPLOAD_ERR_NO_TMP_DIR:
$this->context->addViolation($constraint->uploadNoTmpDirErrorMessage, array(), null, null, $constraint->code);
$this->context->addViolation($constraint->uploadNoTmpDirErrorMessage, array(), $value, null, $constraint->code);

return;
case UPLOAD_ERR_CANT_WRITE:
$this->context->addViolation($constraint->uploadCantWriteErrorMessage, array(), null, null, $constraint->code);
$this->context->addViolation($constraint->uploadCantWriteErrorMessage, array(), $value, null, $constraint->code);

return;
case UPLOAD_ERR_EXTENSION:
$this->context->addViolation($constraint->uploadExtensionErrorMessage, array(), null, null, $constraint->code);
$this->context->addViolation($constraint->uploadExtensionErrorMessage, array(), $value, null, $constraint->code);

return;
default:
$this->context->addViolation($constraint->uploadErrorMessage, array(), null, null, $constraint->code);
$this->context->addViolation($constraint->uploadErrorMessage, array(), $value, null, $constraint->code);

return;
}
Expand All @@ -83,13 +83,13 @@ public function validate($value, Constraint $constraint)
$path = $value instanceof FileObject ? $value->getPathname() : (string) $value;

if (!is_file($path)) {
$this->context->addViolation($constraint->notFoundMessage, array('{{ file }}' => $path), null, null, $constraint->code);
$this->context->addViolation($constraint->notFoundMessage, array('{{ file }}' => $path), $value, null, $constraint->code);

return;
}

if (!is_readable($path)) {
$this->context->addViolation($constraint->notReadableMessage, array('{{ file }}' => $path), null, null, $constraint->code);
$this->context->addViolation($constraint->notReadableMessage, array('{{ file }}' => $path), $value, null, $constraint->code);

return;
}
Expand Down Expand Up @@ -117,7 +117,7 @@ public function validate($value, Constraint $constraint)
'{{ limit }}' => $limit,
'{{ suffix }}' => $suffix,
'{{ file }}' => $path,
), null, null, $constraint->code);
), $value, null, $constraint->code);

return;
}
Expand Down Expand Up @@ -151,7 +151,7 @@ public function validate($value, Constraint $constraint)
'{{ type }}' => '"'.$mime.'"',
'{{ types }}' => '"'.implode('", "', $mimeTypes) .'"',
'{{ file }}' => $path,
), null, null, $constraint->code);
), $value, null, $constraint->code);
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/Symfony/Component/Validator/Constraints/ImageValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function validate($value, Constraint $constraint)

$size = @getimagesize($value);
if (empty($size) || ($size[0] === 0) || ($size[1] === 0)) {
$this->context->addViolation($constraint->sizeNotDetectedMessage, array(), null, null, $constraint->code);
$this->context->addViolation($constraint->sizeNotDetectedMessage, array(), $value, null, $constraint->code);

return;
}
Expand All @@ -61,7 +61,7 @@ public function validate($value, Constraint $constraint)
$this->context->addViolation($constraint->minWidthMessage, array(
'{{ width }}' => $width,
'{{ min_width }}' => $constraint->minWidth
), null, null, $constraint->code);
), $value, null, $constraint->code);

return;
}
Expand All @@ -76,7 +76,7 @@ public function validate($value, Constraint $constraint)
$this->context->addViolation($constraint->maxWidthMessage, array(
'{{ width }}' => $width,
'{{ max_width }}' => $constraint->maxWidth
), null, null, $constraint->code);
), $value, null, $constraint->code);

return;
}
Expand All @@ -91,7 +91,7 @@ public function validate($value, Constraint $constraint)
$this->context->addViolation($constraint->minHeightMessage, array(
'{{ height }}' => $height,
'{{ min_height }}' => $constraint->minHeight
), null, null, $constraint->code);
), $value, null, $constraint->code);

return;
}
Expand All @@ -106,7 +106,7 @@ public function validate($value, Constraint $constraint)
$this->context->addViolation($constraint->maxHeightMessage, array(
'{{ height }}' => $height,
'{{ max_height }}' => $constraint->maxHeight
), null, null, $constraint->code);
), $value, null, $constraint->code);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function validate($value, Constraint $constraint)
}

if (!filter_var($value, FILTER_VALIDATE_IP, $flag)) {
$this->context->addViolation($constraint->message, array('{{ value }}' => $value), null, null, $constraint->code);
$this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint->code);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function validate($value, Constraint $constraint)
$value = (string) $value;

if (!in_array($value, \Symfony\Component\Locale\Locale::getLanguages())) {
$this->context->addViolation($constraint->message, array('{{ value }}' => $value), null, null, $constraint->code);
$this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint->code);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function validate($value, Constraint $constraint)
$value = (string) $value;

if (!in_array($value, \Symfony\Component\Locale\Locale::getLocales())) {
$this->context->addViolation($constraint->message, array('{{ value }}' => $value), null, null, $constraint->code);
$this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint->code);
}
}
}
4 changes: 2 additions & 2 deletions src/Symfony/Component/Validator/Constraints/LuhnValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function validate($value, Constraint $constraint)
}

if (!is_numeric($value)) {
$this->context->addViolation($constraint->message, array(), null, null, $constraint->code);
$this->context->addViolation($constraint->message, array(), $value, null, $constraint->code);

return;
}
Expand All @@ -52,7 +52,7 @@ public function validate($value, Constraint $constraint)
}

if ($sum === 0 || ($sum % 10) !== 0) {
$this->context->addViolation($constraint->message, array(), null, null, $constraint->code);
$this->context->addViolation($constraint->message, array(), $value, null, $constraint->code);
}
}
}
4 changes: 2 additions & 2 deletions src/Symfony/Component/Validator/Constraints/MaxValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function validate($value, Constraint $constraint)
$this->context->addViolation($constraint->invalidMessage, array(
'{{ value }}' => $value,
'{{ limit }}' => $constraint->limit,
), null, null, $constraint->code);
), $value, null, $constraint->code);

return;
}
Expand All @@ -50,7 +50,7 @@ public function validate($value, Constraint $constraint)
$this->context->addViolation($constraint->message, array(
'{{ value }}' => $value,
'{{ limit }}' => $constraint->limit,
), null, null, $constraint->code);
), $value, null, $constraint->code);
}
}
}
4 changes: 2 additions & 2 deletions src/Symfony/Component/Validator/Constraints/MinValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function validate($value, Constraint $constraint)
$this->context->addViolation($constraint->invalidMessage, array(
'{{ value }}' => $value,
'{{ limit }}' => $constraint->limit,
), null, null, $constraint->code);
), $value, null, $constraint->code);

return;
}
Expand All @@ -55,7 +55,7 @@ public function validate($value, Constraint $constraint)
$this->context->addViolation($constraint->message, array(
'{{ value }}' => $value,
'{{ limit }}' => $constraint->limit,
), null, null, $constraint->code);
), $value, null, $constraint->code);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class NotBlankValidator extends ConstraintValidator
public function validate($value, Constraint $constraint)
{
if (false === $value || (empty($value) && '0' != $value)) {
$this->context->addViolation($constraint->message, array(), null, null, $constraint->code);
$this->context->addViolation($constraint->message, array(), $value, null, $constraint->code);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class NotNullValidator extends ConstraintValidator
public function validate($value, Constraint $constraint)
{
if (null === $value) {
$this->context->addViolation($constraint->message, array(), null, null, $constraint->code);
$this->context->addViolation($constraint->message, array(), $value, null, $constraint->code);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class NullValidator extends ConstraintValidator
public function validate($value, Constraint $constraint)
{
if (null !== $value) {
$this->context->addViolation($constraint->message, array('{{ value }}' => $value), null, null, $constraint->code);
$this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint->code);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function validate($value, Constraint $constraint)
if (!is_numeric($value)) {
$this->context->addViolation($constraint->invalidMessage, array(
'{{ value }}' => $value,
), null, null, $constraint->code);
), $value, null, $constraint->code);

return;
}
Expand All @@ -40,7 +40,7 @@ public function validate($value, Constraint $constraint)
$this->context->addViolation($constraint->maxMessage, array(
'{{ value }}' => $value,
'{{ limit }}' => $constraint->max,
), null, null, $constraint->code);
), $value, null, $constraint->code);

return;
}
Expand All @@ -49,7 +49,7 @@ public function validate($value, Constraint $constraint)
$this->context->addViolation($constraint->minMessage, array(
'{{ value }}' => $value,
'{{ limit }}' => $constraint->min,
), null, null, $constraint->code);
), $value, null, $constraint->code);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function validate($value, Constraint $constraint)
$value = (string) $value;

if ($constraint->match xor preg_match($constraint->pattern, $value)) {
$this->context->addViolation($constraint->message, array('{{ value }}' => $value), null, null, $constraint->code);
$this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint->code);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function validate($value, Constraint $constraint)
$value = (string) $value;

if (!preg_match(static::PATTERN, $value)) {
$this->context->addViolation($constraint->message, array('{{ value }}' => $value), null, null, $constraint->code);
$this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint->code);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function validate($value, Constraint $constraint)
}

if (true !== $value && 1 !== $value && '1' !== $value) {
$this->context->addViolation($constraint->message, array(), null, null, $constraint->code);
$this->context->addViolation($constraint->message, array(), $value, null, $constraint->code);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ public function validate($value, Constraint $constraint)
$this->context->addViolation($constraint->message, array(
'{{ value }}' => is_object($value) ? get_class($value) : (is_array($value) ? 'Array' : (string) $value),
'{{ type }}' => $constraint->type,
), null, null, $constraint->code);
), $value, null, $constraint->code);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function validate($value, Constraint $constraint)
$pattern = sprintf(static::PATTERN, implode('|', $constraint->protocols));

if (!preg_match($pattern, $value)) {
$this->context->addViolation($constraint->message, array('{{ value }}' => $value), null, null, $constraint->code);
$this->context->addViolation($constraint->message, array('{{ value }}' => $value), $value, null, $constraint->code);
}
}
}
Loading
0