8000 [Validator] Add ExpressionValidator typehint & remove deprecation by ogizanagi · Pull Request #32128 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Validator] Add ExpressionValidator typehint & remove deprecation #32128

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

Merged
merged 1 commit into from
Jun 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions src/Symfony/Component/Validator/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CHANGELOG
5.0.0
-----

* an `ExpressionLanguage` instance or null must be passed as the first argument of `ExpressionValidator::__construct()`
* removed the `checkDNS` and `dnsMessage` options of the `Url` constraint
* removed the `checkMX`, `checkHost` and `strict` options of the `Email` constraint
* removed support for validating instances of `\DateTimeInterface` in `DateTimeValidator`, `DateValidator` and `TimeValidator`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,8 @@ class ExpressionValidator extends ConstraintValidator
{
private $expressionLanguage;

public function __construct(/*ExpressionLanguage */$expressionLanguage = null)
public function __construct(ExpressionLanguage $expressionLanguage = null)
{
if (\func_num_args() > 1) {
@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);

$expressionLanguage = func_get_arg(1);

if (null !== $expressionLanguage && !$expressionLanguage instanceof ExpressionLanguage) {
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)));
}
} elseif (null !== $expressionLanguage && !$expressionLanguage instanceof ExpressionLanguage) {
@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);
}

$this->expressionLanguage = $expressionLanguage;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,43 +272,6 @@ public function testExpressionLanguageUsage()
$this->assertTrue($used, 'Failed asserting that custom ExpressionLanguage instance is used.');
}

/**
* @group legacy
* @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.
*/
public function testLegacyExpressionLanguageUsage()
{
$constraint = new Expression([
'expression' => 'false',
]);

$expressionLanguage = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ExpressionLanguage')->getMock();

$used = false;

$expressionLanguage->method('evaluate')
->willReturnCallback(function () use (&$used) {
$used = true;

return true;
});

$validator = new ExpressionValidator(null, $expressionLanguage);
$validator->initialize($this->createContext());
$validator->validate(null, $constraint);

$this->assertTrue($used, 'Failed asserting that custom ExpressionLanguage instance is used.');
}

/**
* @group legacy
* @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
*/
public function testConstructorInvalidType()
{
new ExpressionValidator('foo');
}

public function testPassingCustomValues()
{
$constraint = new Expression([
Expand Down
0