Skip to content

Commit 9df2c71

Browse files
committed
remove support for generic constraint option handling
1 parent 0ee792d commit 9df2c71

File tree

121 files changed

+466
-3530
lines changed

Some content is hidden

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

121 files changed

+466
-3530
lines changed

UPGRADE-8.0.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,131 @@ Uid
489489
Validator
490490
---------
491491

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+
use Symfony\Component\Validator\Attribute\HasNamedArguments;
516+
517+
class CustomConstraint extends Constraint
518+
{
519+
public $option1;
520+
public $option2;
521+
522+
#[HasNamedArguments]
523+
public function __construct($option1 = null, $option2 = null, ?array $groups = null, mixed $payload = null)
524+
{
525+
parent::__construct(null, $groups, $payload);
526+
527+
$this->option1 = $option1;
528+
$this->option2 = $option2;
529+
}
530+
}
531+
```
532+
533+
* Remove the `getRequiredOptions()` method from the base `Constraint` class. Use mandatory constructor arguments instead.
534+
535+
Before:
536+
537+
```php
538+
class CustomConstraint extends Constraint
539+
{
540+
public $option1;
541+
public $option2;
542+
543+
public function __construct(?array $options = null)
544+
{
545+
parent::__construct($options);
546+
}
547+
548+
public function getRequiredOptions()
549+
{
550+
return ['option1'];
551+
}
552+
}
553+
```
554+
555+
After:
556+
557+
```php
558+
use Symfony\Component\Validator\Attribute\HasNamedArguments;
559+
560+
class CustomConstraint extends Constraint
561+
{
562+
public $option1;
563+
public $option2;
564+
565+
#[HasNamedArguments]
566+
public function __construct($option1, $option2 = null, ?array $groups = null, mixed $payload = null)
567+
{
568+
parent::__construct(null, $groups, $payload);
569+
570+
$this->option1 = $option1;
571+
$this->option2 = $option2;
572+
}
573+
}
574+
```
575+
* Remove the `normalizeOptions()` and `getDefaultOption()` methods of the base `Constraint` class without replacements.
576+
Overriding them in child constraint does not have any effects.
577+
* Remove support for passing an array of options to the `Composite` constraint class. Initialize the properties referenced with `getNestedConstraints()`
578+
in child classes before calling the constructor of `Composite`.
579+
580+
Before:
581+
582+
```php
583+
class CustomCompositeConstraint extends Composite
584+
{
585+
public array $constraints = [];
586+
587+
public function __construct(?array $options = null)
588+
{
589+
parent::__construct($options);
590+
}
591+
592+
protected function getCompositeOption(): string
593+
{
594+
return 'constraints';
595+
}
596+
}
597+
```
598+
599+
After:
600+
601+
```php
602+
use Symfony\Component\Validator\Attribute\HasNamedArguments;
603+
604+
class CustomCompositeConstraint extends Composite
605+
{
606+
public array $constraints = [];
607+
608+
#[HasNamedArguments]
609+
public function __construct(array $constraints, ?array $groups = null, mixed $payload = null)
610+
{
611+
$this->constraints = $constraints;
612+
613+
parent::__construct(null, $groups, $payload);
614+
}
615+
}
616+
```
492617
* Remove `Bic::INVALID_BANK_CODE_ERROR` constant. This error code was not used in the Bic constraint validator anymore.
493618

494619
VarExporter

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)