1 | <?php |
||
9 | class IPLoggerService extends Object |
||
|
|||
10 | { |
||
11 | private static $rules = array(); |
||
12 | |||
13 | private static $delete_expired = false; |
||
14 | |||
15 | private static $dependencies = array( |
||
16 | 'loggerEntry' => '%$IPLoggerEntry', |
||
17 | 'banEntry' => '%$IPBanEntry' |
||
18 | ); |
||
19 | |||
20 | protected $rule = null; |
||
21 | |||
22 | public function __construct() |
||
25 | |||
26 | /** |
||
27 | * Returns the IP address of the current client; relies on |
||
28 | * {@link SS_HTTPRequest} to provide the IP address. |
||
29 | * |
||
30 | * @return string The current clients IP address |
||
31 | */ |
||
32 | public function getIP() |
||
38 | |||
39 | /** |
||
40 | * Logs an event against a clients IP address. |
||
41 | * |
||
42 | * @param $event string The event being logged. |
||
43 | */ |
||
44 | public function log($event) |
||
53 | |||
54 | /** |
||
55 | * Get's an array of logs related to the clients IP and the supplied event. |
||
56 | * |
||
57 | * @param string $event The event |
||
58 | * @return DataList A list of logged events |
||
59 | */ |
||
60 | public function getEntries($event) |
||
75 | |||
76 | /** |
||
77 | * If a rule exists for a specific event; return it. |
||
78 | * |
||
79 | * Any rules found are checked for validity and an error thrown if incorrect. |
||
80 | * Rules should be defined in .yml config files using the following format. |
||
81 | * |
||
82 | * <code> |
||
83 | * IPLoggerService: |
||
84 | * rules: |
||
85 | * submit_contact_form: |
||
86 | * findtime: 60 |
||
87 | * hits: 4 |
||
88 | * bantime: 600 |
||
89 | * </code> |
||
90 | * |
||
91 | * @param string $event The event we want a rule for |
||
92 | * @return array|null The rule array |
||
93 | */ |
||
94 | public function getRule($event) |
||
115 | |||
116 | /** |
||
117 | * Get a date x seconds ago. |
||
118 | * |
||
119 | * @param integer $seconds The number of seconds to subtract |
||
120 | * @return DateTime |
||
121 | */ |
||
122 | public function getPastDate($seconds) |
||
132 | |||
133 | public function pruneEntries($event) |
||
163 | |||
164 | /** |
||
165 | * Checks if a specific client IP is allowed to perform an event |
||
166 | * |
||
167 | * First if there is no rule supplied for an event string, we assume |
||
168 | * that user can perform this event as many times as needed and it should |
||
169 | * be logged but not restricted. |
||
170 | * Next a check if performed to see if a client IP has been banned from |
||
171 | * performing an event. |
||
172 | * Finally we calculate the total number of logs for an event and check |
||
173 | * these are within the limits set by the rules. If they are not withing |
||
174 | * the limit apply a ban. |
||
175 | * |
||
176 | * @param string $event The event to check |
||
177 | * @return boolean|string Is the client allowd to perform $event |
||
178 | */ |
||
179 | public function checkAllowed($event) |
||
232 | } |
||
233 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.