Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ protected function newConstraint(string $name, mixed $options = null): Constrain
return new $className($options);
}

if (isset($options['value']) && \in_array($name, ['Length', 'Count'], true)) {
trigger_deprecation('symfony/validator', '7.3', 'Using the "value" option in configuration for the "%s" constraint is deprecated. Use "exactly" instead.', $name);

if (!isset($options['exactly'])) {
$options['exactly'] = $options['value'];
unset($options['value']);
}
}

return new $className(...$options);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Symfony\Component\Validator\Constraints\Choice;
use Symfony\Component\Validator\Constraints\Collection;
use Symfony\Component\Validator\Constraints\IsTrue;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotNull;
use Symfony\Component\Validator\Constraints\Range;
use Symfony\Component\Validator\Constraints\Regex;
Expand Down Expand Up @@ -188,4 +189,22 @@ public function testLoadConstraintWithoutNamedArgumentsSupport()

$loader->loadClassMetadata($metadata);
}

/**
* @group legacy
*/
public function testLengthConstraintValueOptionTriggersDeprecation()
{
$this->expectDeprecation('Since symfony/validator 7.3: Using the "value" option in configuration for the "Length" constraint is deprecated. Use "exactly" instead.');

$loader = new XmlFileLoader(__DIR__.'/constraint-mapping-exactly-value.xml');
$metadata = new ClassMetadata(Entity_81::class);
$loader->loadClassMetadata($metadata);
$constraints = $metadata->getPropertyMetadata('title')[0]->constraints;

self::assertCount(1, $constraints);
self::assertInstanceOf(Length::class, $constraints[0]);
self::assertSame(6, $constraints[0]->min);
self::assertSame(6, $constraints[0]->max);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping
https://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">

<class name="Symfony\Component\Validator\Tests\Fixtures\Entity_81">
<property name="title">
<constraint name="Length">
<option name="value">6</option>
<option name="groups">
<value>Foo</value>
</option>
</constraint>
</property>
</class>
</constraint-mapping>
Loading