Skip to content

[DoctrineBridge][Validator] mark getRequiredOptions()/getDefaultOption() of UniqueEntity as deprecated #61108

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 15, 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
7 changes: 7 additions & 0 deletions UPGRADE-7.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ DependencyInjection

* Add argument `$target` to `ContainerBuilder::registerAliasForArgument()`

DoctrineBridge
--------------

* Deprecate `UniqueEntity::getRequiredOptions()` and `UniqueEntity::getDefaultOption()`

FrameworkBundle
---------------

Expand All @@ -48,6 +53,8 @@ Security
Validator
---------

* Deprecate `getRequiredOptions()` and `getDefaultOption()` methods of the `All`, `AtLeastOneOf`, `CardScheme`, `Collection`,
`CssColor`, `Expression`, `Regex`, `Sequentially`, `Type`, and `When` constraints
* Deprecate evaluating options in the base `Constraint` class. Initialize properties in the constructor of the concrete constraint
class instead.

Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Bridge/Doctrine/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

7.4
---

* Deprecate `UniqueEntity::getRequiredOptions()` and `UniqueEntity::getDefaultOption()`

7.3
---

Expand Down
14 changes: 14 additions & 0 deletions src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,15 @@ public function __construct(
$this->identifierFieldNames = $identifierFieldNames ?? $this->identifierFieldNames;
}

/**
* @deprecated since Symfony 7.4
*/
public function getRequiredOptions(): array
{
if (0 === \func_num_args() || func_get_arg(0)) {
trigger_deprecation('symfony/doctrine-bridge', '7.4', 'The %s() method is deprecated.', __METHOD__);
}

return ['fields'];
}

Expand All @@ -109,8 +116,15 @@ public function getTargets(): string|array
return self::CLASS_CONSTRAINT;
}

/**
* @deprecated since Symfony 7.4
*/
public function getDefaultOption(): ?string
{
if (0 === \func_num_args() || func_get_arg(0)) {
trigger_deprecation('symfony/doctrine-bridge', '7.4', 'The %s() method is deprecated.', __METHOD__);
}

return 'fields';
}
}
2 changes: 2 additions & 0 deletions src/Symfony/Component/Validator/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ CHANGELOG
7.4
---

* Deprecate `getRequiredOptions()` and `getDefaultOption()` methods of the `All`, `AtLeastOneOf`, `CardScheme`, `Collection`,
`CssColor`, `Expression`, `Regex`, `Sequentially`, `Type`, and `When` constraints
* Deprecate evaluating options in the base `Constraint` class. Initialize properties in the constructor of the concrete constraint
class instead.

Expand Down
14 changes: 10 additions & 4 deletions src/Symfony/Component/Validator/Constraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ public function __construct(mixed $options = null, ?array $groups = null, mixed
protected function normalizeOptions(mixed $options): array
{
$normalizedOptions = [];
$defaultOption = $this->getDefaultOption();
$defaultOption = $this->getDefaultOption(false);
$invalidOptions = [];
$missingOptions = array_flip($this->getRequiredOptions());
$missingOptions = array_flip($this->getRequiredOptions(false));
$knownOptions = get_class_vars(static::class);

if (\is_array($options) && isset($options['value']) && !property_exists($this, 'value')) {
Expand Down Expand Up @@ -255,11 +255,14 @@ public function addImplicitGroupName(string $group): void
* Override this method to define a default option.
*
* @deprecated since Symfony 7.4
*
* @see __construct()
*/
public function getDefaultOption(): ?string
{
if (0 === \func_num_args() || func_get_arg(0)) {
trigger_deprecation('symfony/validator', '7.4', 'The %s() method is deprecated.', __METHOD__);
}

return null;
}

Expand All @@ -271,11 +274,14 @@ public function getDefaultOption(): ?string
* @return string[]
*
* @deprecated since Symfony 7.4
*
* @see __construct()
*/
public function getRequiredOptions(): array
{
if (0 === \func_num_args() || func_get_arg(0)) {
trigger_deprecation('symfony/validator', '7.4', 'The %s() method is deprecated.', __METHOD__);
}

return [];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ public function __construct(mixed $value = null, ?string $propertyPath = null, ?
*/
public function getDefaultOption(): ?string
{
if (0 === \func_num_args() || func_get_arg(0)) {
trigger_deprecation('symfony/validator', '7.4', 'The %s() method is deprecated.', __METHOD__);
}

return 'value';
}
}
8 changes: 8 additions & 0 deletions src/Symfony/Component/Validator/Constraints/All.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public function __construct(mixed $constraints = null, ?array $groups = null, mi
*/
public function getDefaultOption(): ?string
{
if (0 === \func_num_args() || func_get_arg(0)) {
trigger_deprecation('symfony/validator', '7.4', 'The %s() method is deprecated.', __METHOD__);
}

return 'constraints';
}

Expand All @@ -56,6 +60,10 @@ public function getDefaultOption(): ?string
*/
public function getRequiredOptions(): array
{
if (0 === \func_num_args() || func_get_arg(0)) {
trigger_deprecation('symfony/validator', '7.4', 'The %s() method is deprecated.', __METHOD__);
}

return ['constraints'];
}

Expand Down
8 changes: 8 additions & 0 deletions src/Symfony/Component/Validator/Constraints/AtLeastOneOf.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public function __construct(mixed $constraints = null, ?array $groups = null, mi
*/
public function getDefaultOption(): ?string
{
if (0 === \func_num_args() || func_get_arg(0)) {
trigger_deprecation('symfony/validator', '7.4', 'The %s() method is deprecated.', __METHOD__);
}

return 'constraints';
}

Expand All @@ -70,6 +74,10 @@ public function getDefaultOption(): ?string
*/
public function getRequiredOptions(): array
{
if (0 === \func_num_args() || func_get_arg(0)) {
trigger_deprecation('symfony/validator', '7.4', 'The %s() method is deprecated.', __METHOD__);
}

return ['constraints'];
}

Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public function __construct(array|string|callable|null $callback = null, ?array
*/
public function getDefaultOption(): ?string
{
if (0 === \func_num_args() || func_get_arg(0)) {
trigger_deprecation('symfony/validator', '7.4', 'The %s() method is deprecated.', __METHOD__);
}

return 'callback';
}

Expand Down
8 changes: 8 additions & 0 deletions src/Symfony/Component/Validator/Constraints/CardScheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ public function __construct(array|string|null $schemes, ?string $message = null,
*/
public function getDefaultOption(): ?string
{
if (0 === \func_num_args() || func_get_arg(0)) {
trigger_deprecation('symfony/validator', '7.4', 'The %s() method is deprecated.', __METHOD__);
}

return 'schemes';
}

Expand All @@ -86,6 +90,10 @@ public function getDefaultOption(): ?string
*/
public function getRequiredOptions(): array
{
if (0 === \func_num_args() || func_get_arg(0)) {
trigger_deprecation('symfony/validator', '7.4', 'The %s() method is deprecated.', __METHOD__);
}

return ['schemes'];
}
}
4 changes: 4 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Choice.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ class Choice extends Constraint
*/
public function getDefaultOption(): ?string
{
if (0 === \func_num_args() || func_get_arg(0)) {
trigger_deprecation('symfony/validator', '7.4', 'The %s() method is deprecated.', __METHOD__);
}

return 'choices';
}

Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ protected function initializeNestedConstraints(): void
*/
public function getRequiredOptions(): array
{
if (0 === \func_num_args() || func_get_arg(0)) {
trigger_deprecation('symfony/validator', '7.4', 'The %s() method is deprecated.', __METHOD__);
}

return ['fields'];
}

Expand Down
8 changes: 8 additions & 0 deletions src/Symfony/Component/Validator/Constraints/CssColor.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ public function __construct(array|string $formats = [], ?string $message = null,
*/
public function getDefaultOption(): string
{
if (0 === \func_num_args() || func_get_arg(0)) {
trigger_deprecation('symfony/validator', '7.4', 'The %s() method is deprecated.', __METHOD__);
}

return 'formats';
}

Expand All @@ -111,6 +115,10 @@ public function getDefaultOption(): string
*/
public function getRequiredOptions(): array
{
if (0 === \func_num_args() || func_get_arg(0)) {
trigger_deprecation('symfony/validator', '7.4', 'The %s() method is deprecated.', __METHOD__);
}

return ['formats'];
}
}
4 changes: 4 additions & 0 deletions src/Symfony/Component/Validator/Constraints/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ public function __construct(string|array|null $format = null, ?string $message =
*/
public function getDefaultOption(): ?string
{
if (0 === \func_num_args() || func_get_arg(0)) {
trigger_deprecation('symfony/validator', '7.4', 'The %s() method is deprecated.', __METHOD__);
}

return 'format';
}
}
4 changes: 4 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Existence.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public function __construct(mixed $constraints = null, ?array $groups = null, mi
*/
public function getDefaultOption(): ?string
{
if (0 === \func_num_args() || func_get_arg(0)) {
trigger_deprecation('symfony/validator', '7.4', 'The %s() method is deprecated.', __METHOD__);
}

return 'constraints';
}

Expand Down
8 changes: 8 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Expression.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ public function __construct(
*/
public function getDefaultOption(): ?string
{
if (0 === \func_num_args() || func_get_arg(0)) {
trigger_deprecation('symfony/validator', '7.4', 'The %s() method is deprecated.', __METHOD__);
}

return 'expression';
}

Expand All @@ -94,6 +98,10 @@ public function getDefaultOption(): ?string
*/
public function getRequiredOptions(): array
{
if (0 === \func_num_args() || func_get_arg(0)) {
trigger_deprecation('symfony/validator', '7.4', 'The %s() method is deprecated.', __METHOD__);
}

return ['expression'];
}

Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Isbn.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ public function __construct(
*/
public function getDefaultOption(): ?string
{
if (0 === \func_num_args() || func_get_arg(0)) {
trigger_deprecation('symfony/validator', '7.4', 'The %s() method is deprecated.', __METHOD__);
}

return 'type';
}
}
8 changes: 8 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Regex.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ public function __construct(
*/
public function getDefaultOption(): ?string
{
if (0 === \func_num_args() || func_get_arg(0)) {
trigger_deprecation('symfony/validator', '7.4', 'The %s() method is deprecated.', __METHOD__);
}

return 'pattern';
}

Expand All @@ -91,6 +95,10 @@ public function getDefaultOption(): ?string
*/
public function getRequiredOptions(): array
{
if (0 === \func_num_args() || func_get_arg(0)) {
trigger_deprecation('symfony/validator', '7.4', 'The %s() method is deprecated.', __METHOD__);
}

return ['pattern'];
}

Expand Down
8 changes: 8 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Sequentially.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public function __construct(mixed $constraints = null, ?array $groups = null, mi
*/
public function getDefaultOption(): ?string
{
if (0 === \func_num_args() || func_get_arg(0)) {
trigger_deprecation('symfony/validator', '7.4', 'The %s() method is deprecated.', __METHOD__);
}

return 'constraints';
}

Expand All @@ -55,6 +59,10 @@ public function getDefaultOption(): ?string
*/
public function getRequiredOptions(): array
{
if (0 === \func_num_args() || func_get_arg(0)) {
trigger_deprecation('symfony/validator', '7.4', 'The %s() method is deprecated.', __METHOD__);
}

return ['constraints'];
}

Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Timezone.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ public function __construct(
*/
public function getDefaultOption(): ?string
{
if (0 === \func_num_args() || func_get_arg(0)) {
trigger_deprecation('symfony/validator', '7.4', 'The %s() method is deprecated.', __METHOD__);
}

return 'zone';
}
}
4 changes: 4 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Traverse.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public function __construct(bool|array|null $traverse = null, mixed $payload = n
*/
public function getDefaultOption(): ?string
{
if (0 === \func_num_args() || func_get_arg(0)) {
trigger_deprecation('symfony/validator', '7.4', 'The %s() method is deprecated.', __METHOD__);
}

return 'traverse';
}

Expand Down
8 changes: 8 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public function __construct(string|array|null $type, ?string $message = null, ?a
*/
public function getDefaultOption(): ?string
{
if (0 === \func_num_args() || func_get_arg(0)) {
trigger_deprecation('symfony/validator', '7.4', 'The %s() method is deprecated.', __METHOD__);
}

return 'type';
}

Expand All @@ -71,6 +75,10 @@ public function getDefaultOption(): ?string
*/
public function getRequiredOptions(): array
{
if (0 === \func_num_args() || func_get_arg(0)) {
trigger_deprecation('symfony/validator', '7.4', 'The %s() method is deprecated.', __METHOD__);
}

return ['type'];
}
}
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