-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIpField.php
48 lines (41 loc) · 973 Bytes
/
IpField.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
declare(strict_types=1);
/*
* Studio 107 (c) 2017 Maxim Falaleev
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mindy\Orm\Fields;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Class IpField.
*/
class IpField extends CharField
{
/**
* @var int
*/
public $version = 4;
/**
* IpField constructor.
*
* @param array $config
*/
public function __construct(array $config = [])
{
parent::__construct($config);
if (!in_array($this->version, [4, 6])) {
throw new \LogicException('Unknown IP protocol version. Allowed 4 and 6');
}
}
/**
* @return array
*/
public function getValidationConstraints()
{
return array_merge(parent::getValidationConstraints(), [
new Assert\Ip(['version' => $this->version]),
]);
}
}