Skip to content

Commit e4c4d2d

Browse files
committed
[Validator] Add ExpressionValidator typehint & remove deprecation
1 parent 16ff6ee commit e4c4d2d

File tree

3 files changed

+2
-50
lines changed

3 files changed

+2
-50
lines changed

src/Symfony/Component/Validator/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
5.0.0
55
-----
66

7+
* an `ExpressionLanguage` instance or null must be passed as the first argument of `ExpressionValidator::__construct()`
78
* removed the `checkDNS` and `dnsMessage` options of the `Url` constraint
89
* removed the `checkMX`, `checkHost` and `strict` options of the `Email` constraint
910
* removed support for validating instances of `\DateTimeInterface` in `DateTimeValidator`, `DateValidator` and `TimeValidator`

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,8 @@ class ExpressionValidator extends ConstraintValidator
2424
{
2525
private $expressionLanguage;
2626

27-
public function __construct(/*ExpressionLanguage */$expressionLanguage = null)
27+
public function __construct(ExpressionLanguage $expressionLanguage = null)
2828
{
29-
if (\func_num_args() > 1) {
30-
@trigger_error(sprintf('The "%s" instance should be passed as "%s" first argument instead of second argument since 4.4.', ExpressionLanguage::class, __METHOD__), E_USER_DEPRECATED);
31-
32-
$expressionLanguage = func_get_arg(1);
33-
34-
if (null !== $expressionLanguage && !$expressionLanguage instanceof ExpressionLanguage) {
35-
throw new \TypeError(sprintf('Argument 2 passed to %s() must be an instance of %s or null, %s given. Since 4.4, passing it as the second argument is deprecated and will trigger a deprecation. Pass it as the first argument instead.', __METHOD__, ExpressionLanguage::class, \is_object($expressionLanguage) ? \get_class($expressionLanguage) : \gettype($expressionLanguage)));
36-
}
37-
} elseif (null !== $expressionLanguage && !$expressionLanguage instanceof ExpressionLanguage) {
38-
@trigger_error(sprintf('The "%s" first argument must be an instance of "%s" or null since 4.4. "%s" given', __METHOD__, ExpressionLanguage::class, \is_object($expressionLanguage) ? \get_class($expressionLanguage) : \gettype($expressionLanguage)), E_USER_DEPRECATED);
39-
}
40-
4129
$this->expressionLanguage = $expressionLanguage;
4230
}
4331

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

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -272,43 +272,6 @@ public function testExpressionLanguageUsage()
272272
$this->assertTrue($used, 'Failed asserting that custom ExpressionLanguage instance is used.');
273273
}
274274

275-
/**
276-
* @group legacy
277-
* @expectedDeprecation The "Symfony\Component\ExpressionLanguage\ExpressionLanguage" instance should be passed as "Symfony\Component\Validator\Constraints\ExpressionValidator::__construct" first argument instead of second argument since 4.4.
278-
*/
279-
public function testLegacyExpressionLanguageUsage()
280-
{
281-
$constraint = new Expression([
282-
'expression' => 'false',
283-
]);
284-
285-
$expressionLanguage = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ExpressionLanguage')->getMock();
286-
287-
$used = false;
288-
289-
$expressionLanguage->method('evaluate')
290-
->willReturnCallback(function () use (&$used) {
291-
$used = true;
292-
293-
return true;
294-
});
295-
296-
$validator = new ExpressionValidator(null, $expressionLanguage);
297-
$validator->initialize($this->createContext());
298-
$validator->validate(null, $constraint);
299-
300-
$this->assertTrue($used, 'Failed asserting that custom ExpressionLanguage instance is used.');
301-
}
302-
303-
/**
304-
* @group legacy
305-
* @expectedDeprecation The "Symfony\Component\Validator\Constraints\ExpressionValidator::__construct" first argument must be an instance of "Symfony\Component\ExpressionLanguage\ExpressionLanguage" or null since 4.4. "string" given
306-
*/
307-
public function testConstructorInvalidType()
308-
{
309-
new ExpressionValidator('foo');
310-
}
311-
312275
public function testPassingCustomValues()
313276
{
314277
$constraint = new Expression([

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy