comparison vendor/symfony/validator/Constraints/Length.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 129ea1e6d783
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Component\Validator\Constraints;
13
14 use Symfony\Component\Validator\Constraint;
15 use Symfony\Component\Validator\Exception\MissingOptionsException;
16
17 /**
18 * @Annotation
19 * @Target({"PROPERTY", "METHOD", "ANNOTATION"})
20 *
21 * @author Bernhard Schussek <bschussek@gmail.com>
22 */
23 class Length extends Constraint
24 {
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';
28
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',
33 );
34
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.';
39 public $max;
40 public $min;
41 public $charset = 'UTF-8';
42
43 public function __construct($options = null)
44 {
45 if (null !== $options && !is_array($options)) {
46 $options = array(
47 'min' => $options,
48 'max' => $options,
49 );
50 }
51
52 parent::__construct($options);
53
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'));
56 }
57 }
58 }