Chain
その目的でバリデーターを使用できます: https://gist.github.com/rybakit/4705749
プレーンな PHP での例を次に示します。
<?php
use Symfony\Component\Validator\Constraints\Date;
use Symfony\Component\Validator\Constraints\Type;
use Acme\Validator\Constraints\Chain;
$constraint = new Chain([new Type('string'), new Date()]);
XML の場合:
<!-- src/Acme/DemoBundle/Resources/config/validation.xml -->
<class name="Acme\DemoBundle\Entity\AcmeEntity">
<property name="date">
<constraint name="Acme\Validator\Constraints\Chain">
<option name="constraints">
<constraint name="Type">
<option name="type">string</option>
</constraint>
<constraint name="Date" />
</option>
</constraint>
</property>
</class>
Chain
ただし、次のようなネストされた制約が必要な場合は注意してください。
<?php
$constraint = new Chain([
new Callback(...),
new Chain([new Type('string'), new Date()]),
]);
validator.validator_factory
現在の実装でネストされた制約を処理する際の問題を修正するには、symfony サービスをオーバーライドする必要があります: https://github.com/symfony/Validator/blob/fc0650c1825c842f9dcc4819a2eaff9922a07e7c/ConstraintValidatorFactory.php#L48。
要点からファイルを参照して、NoCacheConstraintValidatorFactory.php
解決方法を理解してください。