Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cd8c4b4

Browse files
committed
Removed 2.5 bc layer
1 parent 0021010 commit cd8c4b4

File tree

5 files changed

+44
-41
lines changed

5 files changed

+44
-41
lines changed

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,14 +305,14 @@ public function testFullyConfiguredValidationService()
305305

306306
$container = $this->createContainerFromFile('full');
307307

308-
$this->assertInstanceOf('Symfony\Component\Validator\ValidatorInterface', $container->get('validator'));
308+
$this->assertInstanceOf('Symfony\Component\Validator\Validator\ValidatorInterface', $container->get('validator'));
309309
}
310310

311311
public function testValidationService()
312312
{
313313
$container = $this->createContainerFromFile('validation_annotations');
314314

315-
$this->assertInstanceOf('Symfony\Component\Validator\ValidatorInterface', $container->get('validator'));
315+
$this->assertInstanceOf('Symfony\Component\Validator\Validator\ValidatorInterface', $container->get('validator'));
316316
}
317317

318318
public function testAnnotations()

src/Symfony/Component/Validator/Tests/ValidatorBuilderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public function testLegacyDefaultApiVersion()
115115
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
116116

117117
// Legacy compatible implementation
118-
$this->assertInstanceOf('Symfony\Component\Validator\Validator\LegacyValidator', $this->builder->getValidator());
118+
$this->assertInstanceOf('Symfony\Component\Validator\Validator\RecursiveValidator', $this->builder->getValidator());
119119
}
120120

121121
public function testSetApiVersion25()
@@ -129,6 +129,6 @@ public function testLegacySetApiVersion24And25()
129129
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
130130

131131
$this->assertSame($this->builder, $this->builder->setApiVersion(Validation::API_VERSION_2_5_BC));
132-
$this->assertInstanceOf('Symfony\Component\Validator\Validator\LegacyValidator', $this->builder->getValidator());
132+
$this->assertInstanceOf('Symfony\Component\Validator\Validator\RecursiveValidator', $this->builder->getValidator());
133133
}
134134
}

src/Symfony/Component/Validator/Validator/LegacyValidator.php

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111

1212
namespace Symfony\Component\Validator\Validator;
1313

14-
use Symfony\Component\Validator\Constraint;
15-
use Symfony\Component\Validator\Constraints\GroupSequence;
16-
use Symfony\Component\Validator\Constraints\Valid;
1714
use Symfony\Component\Validator\ValidatorInterface as LegacyValidatorInterface;
1815

