Skip to content

[Validator] remove support for generic constraint option handling #61063

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
Jul 30, 2025
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
113 changes: 112 additions & 1 deletion UPGRADE-8.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,118 @@ Uid
Validator
---------

* Remove `Bic::INVALID_BANK_CODE_ERROR` constant. This error code was not used in the Bic constraint validator anymore.
* Remove the `getRequiredOptions()` and `getDefaultOption()` methods from the `All`, `AtLeastOneOf`, `CardScheme`, `Collection`,
`CssColor`, `Expression`, `Regex`, `Sequentially`, `Type`, and `When` constraints
* Remove support for evaluating options in the base `Constraint` class. Initialize properties in the constructor of the concrete constraint
class instead.

Before:

```php
class CustomConstraint extends Constraint
{
public $option1;
public $option2;

public function __construct(?array $options = null)
{
parent::__construct($options);
}
}
```

After:

```php
class CustomConstraint extends Constraint
{
public function __construct(
public $option1 = null,
public $option2 = null,
?array $groups = null,
mixed $payload = null,
) {
parent::__construct(null, $groups, $payload);
}
}
```

* Remove the `getRequiredOptions()` method from the base `Constraint` class. Use mandatory constructor arguments instead.

Before:

```php
class CustomConstraint extends Constraint
{
public $option1;
public $option2;

public function __construct(?array $options = null)
{
parent::__construct($options);
}

public function getRequiredOptions()
{
return ['option1'];
}
}
```

After:

```php
class CustomConstraint extends Constraint
{
public function __construct(
public $option1,
public $option2 = null,
?array $groups = null,
mixed $payload = null,
) {
parent::__construct(null, $groups, $payload);
}
}
```
* Remove the `normalizeOptions()` and `getDefaultOption()` methods of the base `Constraint` class without replacements.
Overriding them in child constraint does not have any effects.
* Remove support for passing an array of options to the `Composite` constraint class. Initialize the properties referenced with `getNestedConstraints()`
in child classes before calling the constructor of `Composite`.

Before:

```php
class CustomCompositeConstraint extends Composite
{
public array $constraints = [];

public function __construct(?array $options = null)
{
parent::__construct($options);
}

protected function getCompositeOption(): string
{
return 'constraints';
}
}
```

After:

```php
class CustomCompositeConstraint extends Composite
{
public function __construct(
public array $constraints,
?array $groups = null,
mixed $payload = null,
) {
parent::__construct(null, $groups, $payload);
}
}
```
* Remove `Bic::INVALID_BANK_CODE_ERROR` constant. This error code was not used in the Bic constraint validator anymore

VarExporter
-----------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,6 @@ public function testAttributeWithGroupsAndPaylod()
self::assertSame('some attached data', $constraint->payload);
self::assertSame(['some_group'], $constraint->groups);
}

/**
* @group legacy
*/
public function testValueOptionConfiguresFields()
{
$constraint = new UniqueEntity(['value' => 'email']);

$this->assertSame('email', $constraint->fields);
}
}

#[UniqueEntity(['email'], message: 'myMessage')]
Expand Down
Loading
Loading
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