Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is a callback constraint. See <a href="http://symfony.com/doc/master/reference/constraints/Callback.html" rel="nofollow">http://symfony.com/doc/master/reference/constraints/Callback.html</a></p> <p><strong>Update:</strong></p> <p>I could not find a cleaner way to get the keys of the current value being validated. There probably is a better way, I did not spend too much time on this but it works for your case. </p> <pre><code> use Symfony\Component\Validator\Constraints; use Symfony\Component\Validator\Context\ExecutionContextInterface; // ... $input = array( 'emails' =&gt; array( 7 =&gt; 'david@panmedia.co.nz', 12 =&gt; 'some@email.add', ), 'user' =&gt; 'bob', 'amount' =&gt; 7, ); // inside a sf2 controller: $validator = $this-&gt;get('validator.builder')-&gt;getValidator(); $validator = Validation::createValidator(); $constraint = new Constraints\Collection(array( 'emails' =&gt; new Constraints\All(array( new Constraints\Email(), new Constraints\Callback(array('methods' =&gt; array(function($value, ExecutionContextInterface $context){ $propertyPath = $context-&gt;getPropertyPath(); $valueKey = preg_replace('/[^0-9]/','',$propertyPath); if($valueKey == 7){ $context-&gt;addViolationAt('email', sprintf('E-Mail %s Has Has Key 7',$value), array(), null); } }))) )), 'user' =&gt; new Constraints\Regex('/[a-z]/i'), 'amount' =&gt; new Constraints\Range(array('min' =&gt; 5, 'max' =&gt; 10)), )); $violations = $validator-&gt;validate($input, $constraint); echo $violations; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload