Skip to content

Commit 8fd32ba

Browse files
committed
[Validator] remove the API_VERSION
1 parent 2a6b629 commit 8fd32ba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+20
-1012
lines changed

src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
2323
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntityValidator;
2424
use Symfony\Component\Validator\Tests\Constraints\AbstractConstraintValidatorTest;
25-
use Symfony\Component\Validator\Validation;
2625
use Doctrine\ORM\Tools\SchemaTool;
2726

2827
/**
@@ -47,11 +46,6 @@ class UniqueEntityValidatorTest extends AbstractConstraintValidatorTest
4746
*/
4847
protected $repository;
4948

50-
protected function getApiVersion()
51-
{
52-
return Validation::API_VERSION_2_5;
53-
}
54-
5549
protected function setUp()
5650
{
5751
$this->em = DoctrineTestHelper::createTestEntityManager();

src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
use Symfony\Component\Validator\Constraints\NotBlank;
2323
use Symfony\Component\Validator\Constraints\Valid;
2424
use Symfony\Component\Validator\Tests\Constraints\AbstractConstraintValidatorTest;
25-
use Symfony\Component\Validator\Validation;
2625

2726
/**
2827
* @author Bernhard Schussek <bschussek@gmail.com>
@@ -56,11 +55,6 @@ protected function setUp()
5655
parent::setUp();
5756
}
5857

59-
protected function getApiVersion()
60-
{
61-
return Validation::API_VERSION_2_5;
62-
}
63-
6458
protected function createValidator()
6559
{
6660
return new FormValidator($this->serverParams);

src/Symfony/Component/Validator/Constraints/AllValidator.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use Symfony\Component\Validator\Constraint;
1515
use Symfony\Component\Validator\ConstraintValidator;
16-
use Symfony\Component\Validator\Context\ExecutionContextInterface;
1716
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
1817

1918
/**
@@ -40,17 +39,10 @@ public function validate($value, Constraint $constraint)
4039

4140
$context = $this->context;
4241

43-
if ($context instanceof ExecutionContextInterface) {
44-
$validator = $context->getValidator()->inContext($context);
45-
46-
foreach ($value as $key => $element) {
47-
$validator->atPath('['.$key.']')->validate($element, $constraint->constraints);
48-
}
49-
} else {
50-
// 2.4 API
51-
foreach ($value as $key => $element) {
52-
$context->validateValue($element, $constraint->constraints, '['.$key.']');
53-
}
42+
$validator = $context->getValidator()->inContext($context);
43+
44+
foreach ($value as $key => $element) {
45+
$validator->atPath('['.$key.']')->validate($element, $constraint->constraints);
5446
}
5547
}
5648
}

src/Symfony/Component/Validator/Constraints/CollectionValidator.php

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use Symfony\Component\Validator\Constraint;
1515
use Symfony\Component\Validator\ConstraintValidator;
16-
use Symfony\Component\Validator\Context\ExecutionContextInterface;
1716
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
1817

1918
/**
@@ -56,53 +55,30 @@ public function validate($value, Constraint $constraint)
5655

5756
if ($existsInArray || $existsInArrayAccess) {
5857
if (count($fieldConstraint->constraints) > 0) {
59-
if ($context instanceof ExecutionContextInterface) {
60-
$context->getValidator()
61-
->inContext($context)
62-
->atPath('['.$field.']')
63-
->validate($value[$field], $fieldConstraint->constraints);
64-
} else {
65-
// 2.4 API
66-
$context->validateValue($value[$field], $fieldConstraint->constraints, '['.$field.']');
67-
}
68-
}
69-
} elseif (!$fieldConstraint instanceof Optional && !$constraint->allowMissingFields) {
70-
if ($context instanceof ExecutionContextInterface) {
71-
$context->buildViolation($constraint->missingFieldsMessage)
72-
->atPath('['.$field.']')
73-
->setParameter('{{ field }}', $this->formatValue($field))
74-
->setInvalidValue(null)
75-
->setCode(Collection::MISSING_FIELD_ERROR)
76-
->addViolation();
77-
} else {
78-
$this->buildViolationInContext($context, $constraint->missingFieldsMessage)
58+
$context->getValidator()
59+
->inContext($context)
7960
->atPath('['.$field.']')
80-
->setParameter('{{ field }}', $this->formatValue($field))
81-
->setInvalidValue(null)
82-
->setCode(Collection::MISSING_FIELD_ERROR)
83-
->addViolation();
61+
->validate($value[$field], $fieldConstraint->constraints);
8462
}
63+
} elseif (!$fieldConstraint instanceof Optional && !$constraint->allowMissingFields) {
64+
$context->buildViolation($constraint->missingFieldsMessage)
65+
->atPath('['.$field.']')
66+
->setParameter('{{ field }}', $this->formatValue($field))
67+
->setInvalidValue(null)
68+
->setCode(Collection::MISSING_FIELD_ERROR)
69+
->addViolation();
8570
}
8671
}
8772

8873
if (!$constraint->allowExtraFields) {
8974
foreach ($value as $field => $fieldValue) {
9075
if (!isset($constraint->fields[$field])) {
91-
if ($context instanceof ExecutionContextInterface) {
92-
$context->buildViolation($constraint->extraFieldsMessage)
93-
->atPath('['.$field.']')
94-
->setParameter('{{ field }}', $this->formatValue($field))
95-
->setInvalidValue($fieldValue)
96-
->setCode(Collection::NO_SUCH_FIELD_ERROR)
97-
->addViolation();
98-
} else {
99-
$this->buildViolationInContext($context, $constraint->extraFieldsMessage)
100-
->atPath('['.$field.']')
101-
->setParameter('{{ field }}', $this->formatValue($field))
102-
->setInvalidValue($fieldValue)
103-
->setCode(Collection::NO_SUCH_FIELD_ERROR)
104-
->addViolation();
105-
}
76+
$context->buildViolation($constraint->extraFieldsMessage)
77+
->atPath('['.$field.']')
78+
->setParameter('{{ field }}', $this->formatValue($field))
79+
->setInvalidValue($fieldValue)
80+
->setCode(Collection::NO_SUCH_FIELD_ERROR)
81+
->addViolation();
10682
}
10783
}
10884
}

src/Symfony/Component/Validator/Tests/Constraints/AbstractConstraintValidatorTest.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,6 @@ protected function buildViolation($message)
204204
return new ConstraintViolationAssertion($this->context, $message, $this->constraint);
205205
}
206206

207-
protected function getApiVersion()
208-
{
209-
return Validation::API_VERSION_2_5;
210-
}
211-
212207
abstract protected function createValidator();
213208
}
214209

src/Symfony/Component/Validator/Tests/Constraints/AllValidatorTest.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@
1919

2020
class AllValidatorTest extends AbstractConstraintValidatorTest
2121
{
22-
protected function getApiVersion()
23-
{
24-
return Validation::API_VERSION_2_5;
25-
}
26-
2722
protected function createValidator()
2823
{
2924
return new AllValidator();

src/Symfony/Component/Validator/Tests/Constraints/BlankValidatorTest.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@
1717

1818
class BlankValidatorTest extends AbstractConstraintValidatorTest
1919
{
20-
protected function getApiVersion()
21-
{
22-
return Validation::API_VERSION_2_5;
23-
}
24-
2520
protected function createValidator()
2621
{
2722
return new BlankValidator();

src/Symfony/Component/Validator/Tests/Constraints/CallbackValidatorTest.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,6 @@ public static function validateStatic($object, ExecutionContextInterface $contex
4646

4747
class CallbackValidatorTest extends AbstractConstraintValidatorTest
4848
{
49-
protected function getApiVersion()
50-
{
51-
return Validation::API_VERSION_2_5;
52-
}
53-
5449
protected function createValidator()
5550
{
5651
return new CallbackValidator();

src/Symfony/Component/Validator/Tests/Constraints/CardSchemeValidatorTest.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@
1717

1818
class CardSchemeValidatorTest extends AbstractConstraintValidatorTest
1919
{
20-
protected function getApiVersion()
21-
{
22-
return Validation::API_VERSION_2_5;
23-
}
24-
2520
protected function createValidator()
2621
{
2722
return new CardSchemeValidator();

src/Symfony/Component/Validator/Tests/Constraints/ChoiceValidatorTest.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ function choice_callback()
2222

2323
class ChoiceValidatorTest extends AbstractConstraintValidatorTest
2424
{
25-
protected function getApiVersion()
26-
{
27-
return Validation::API_VERSION_2_5;
28-
}
29-
3025
protected function createValidator()
3126
{
3227
return new ChoiceValidator();

0 commit comments

Comments
 (0)