1 | <?php |
||
5 | trait IpHelper |
||
6 | { |
||
7 | /** |
||
8 | * Returns client IP. |
||
9 | * If a proxy used this returns X_FORWARDED_FOR IP. |
||
10 | * |
||
11 | * @return string |
||
12 | */ |
||
13 | protected function getClientIp() |
||
17 | |||
18 | /** |
||
19 | * Checks client IP against allowed ips. |
||
20 | * |
||
21 | * @param $clientIp |
||
22 | * |
||
23 | * @return bool |
||
24 | * |
||
25 | * @throws \Exception |
||
26 | */ |
||
27 | protected function isAllowed($clientIp) |
||
39 | |||
40 | /** |
||
41 | * Returns allowed Ips from config. |
||
42 | * |
||
43 | * @return mixed |
||
44 | * |
||
45 | * @throws \Exception |
||
46 | */ |
||
47 | protected function getAllowedIps() |
||
61 | |||
62 | /** |
||
63 | * Quick way to check if the given ip is a range. |
||
64 | * |
||
65 | * @param $ipRange |
||
66 | * |
||
67 | * @return bool |
||
68 | */ |
||
69 | protected function isARange($ipRange) |
||
73 | |||
74 | /** |
||
75 | * Compare a given ip against an ip or a an ip range. |
||
76 | * |
||
77 | * @param $ip |
||
78 | * @param $ipOrRange |
||
79 | * |
||
80 | * @return bool |
||
81 | */ |
||
82 | protected function ipEqualOrInRange($ip, $ipOrRange) |
||
88 | |||
89 | /** |
||
90 | * Checks if a given ip belongs to an ip Range. |
||
91 | * |
||
92 | * @param $ip |
||
93 | * @param $range |
||
94 | * |
||
95 | * @return bool |
||
96 | */ |
||
97 | protected function ipInRange($ip, $range) |
||
106 | |||
107 | private function commaSepratedValues($csv, $trim = true) |
||
121 | } |
||
122 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: