Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\Validator\Constraints; Chris@0: Chris@0: use Symfony\Component\Validator\Constraint; Chris@0: use Symfony\Component\Validator\Exception\MissingOptionsException; Chris@0: Chris@0: /** Chris@0: * @Annotation Chris@0: * @Target({"PROPERTY", "METHOD", "ANNOTATION"}) Chris@0: * Chris@0: * @author Bernhard Schussek Chris@0: */ Chris@0: class Count extends Constraint Chris@0: { Chris@0: const TOO_FEW_ERROR = 'bef8e338-6ae5-4caf-b8e2-50e7b0579e69'; Chris@0: const TOO_MANY_ERROR = '756b1212-697c-468d-a9ad-50dd783bb169'; Chris@0: Chris@17: protected static $errorNames = [ Chris@0: self::TOO_FEW_ERROR => 'TOO_FEW_ERROR', Chris@0: self::TOO_MANY_ERROR => 'TOO_MANY_ERROR', Chris@17: ]; Chris@0: Chris@0: public $minMessage = 'This collection should contain {{ limit }} element or more.|This collection should contain {{ limit }} elements or more.'; Chris@0: public $maxMessage = 'This collection should contain {{ limit }} element or less.|This collection should contain {{ limit }} elements or less.'; Chris@0: public $exactMessage = 'This collection should contain exactly {{ limit }} element.|This collection should contain exactly {{ limit }} elements.'; Chris@0: public $min; Chris@0: public $max; Chris@0: Chris@0: public function __construct($options = null) Chris@0: { Chris@17: if (null !== $options && !\is_array($options)) { Chris@17: $options = [ Chris@0: 'min' => $options, Chris@0: 'max' => $options, Chris@17: ]; Chris@18: } elseif (\is_array($options) && isset($options['value']) && !isset($options['min']) && !isset($options['max'])) { Chris@18: $options['min'] = $options['max'] = $options['value']; Chris@18: unset($options['value']); Chris@0: } Chris@0: Chris@0: parent::__construct($options); Chris@0: Chris@0: if (null === $this->min && null === $this->max) { Chris@17: throw new MissingOptionsException(sprintf('Either option "min" or "max" must be given for constraint %s', __CLASS__), ['min', 'max']); Chris@0: } Chris@0: } Chris@0: }