Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
IpValidator.php
Go to the documentation of this file.
1<?php
2
4
6
16 protected $ref = Ip::V4;
17 const FLAGS = [
18 Ip::V4 => FILTER_FLAG_IPV4,
19 Ip::V6 => FILTER_FLAG_IPV6,
20 Ip::V4_NO_PRIV => FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE,
21 Ip::V6_NO_PRIV => FILTER_FLAG_IPV6 | FILTER_FLAG_NO_PRIV_RANGE,
22 Ip::ALL_NO_PRIV => FILTER_FLAG_NO_PRIV_RANGE,
23 Ip::V4_NO_RES => FILTER_FLAG_IPV4 | FILTER_FLAG_NO_RES_RANGE,
24 Ip::V6_NO_RES => FILTER_FLAG_IPV6 | FILTER_FLAG_NO_RES_RANGE,
25 Ip::ALL_NO_RES => FILTER_FLAG_NO_RES_RANGE,
26 Ip::V4_ONLY_PUBLIC => FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE,
27 Ip::V6_ONLY_PUBLIC => FILTER_FLAG_IPV6 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE,
28 Ip::ALL_ONLY_PUBLIC => FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ];
29
30 public function __construct() {
31 $this->message = "{value} is not a valid ip of type {ref}";
32 }
33
34 public function validate($value) {
35 parent::validate ( $value );
36 $value = ( string ) $value;
37 $flag = null;
38 if ($this->notNull !== false) {
39 if (isset ( self::FLAGS [$this->ref] )) {
40 $flag = self::FLAGS [$this->ref];
41 }
42 return \filter_var ( $value, \FILTER_VALIDATE_IP, $flag );
43 }
44 return true;
45 }
46
52 public function getParameters(): array {
53 return [ 'value','ref' ];
54 }
55}
56
Validates an address ip Usage @validator("ip","4") Inspired from Bernhard Schussek Symfony IpValidato...
getParameters()
{{}\Ubiquity\contents\validation\validators\ValidatorInterfacegetParameters()}