Skip to content

[Validator] Remove deprecated Expression methods #61104

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
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
2 changes: 2 additions & 0 deletions UPGRADE-8.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,8 @@ Validator
---------

* Remove `Bic::INVALID_BANK_CODE_ERROR` constant. This error code was not used in the Bic constraint validator anymore.
* Remove `Expression::getDefaultOption()`, use named arguments instead.
* Remove `Expression::etRequiredOptions()`, use named arguments instead.

VarExporter
-----------
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Validator/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ CHANGELOG
---

* Remove `Bic::INVALID_BANK_CODE_ERROR` constant. This error code was not used in the Bic constraint validator anymore.
* Remove `Expression::getDefaultOption()`, use named arguments instead.
* Remove `Expression::etRequiredOptions()`, use named arguments instead.

7.4
---
Expand Down
41 changes: 6 additions & 35 deletions src/Symfony/Component/Validator/Constraints/Expression.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ class Expression extends Constraint
public bool $negate = true;

/**
* @param string|ExpressionObject|array<string,mixed>|null $expression The expression to evaluate
* @param array<string,mixed>|null $values The values of the custom variables used in the expression (defaults to an empty array)
* @param string[]|null $groups
* @param array<string,mixed>|null $options
* @param bool|null $negate Whether to fail if the expression evaluates to true (defaults to false)
* @param string|ExpressionObject|null $expression The expression to evaluate
* @param array<string,mixed>|null $values The values of the custom variables used in the expression (defaults to an empty array)
* @param string[]|null $groups
* @param array<string,mixed>|null $options
* @param bool|null $negate Whether to fail if the expression evaluates to true (defaults to false)
*/
#[HasNamedArguments]
public function __construct(
string|ExpressionObject|array|null $expression,
string|ExpressionObject|null $expression = null,
?string $message = null,
?array $values = null,
?array $groups = null,
Expand All @@ -60,19 +60,6 @@ public function __construct(
throw new LogicException(\sprintf('The "symfony/expression-language" component is required to use the "%s" constraint. Try running "composer require symfony/expression-language".', __CLASS__));
}

if (\is_array($expression)) {
trigger_deprecation('symfony/validator', '7.3', 'Passing an array of options to configure the "%s" constraint is deprecated, use named arguments instead.', static::class);

$options = array_merge($expression, $options ?? []);
$expression = null;
} else {
if (\is_array($options)) {
trigger_deprecation('symfony/validator', '7.3', 'Passing an array of options to configure the "%s" constraint is deprecated, use named arguments instead.', static::class);

$options['value'] = $expression;
}
}

parent::__construct($options, $groups, $payload);

$this->message = $message ?? $this->message;
Expand All @@ -81,22 +68,6 @@ public function __construct(
$this->negate = $negate ?? $this->negate;
}

/**
* @deprecated since Symfony 7.4
*/
public function getDefaultOption(): ?string
{
return 'expression';
}

/**
* @deprecated since Symfony 7.4
*/
public function getRequiredOptions(): array
{
return ['expression'];
}

public function getTargets(): string|array
{
return [self::CLASS_CONSTRAINT, self::PROPERTY_CONSTRAINT];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,6 @@ public function testAttributes()
self::assertSame('some attached data', $cConstraint->payload);
self::assertFalse($cConstraint->negate);
}

/**
* @group legacy
*/
public function testInitializeWithOptionsArray()
{
$constraint = new Expression([
'expression' => '!this.getParent().get("field2").getData()',
]);

$this->assertSame('!this.getParent().get("field2").getData()', $constraint->expression);
}
}

class ExpressionDummy
Expand Down
Loading