Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / symfony / validator / Constraints / Ip.php
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\ConstraintDefinitionException;
16
17 /**
18  * Validates that a value is a valid IP address.
19  *
20  * @Annotation
21  * @Target({"PROPERTY", "METHOD", "ANNOTATION"})
22  *
23  * @author Bernhard Schussek <bschussek@gmail.com>
24  * @author Joseph Bielawski <stloyd@gmail.com>
25  */
26 class Ip extends Constraint
27 {
28     const V4 = '4';
29     const V6 = '6';
30     const ALL = 'all';
31
32     // adds FILTER_FLAG_NO_PRIV_RANGE flag (skip private ranges)
33     const V4_NO_PRIV = '4_no_priv';
34     const V6_NO_PRIV = '6_no_priv';
35     const ALL_NO_PRIV = 'all_no_priv';
36
37     // adds FILTER_FLAG_NO_RES_RANGE flag (skip reserved ranges)
38     const V4_NO_RES = '4_no_res';
39     const V6_NO_RES = '6_no_res';
40     const ALL_NO_RES = 'all_no_res';
41
42     // adds FILTER_FLAG_NO_PRIV_RANGE and FILTER_FLAG_NO_RES_RANGE flags (skip both)
43     const V4_ONLY_PUBLIC = '4_public';
44     const V6_ONLY_PUBLIC = '6_public';
45     const ALL_ONLY_PUBLIC = 'all_public';
46
47     const INVALID_IP_ERROR = 'b1b427ae-9f6f-41b0-aa9b-84511fbb3c5b';
48
49     protected static $versions = array(
50         self::V4,
51         self::V6,
52         self::ALL,
53
54         self::V4_NO_PRIV,
55         self::V6_NO_PRIV,
56         self::ALL_NO_PRIV,
57
58         self::V4_NO_RES,
59         self::V6_NO_RES,
60         self::ALL_NO_RES,
61
62         self::V4_ONLY_PUBLIC,
63         self::V6_ONLY_PUBLIC,
64         self::ALL_ONLY_PUBLIC,
65     );
66
67     protected static $errorNames = array(
68         self::INVALID_IP_ERROR => 'INVALID_IP_ERROR',
69     );
70
71     public $version = self::V4;
72
73     public $message = 'This is not a valid IP address.';
74
75     /**
76      * {@inheritdoc}
77      */
78     public function __construct($options = null)
79     {
80         parent::__construct($options);
81
82         if (!in_array($this->version, self::$versions)) {
83             throw new ConstraintDefinitionException(sprintf('The option "version" must be one of "%s"', implode('", "', self::$versions)));
84         }
85     }
86 }