1916
/**
@@ -31,22 +28,9 @@ class LegacyValidator extends RecursiveValidator implements LegacyValidatorInter
3128
{
3229
public function validate($value, $groups = null, $traverse = false, $deep = false)
3330
{
34-
$numArgs = func_num_args();
35-
36-
// Use new signature if constraints are given in the second argument
37-
if (self::testConstraints($groups) && ($numArgs < 3 || 3 === $numArgs && self::testGroups($traverse))) {
38-
// Rename to avoid total confusion ;)
39-
$constraints = $groups;
40-
$groups = $traverse;
41-
42-
return parent::validate($value, $constraints, $groups);
43-
}
44-
4531
trigger_error('The '.__METHOD__.' method is deprecated in version 2.5 and will be removed in version 3.0. Use the Symfony\Component\Validator\Validator\ValidatorInterface::validate method instead.', E_USER_DEPRECATED);
4632

47-
$constraint = new Valid(array('traverse' => $traverse, 'deep' => $deep));
48-
49-
return parent::validate($value, $constraint, $groups);
33+
return parent::validate($value, false, $groups, $traverse, $deep);
5034
}
5135

5236
public function validateValue($value, $constraints, $groups = null)
@@ -62,14 +46,4 @@ public function getMetadataFactory()
6246

6347
return $this->metadataFactory;
6448
}
65-
66-
private static function testConstraints($constraints)
67-
{
68-
return null === $constraints || $constraints instanceof Constraint || (is_array($constraints) && current($constraints) instanceof Constraint);
69-
}
70-
71-
private static function testGroups($groups)
72-
{
73-
return null === $groups || is_string($groups) || $groups instanceof GroupSequence || (is_array($groups) && (is_string(current($groups)) || current($groups) instanceof GroupSequence));
74-
}
7549
}

src/Symfony/Component/Validator/Validator/RecursiveValidator.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
namespace Symfony\Component\Validator\Validator;
1313

14+
use Symfony\Component\Validator\Constraint;
15+
use Symfony\Component\Validator\Constraints\GroupSequence;
16+
use Symfony\Component\Validator\Constraints\Valid;
1417
use Symfony\Component\Validator\ConstraintValidatorFactoryInterface;
1518
use Symfony\Component\Validator\Context\ExecutionContextFactoryInterface;
1619
use Symfony\Component\Validator\Context\ExecutionContextInterface;
@@ -112,6 +115,22 @@ public function hasMetadataFor($object)
112115
*/
113116
public function validate($value, $constraints = null, $groups = null)
114117
{
118+
// The following code must be removed in 3.0
119+
$numArgs = func_num_args();
120+
if ($numArgs > 3) {
121+
trigger_error('The '.__METHOD__.' method is deprecated in version 2.5 and will be removed in version 3.0. Use the Symfony\Component\Validator\Validator\ValidatorInterface::validate method instead.', E_USER_DEPRECATED);
122+
$traverse = func_get_arg(3);
123+
$deep = func_get_arg(4);
124+
$constraints = new Valid(array('traverse' => $traverse, 'deep' => $deep));
125+
126+
if (self::testConstraints($groups)) {
127+
if ((!$traverse && !$deep) || self::testGroups($traverse)) {
128+
$constraints = $groups;
129+
$groups = $traverse;
130+
}
131+
}
132+
}
133+
115134
return $this->startContext($value)
116135
->validate($value, $constraints, $groups)
117136
->getViolations();
@@ -137,4 +156,22 @@ public function validatePropertyValue($objectOrClass, $propertyName, $value, $gr
137156
->validatePropertyValue($objectOrClass, $propertyName, $value, $groups)
138157
->getViolations();
139158
}
159+
160+
/**
161+
* @internal
162+
* @deprecated since version 2.5, to be removed in 3.0.
163+
*/
164+
private static function testConstraints($constraints)
165+
{
166+
return null === $constraints || $constraints instanceof Constraint || (is_array($constraints) && current($constraints) instanceof Constraint);
167+
}
168+
169+
/**
170+
* @internal
171+
* @deprecated since version 2.5, to be removed in 3.0.
172+
*/
173+
private static function testGroups($groups)
174+
{
175+
return null === $groups || is_string($groups) || $groups instanceof GroupSequence || (is_array($groups) && (is_string(current($groups)) || current($groups) instanceof GroupSequence));
176+
}
140177
}

src/Symfony/Component/Validator/ValidatorBuilder.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use Symfony\Component\Translation\IdentityTranslator;
2020
use Symfony\Component\Translation\TranslatorInterface;
2121
use Symfony\Component\Validator\Context\ExecutionContextFactory;
22-
use Symfony\Component\Validator\Context\LegacyExecutionContextFactory;
2322
use Symfony\Component\Validator\Exception\InvalidArgumentException;
2423
use Symfony\Component\Validator\Exception\ValidatorException;
2524
use Symfony\Component\Validator\Mapping\Cache\CacheInterface;
@@ -31,7 +30,6 @@
3130
use Symfony\Component\Validator\Mapping\Loader\XmlFilesLoader;
3231
use Symfony\Component\Validator\Mapping\Loader\YamlFileLoader;
3332
use Symfony\Component\Validator\Mapping\Loader\YamlFilesLoader;
34-
use Symfony\Component\Validator\Validator\LegacyValidator;
3533
use Symfony\Component\Validator\Validator\RecursiveValidator;
3634

3735
/**
@@ -393,14 +391,8 @@ public function getValidator()
393391
$translator->setLocale('en');
394392
}
395393

396-
if (Validation::API_VERSION_2_5 === $apiVersion) {
397-
$contextFactory = new ExecutionContextFactory($translator, $this->translationDomain);
394+
$contextFactory = new ExecutionContextFactory($translator, $this->translationDomain);
398395

399-
return new RecursiveValidator($contextFactory, $metadataFactory, $validatorFactory, $this->initializers);
400-
}
401-
402-
$contextFactory = new LegacyExecutionContextFactory($metadataFactory, $translator, $this->translationDomain);
403-
404-
return new LegacyValidator($contextFactory, $metadataFactory, $validatorFactory, $this->initializers);
396+
return new RecursiveValidator($contextFactory, $metadataFactory, $validatorFactory, $this->initializers);
405397
}
406398
}

0 commit comments

Comments
 (0)