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 Range extends Constraint
|
Chris@0
|
24 {
|
Chris@0
|
25 const INVALID_CHARACTERS_ERROR = 'ad9a9798-7a99-4df7-8ce9-46e416a1e60b';
|
Chris@0
|
26 const TOO_HIGH_ERROR = '2d28afcb-e32e-45fb-a815-01c431a86a69';
|
Chris@0
|
27 const TOO_LOW_ERROR = '76454e69-502c-46c5-9643-f447d837c4d5';
|
Chris@0
|
28
|
Chris@17
|
29 protected static $errorNames = [
|
Chris@0
|
30 self::INVALID_CHARACTERS_ERROR => 'INVALID_CHARACTERS_ERROR',
|
Chris@0
|
31 self::TOO_HIGH_ERROR => 'TOO_HIGH_ERROR',
|
Chris@0
|
32 self::TOO_LOW_ERROR => 'TOO_LOW_ERROR',
|
Chris@17
|
33 ];
|
Chris@0
|
34
|
Chris@0
|
35 public $minMessage = 'This value should be {{ limit }} or more.';
|
Chris@0
|
36 public $maxMessage = 'This value should be {{ limit }} or less.';
|
Chris@0
|
37 public $invalidMessage = 'This value should be a valid number.';
|
Chris@0
|
38 public $min;
|
Chris@0
|
39 public $max;
|
Chris@0
|
40
|
Chris@0
|
41 public function __construct($options = null)
|
Chris@0
|
42 {
|
Chris@0
|
43 parent::__construct($options);
|
Chris@0
|
44
|
Chris@0
|
45 if (null === $this->min && null === $this->max) {
|
Chris@17
|
46 throw new MissingOptionsException(sprintf('Either option "min" or "max" must be given for constraint %s', __CLASS__), ['min', 'max']);
|
Chris@0
|
47 }
|
Chris@0
|
48 }
|
Chris@0
|
49 }
|