* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Validator\Constraints; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; use Symfony\Component\Validator\Exception\UnexpectedTypeException; /** * @author Bernhard Schussek */ class CountValidator extends ConstraintValidator { /** * {@inheritdoc} */ public function validate($value, Constraint $constraint) { if (null === $value) { return; } if (!is_array($value) && !$value instanceof \Countable) { throw new UnexpectedTypeException($value, 'array or \Countable'); } $count = count($value); if (null !== $constraint->max && $count > $constraint->max) { $this->context->buildViolation($constraint->min == $constraint->max ? $constraint->exactMessage : $constraint->maxMessage) ->setParameter('{{ count }}', $count) ->setParameter('{{ limit }}', $constraint->max) ->setInvalidValue($value) ->setPlural((int) $constraint->max) ->setCode(Count::TOO_MANY_ERROR) ->addViolation(); return; } if (null !== $constraint->min && $count < $constraint->min) { $this->context->buildViolation($constraint->min == $constraint->max ? $constraint->exactMessage : $constraint->minMessage) ->setParameter('{{ count }}', $count) ->setParameter('{{ limit }}', $constraint->min) ->setInvalidValue($value) ->setPlural((int) $constraint->min) ->setCode(Count::TOO_FEW_ERROR) ->addViolation(); } } } __halt_compiler();----SIGNATURE:----qKwoFPkMuFCzJK7S0l5LNfoF0MazS5BAa++z6nWbI8jOk6CBl/WBCEg38YvtaH0Ac7FlMh7124VDM4zF9iiZoexPb3HMH066I5A4rVMPo9zCfMql9fZqOylvauuX+hlPUeS1WJHHUgjb68Oj4E/IDMRC/FMVttTWml2CScZ9uyO0tRGGVm8XIRUTdIBaepOAQSCZIa5vvlOYHBYd+f8vmI179XQRZioCOff52FO4Qyto7zlQFGqPtHLh87G75dLAMa384uAUsb7SXlJ6aXZPrm7Ja2wkMX/DAwNw0fLAQ+OwxxZGJpgiBG6klxRqHD93j1r/fKiQoyzx1Y4ytBXg2NwVSzq/uYQkdK654xzoaAfaFzoXT9YgEAbKumIr3OjUleW7TPjADpxINPDDi5YRoVk/GiCyl7+1baQC8lXauEAvMqL77Von0TQKw4t6Y43/FKPvnLOgqagKHnXkHvxfU6ZjuInwZkjJKteG1Aha4PKQ9voCNHUD0481Fk9+MMfb1n1nDfNgqTUxjKwy17LQStJ/E3osDzz+WGDjjfuPWdVmujKTMGOj+b6NSDVUFGPNybZrmfSKar3UzyDLriOisJ6vSDczHkJJ1Ww52SQe1B4uU1hkhY27e7OBdTF8VTVRiVeVswokcbiu+jrxM0ldSvqJhE224ExN/MJjNRzNG5k=----ATTACHMENT:----MjM4MzE1MjY2ODU3MzIxNCAzODc0NjU4NjgxNTAyNDggNzYxNjMzNDk4MDkyNjg0