1 | <?php |
||
18 | class IP implements ExcluderInterface |
||
19 | { |
||
20 | /** |
||
21 | * List of IPs to be excluded. |
||
22 | * |
||
23 | * @var array |
||
24 | */ |
||
25 | protected $ips = []; |
||
26 | |||
27 | /** |
||
28 | * Allowed proxies. |
||
29 | * |
||
30 | * @var array |
||
31 | */ |
||
32 | protected $trustedProxies = []; |
||
33 | |||
34 | /** |
||
35 | * @param string|array|null $ips |
||
36 | * @param string|array|null $trustedProxies |
||
37 | * |
||
38 | * @throws \InvalidArgumentException |
||
39 | */ |
||
40 | public function __construct($ips = null, $trustedProxies = null) |
||
62 | |||
63 | /** |
||
64 | * Add IP. |
||
65 | * |
||
66 | * @param string $ipAddress |
||
67 | * |
||
68 | * @throws \InvalidArgumentException |
||
69 | * |
||
70 | * @return $this |
||
71 | */ |
||
72 | public function addIP($ipAddress) |
||
82 | |||
83 | /** |
||
84 | * Add Trusted proxy. |
||
85 | * |
||
86 | * @param string $ipAddress |
||
87 | * |
||
88 | * @throws \InvalidArgumentException |
||
89 | * |
||
90 | * @return $this |
||
91 | */ |
||
92 | public function addTrustedProxy($ipAddress) |
||
102 | |||
103 | /** |
||
104 | * {@inheritdoc} |
||
105 | */ |
||
106 | public function isExcluded(ServerRequestInterface $request) |
||
118 | |||
119 | /** |
||
120 | * Find client's IP. |
||
121 | * |
||
122 | * @param ServerRequestInterface $request |
||
123 | * |
||
124 | * @return string|null |
||
125 | */ |
||
126 | protected function determineCurrentIp(ServerRequestInterface $request) |
||
158 | |||
159 | /** |
||
160 | * Return current IP retrieved from server parameters. |
||
161 | * |
||
162 | * @param ServerRequestInterface $request |
||
163 | * |
||
164 | * @return string|null |
||
165 | */ |
||
166 | private function getIpFromServerParams(ServerRequestInterface $request) |
||
177 | |||
178 | /** |
||
179 | * Check IP validity. |
||
180 | * |
||
181 | * @param string $ipAddress |
||
182 | * |
||
183 | * @return bool |
||
184 | */ |
||
185 | private function isValidIp($ipAddress) |
||
189 | } |
||
190 |