annotate vendor/symfony/validator/Constraints/Length.php @ 8:50b0d041100e

Further files for download
author Chris Cannam
date Mon, 05 Feb 2018 10:56:40 +0000
parents 4c8ae668cc8c
children 129ea1e6d783
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@0 29 protected static $errorNames = array(
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@0 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@0 45 if (null !== $options && !is_array($options)) {
Chris@0 46 $options = array(
Chris@0 47 'min' => $options,
Chris@0 48 'max' => $options,
Chris@0 49 );
Chris@0 50 }
Chris@0 51
Chris@0 52 parent::__construct($options);
Chris@0 53
Chris@0 54 if (null === $this->min && null === $this->max) {
Chris@0 55 throw new MissingOptionsException(sprintf('Either option "min" or "max" must be given for constraint %s', __CLASS__), array('min', 'max'));
Chris@0 56 }
Chris@0 57 }
Chris@0 58 }