4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Validator\Constraints;
14 use Symfony\Component\Validator\Constraint;
15 use Symfony\Component\Validator\Exception\MissingOptionsException;
19 * @Target({"PROPERTY", "METHOD", "ANNOTATION"})
21 * @author Bernhard Schussek <bschussek@gmail.com>
23 class Count extends Constraint
25 const TOO_FEW_ERROR = 'bef8e338-6ae5-4caf-b8e2-50e7b0579e69';
26 const TOO_MANY_ERROR = '756b1212-697c-468d-a9ad-50dd783bb169';
28 protected static $errorNames = array(
29 self::TOO_FEW_ERROR => 'TOO_FEW_ERROR',
30 self::TOO_MANY_ERROR => 'TOO_MANY_ERROR',
33 public $minMessage = 'This collection should contain {{ limit }} element or more.|This collection should contain {{ limit }} elements or more.';
34 public $maxMessage = 'This collection should contain {{ limit }} element or less.|This collection should contain {{ limit }} elements or less.';
35 public $exactMessage = 'This collection should contain exactly {{ limit }} element.|This collection should contain exactly {{ limit }} elements.';
39 public function __construct($options = null)
41 if (null !== $options && !is_array($options)) {
48 parent::__construct($options);
50 if (null === $this->min && null === $this->max) {
51 throw new MissingOptionsException(sprintf('Either option "min" or "max" must be given for constraint %s', __CLASS__), array('min', 'max'));