1 | <?php |
||
2 | |||
3 | namespace LeKoala\CommonExtensions; |
||
4 | |||
5 | use SilverStripe\ORM\DataExtension; |
||
6 | use SilverStripe\Control\Controller; |
||
7 | use SilverStripe\Core\Injector\Injector; |
||
8 | |||
9 | /** |
||
10 | * Store IP as binary |
||
11 | * |
||
12 | * @link https://stackoverflow.com/questions/22636912/store-both-ipv4-and-ipv6-address-in-a-single-column |
||
13 | * @property \BinaryIPExtension $owner |
||
14 | * @property string $IP |
||
15 | */ |
||
16 | class BinaryIPExtension extends DataExtension |
||
17 | { |
||
18 | private static $db = [ |
||
19 | "IP" => "BinaryIP" |
||
20 | ]; |
||
21 | |||
22 | public function onBeforeWrite() |
||
23 | { |
||
24 | $controller = Controller::curr(); |
||
25 | // This is best used when IP is set on creation |
||
26 | if (!$this->owner->IP) { |
||
27 | $ip = $controller->getRequest()->getIP(); |
||
28 | $this->owner->IP = $ip; |
||
29 | } |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * This require geotools module |
||
34 | * |
||
35 | * @return \LeKoala\GeoTools\Models\Address|null |
||
0 ignored issues
–
show
|
|||
36 | */ |
||
37 | public function getIpLocationDetails() |
||
38 | { |
||
39 | if (!$this->owner->IP) { |
||
40 | return null; |
||
41 | } |
||
42 | $geolocator = Injector::inst()->get(\LeKoala\Geo\Services\Geolocator::class); |
||
0 ignored issues
–
show
The type
LeKoala\Geo\Services\Geolocator was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
43 | return $geolocator->geolocate($this->owner->IP); |
||
44 | } |
||
45 | } |
||
46 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths