annotate vendor/symfony/validator/Constraints/Length.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents af1871eacc83
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 /*
Chris@0 4 * This file is part of the Symfony package.
Chris@0 5 *
Chris@0 6 * (c) Fabien Potencier <fabien@symfony.com>
Chris@0 7 *
Chris@0 8 * For the full copyright and license information, please view the LICENSE
Chris@0 9 * file that was distributed with this source code.
Chris@0 10 */
Chris@0 11
Chris@0 12 namespace Symfony\Component\Validator\Constraints;
Chris@0 13
Chris@0 14 use Symfony\Component\Validator\Constraint;
Chris@0 15 use Symfony\Component\Validator\Exception\MissingOptionsException;
Chris@0 16
Chris@0 17 /**
Chris@0 18 * @Annotation
Chris@0 19 * @Target({"PROPERTY", "METHOD", "ANNOTATION"})
Chris@0 20 *
Chris@0 21 * @author Bernhard Schussek <bschussek@gmail.com>
Chris@0 22 */
Chris@0 23 class Length extends Constraint
Chris@0 24 {
Chris@0 25 const TOO_SHORT_ERROR = '9ff3fdc4-b214-49db-8718-39c315e33d45';
Chris@0 26 const TOO_LONG_ERROR = 'd94b19cc-114f-4f44-9cc4-4138e80a87b9';
Chris@0 27 const INVALID_CHARACTERS_ERROR = '35e6a710-aa2e-4719-b58e-24b35749b767';
Chris@0 28
Chris@17 29 protected static $errorNames = [
Chris@0 30 self::TOO_SHORT_ERROR => 'TOO_SHORT_ERROR',
Chris@0 31 self::TOO_LONG_ERROR => 'TOO_LONG_ERROR',
Chris@0 32 self::INVALID_CHARACTERS_ERROR => 'INVALID_CHARACTERS_ERROR',
Chris@17 33 ];
Chris@0 34
Chris@0 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.';
Chris@0 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.';
Chris@0 37 public $exactMessage = 'This value should have exactly {{ limit }} character.|This value should have exactly {{ limit }} characters.';
Chris@0 38 public $charsetMessage = 'This value does not match the expected {{ charset }} charset.';
Chris@0 39 public $max;
Chris@0 40 public $min;
Chris@0 41 public $charset = 'UTF-8';
Chris@0 42
Chris@0 43 public function __construct($options = null)
Chris@0 44 {
Chris@17 45 if (null !== $options && !\is_array($options)) {
Chris@17 46 $options = [
Chris@0 47 'min' => $options,
Chris@0 48 'max' => $options,
Chris@17 49 ];
Chris@18 50 } elseif (\is_array($options) && isset($options['value']) && !isset($options['min']) && !isset($options['max'])) {
Chris@18 51 $options['min'] = $options['max'] = $options['value'];
Chris@18 52 unset($options['value']);
Chris@0 53 }
Chris@0 54
Chris@0 55 parent::__construct($options);
Chris@0 56
Chris@0 57 if (null === $this->min && null === $this->max) {
Chris@17 58 throw new MissingOptionsException(sprintf('Either option "min" or "max" must be given for constraint %s', __CLASS__), ['min', 'max']);
Chris@0 59 }
Chris@0 60 }
Chris@0 61 }