| Total Complexity | 6 |
| Total Lines | 38 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 16 | class IPExtension extends DataExtension |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * @var array<string,string> |
||
| 20 | */ |
||
| 21 | private static $db = [ |
||
|
|
|||
| 22 | "IP" => "Varchar(45)" |
||
| 23 | ]; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @return void |
||
| 27 | */ |
||
| 28 | public function onBeforeWrite() |
||
| 29 | { |
||
| 30 | if (!Controller::has_curr()) { |
||
| 31 | return; |
||
| 32 | } |
||
| 33 | $controller = Controller::curr(); |
||
| 34 | // This is best used when IP is set on creation |
||
| 35 | if (!$this->owner->IP) { |
||
| 36 | $ip = $controller->getRequest()->getIP(); |
||
| 37 | $this->owner->IP = $ip; |
||
| 38 | } |
||
| 39 | } |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @return \LeKoala\GeoTools\Models\Address|null |
||
| 43 | */ |
||
| 44 | public function getIpLocationDetails() |
||
| 54 | } |
||
| 55 | } |
||
| 56 |