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 Length extends Constraint
25 const TOO_SHORT_ERROR = '9ff3fdc4-b214-49db-8718-39c315e33d45';
26 const TOO_LONG_ERROR = 'd94b19cc-114f-4f44-9cc4-4138e80a87b9';
27 const INVALID_CHARACTERS_ERROR = '35e6a710-aa2e-4719-b58e-24b35749b767';
29 protected static $errorNames = array(
30 self::TOO_SHORT_ERROR => 'TOO_SHORT_ERROR',
31 self::TOO_LONG_ERROR => 'TOO_LONG_ERROR',
32 self::INVALID_CHARACTERS_ERROR => 'INVALID_CHARACTERS_ERROR',
35 public $maxMessage = 'This value is too long. It should have {{ limit }} character or less.|This value is too long. It should have {{ limit }} characters or less.';
36 public $minMessage = 'This value is too short. It should have {{ limit }} character or more.|This value is too short. It should have {{ limit }} characters or more.';
37 public $exactMessage = 'This value should have exactly {{ limit }} character.|This value should have exactly {{ limit }} characters.';
38 public $charsetMessage = 'This value does not match the expected {{ charset }} charset.';
41 public $charset = 'UTF-8';
43 public function __construct($options = null)
45 if (null !== $options && !is_array($options)) {
52 parent::__construct($options);
54 if (null === $this->min && null === $this->max) {
55 throw new MissingOptionsException(sprintf('Either option "min" or "max" must be given for constraint %s', __CLASS__), array('min', 'max'));