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 | public $loggerEntry; |
||
21 | |||
22 | public $banEntry; |
||
23 | |||
24 | public function __construct() |
||
27 | |||
28 | /** |
||
29 | * Returns the IP address of the current client; relies on |
||
30 | * {@link SS_HTTPRequest} to provide the IP address. |
||
31 | * |
||
32 | * @return string The current clients IP address |
||
33 | */ |
||
34 | public function getIP() |
||
40 | |||
41 | /** |
||
42 | * Logs an event against a clients IP address. |
||
43 | * |
||
44 | * @param $event string The event being logged. |
||
45 | */ |
||
46 | public function log($event) |
||
55 | |||
56 | /** |
||
57 | * Get's an array of logs related to the clients IP and the supplied event. |
||
58 | * |
||
59 | * @param string $event The event |
||
60 | * @return DataList A list of logged events |
||
61 | */ |
||
62 | public function getEntries($event) |
||
77 | |||
78 | /** |
||
79 | * If a rule exists for a specific event; return it. |
||
80 | * |
||
81 | * Any rules found are checked for validity and an error thrown if incorrect. |
||
82 | * Rules should be defined in .yml config files using the following format. |
||
83 | * |
||
84 | * <code> |
||
85 | * IPLoggerService: |
||
86 | * rules: |
||
87 | * submit_contact_form: |
||
88 | * findtime: 60 |
||
89 | * hits: 4 |
||
90 | * bantime: 600 |
||
91 | * </code> |
||
92 | * |
||
93 | * @param string $event The event we want a rule for |
||
94 | * @return array|null The rule array |
||
95 | */ |
||
96 | public function getRule($event) |
||
117 | |||
118 | /** |
||
119 | * Get a date x seconds ago. |
||
120 | * |
||
121 | * @param integer $seconds The number of seconds to subtract |
||
122 | * @return DateTime |
||
123 | */ |
||
124 | public function getPastDate($seconds) |
||
134 | |||
135 | /** |
||
136 | * Checks if a specific client IP is allowed to perform an event |
||
137 | * |
||
138 | * First if there is no rule supplied for an event string, we assume |
||
139 | * that user can perform this event as many times as needed and it should |
||
140 | * be logged but not restricted. |
||
141 | * Next a check if performed to see if a client IP has been banned from |
||
142 | * performing an event. |
||
143 | * Finally we calculate the total number of logs for an event and check |
||
144 | * these are within the limits set by the rules. If they are not withing |
||
145 | * the limit apply a ban. |
||
146 | * |
||
147 | * @param string $event The event to check |
||
148 | * @return boolean|string Is the client allowd to perform $event |
||
149 | */ |
||
150 | public function checkAllowed($event) |
||
208 | } |
||
209 |
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.