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 Length extends Constraint Chris@0: { Chris@0: const TOO_SHORT_ERROR = '9ff3fdc4-b214-49db-8718-39c315e33d45'; Chris@0: const TOO_LONG_ERROR = 'd94b19cc-114f-4f44-9cc4-4138e80a87b9'; Chris@0: const INVALID_CHARACTERS_ERROR = '35e6a710-aa2e-4719-b58e-24b35749b767'; Chris@0: Chris@17: protected static $errorNames = [ Chris@0: self::TOO_SHORT_ERROR => 'TOO_SHORT_ERROR', Chris@0: self::TOO_LONG_ERROR => 'TOO_LONG_ERROR', Chris@0: self::INVALID_CHARACTERS_ERROR => 'INVALID_CHARACTERS_ERROR', Chris@17: ]; Chris@0: Chris@0: 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.'; Chris@0: 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.'; Chris@0: public $exactMessage = 'This value should have exactly {{ limit }} character.|This value should have exactly {{ limit }} characters.'; Chris@0: public $charsetMessage = 'This value does not match the expected {{ charset }} charset.'; Chris@0: public $max; Chris@0: public $min; Chris@0: public $charset = 'UTF-8'; 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: }