Skip to content

Commit 03f9d5d

Browse files
feature #61063 [Validator] remove support for generic constraint option handling (xabbuh)
This PR was merged into the 8.0 branch. Discussion ---------- [Validator] remove support for generic constraint option handling | Q | A | ------------- | --- | Branch? | 8.0 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | | License | MIT opening the PR already even if some polishing needs to be done (and not all tests pass yet) to avoid someone else wasting their time on this topic Commits ------- 09299fc remove support for generic constraint option handling
2 parents 75bf016 + 09299fc commit 03f9d5d

File tree

133 files changed

+520
-3649
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+520
-3649
lines changed

UPGRADE-8.0.md

Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,118 @@ Uid
489489
Validator
490490
---------
491491

492-
* Remove `Bic::INVALID_BANK_CODE_ERROR` constant. This error code was not used in the Bic constraint validator anymore.
492+
* Remove the `getRequiredOptions()` and `getDefaultOption()` methods from the `All`, `AtLeastOneOf`, `CardScheme`, `Collection`,
493+
`CssColor`, `Expression`, `Regex`, `Sequentially`, `Type`, and `When` constraints
494+
* Remove support for evaluating options in the base `Constraint` class. Initialize properties in the constructor of the concrete constraint
495+
class instead.
496+
497+
Before:
498+
499+
```php
500+
class CustomConstraint extends Constraint
501+
{
502+
public $option1;
503+
public $option2;
504+
505+
public function __construct(?array $options = null)
506+
{
507+
parent::__construct($options);
508+
}
509+
}
510+
```
511+
512+
After:
513+
514+
```php
515+
class CustomConstraint extends Constraint
516+
{
517+
public function __construct(
518+
public $option1 = null,
519+
public $option2 = null,
520+
?array $groups = null,
521+
mixed $payload = null,
522+
) {
523+
parent::__construct(null, $groups, $payload);
524+
}
525+
}
526+
```
527+
528+
* Remove the `getRequiredOptions()` method from the base `Constraint` class. Use mandatory constructor arguments instead.
529+
530+
Before:
531+
532+
```php
533+
class CustomConstraint extends Constraint
534+
{
535+
public $option1;
536+
public $option2;
537+
538+
public function __construct(?array $options = null)
539+
{
540+
parent::__construct($options);
541+
}
542+
543+
public function getRequiredOptions()
544+
{
545+
return ['option1'];
546+
}
547+
}
548+
```
549+
550+
After:
551+
552+
```php
553+
class CustomConstraint extends Constraint
554+
{
555+
public function __construct(
556+
public $option1,
557+
public $option2 = null,
558+
?array $groups = null,
559+
mixed $payload = null,
560+
) {
561+
parent::__construct(null, $groups, $payload);
562+
}
563+
}
564+
```
565+
* Remove the `normalizeOptions()` and `getDefaultOption()` methods of the base `Constraint` class without replacements.
566+
Overriding them in child constraint does not have any effects.
567+
* Remove support for passing an array of options to the `Composite` constraint class. Initialize the properties referenced with `getNestedConstraints()`
568+
in child classes before calling the constructor of `Composite`.
569+
570+
Before:
571+
572+
```php
573+
class CustomCompositeConstraint extends Composite
574+
{
575+
public array $constraints = [];
576+
577+
public function __construct(?array $options = null)
578+
{
579+
parent::__construct($options);
580+
}
581+
582+
protected function getCompositeOption(): string
583+
{
584+
return 'constraints';
585+
}
586+
}
587+
```
588+
589+
After:
590+
591+
```php
592+
class CustomCompositeConstraint extends Composite
593+
{
594+
public function __construct(
595+
public array $constraints,
596+
?array $groups = null,
597+
mixed $payload = null,
598+
) {
599+
parent::__construct(null, $groups, $payload);
600+
}
601+
}
602+
```
603+
* Remove `Bic::INVALID_BANK_CODE_ERROR` constant. This error code was not used in the Bic constraint validator anymore
493604

494605
VarExporter
495606
-----------

src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityTest.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,6 @@ public function testAttributeWithGroupsAndPaylod()
6060
self::assertSame('some attached data', $constraint->payload);
6161
self::assertSame(['some_group'], $constraint->groups);
6262
}
63-
64-
/**
65-
* @group legacy
66-
*/
67-
public function testValueOptionConfiguresFields()
68-
{
69-
$constraint = new UniqueEntity(['value' => 'email']);
70-
71-
$this->assertSame('email', $constraint->fields);
72-
}
7363
}
7464

7565
#[UniqueEntity(['email'], message: 'myMessage')]

0 commit comments

Comments
 (0)