1 | <?php |
||
32 | class RemoteIp extends ObjectAbstract implements ValidatorInterface |
||
33 | { |
||
34 | /** |
||
35 | * Allowed ip patterns |
||
36 | * |
||
37 | * @var array |
||
38 | * @access protected |
||
39 | */ |
||
40 | protected $allowed; |
||
41 | |||
42 | /** |
||
43 | * Denied ip patterns |
||
44 | * |
||
45 | * @var array |
||
46 | * @access protected |
||
47 | */ |
||
48 | protected $denied; |
||
49 | |||
50 | /** |
||
51 | * Inject allowed or denied ip patterns like '216.110.124.0/24' etc. |
||
52 | * |
||
53 | * @param array $denied |
||
54 | * @param array $allowed |
||
55 | * @access protected |
||
56 | */ |
||
57 | public function __construct(array $denied = [], array $allowed = []) |
||
61 | |||
62 | /** |
||
63 | * {@inheritDoc} |
||
64 | */ |
||
65 | public function validate()/*# : bool */ |
||
81 | |||
82 | /** |
||
83 | * Set allowed patterns |
||
84 | * |
||
85 | * @param array $patterns |
||
86 | * @return $this |
||
87 | * @access public |
||
88 | */ |
||
89 | public function setAllowed(array $patterns) |
||
94 | |||
95 | /** |
||
96 | * Set denied patterns |
||
97 | * |
||
98 | * @param array $patterns |
||
99 | * @return $this |
||
100 | * @access public |
||
101 | */ |
||
102 | public function setDenied(array $patterns) |
||
107 | |||
108 | /** |
||
109 | * Match ip with patterns |
||
110 | * |
||
111 | * @param string $ip |
||
112 | * @param array $patterns |
||
113 | * @return boolean |
||
114 | * @access protected |
||
115 | */ |
||
116 | protected function matchIp(/*# string */ $ip, array $patterns)/*# : bool */ |
||
126 | |||
127 | /** |
||
128 | * Pre-process ip matching pattern |
||
129 | * |
||
130 | * @param array $patterns |
||
131 | * @return array |
||
132 | * @access protected |
||
133 | */ |
||
134 | protected function processPattern(array $patterns)/*# : array */ |
||
150 | |||
151 | /** |
||
152 | * Convert mask length to mask in decimal |
||
153 | * |
||
154 | * @param int $length |
||
155 | * @return int |
||
156 | * @access protected |
||
157 | */ |
||
158 | protected function getMask(/*# int */ $length = 32)/*# : int */ |
||
163 | } |
||
164 |