1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Hab\MeModule; |
4
|
|
|
|
5
|
|
|
use Anax\Commons\ContainerInjectableInterface; |
6
|
|
|
use Anax\Commons\ContainerInjectableTrait; |
7
|
|
|
use Hab\Model; |
|
|
|
|
8
|
|
|
|
9
|
|
|
// use Anax\Route\Exception\ForbiddenException; |
10
|
|
|
// use Anax\Route\Exception\NotFoundException; |
11
|
|
|
// use Anax\Route\Exception\InternalErrorException; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* A sample controller to show how a controller class can be implemented. |
15
|
|
|
* The controller will be injected with $di if implementing the interface |
16
|
|
|
* ContainerInjectableInterface, like this sample class does. |
17
|
|
|
* The controller is mounted on a particular route and can then handle all |
18
|
|
|
* requests for that mount point. |
19
|
|
|
* |
20
|
|
|
* @SuppressWarnings(PHPMD.TooManyPublicMethods) |
21
|
|
|
*/ |
22
|
|
|
class GeoJSONController implements ContainerInjectableInterface |
23
|
|
|
{ |
24
|
|
|
use ContainerInjectableTrait; |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var string $res is the response of filters on selected IP |
30
|
|
|
*/ |
31
|
|
|
private $res = []; |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* The initialize method is optional and will always be called before the |
36
|
|
|
* target method/action. This is a convienient method where you could |
37
|
|
|
* setup internal properties that are commonly used by several methods. |
38
|
|
|
* |
39
|
|
|
* @return void |
40
|
|
|
*/ |
41
|
2 |
|
public function initialize() : void |
42
|
|
|
{ |
43
|
|
|
// Use to initialise member variables. |
44
|
2 |
|
$this->res = []; |
|
|
|
|
45
|
2 |
|
} |
46
|
|
|
|
47
|
1 |
|
public function searchActionPost() |
48
|
|
|
{ |
49
|
1 |
|
$request = $this->di->get("request"); |
50
|
1 |
|
$ip = $request->getPost("ip"); |
51
|
1 |
|
$validator = new \Hab\MeModule\ValidateIP($ip); |
52
|
1 |
|
$data = $validator->sendRes(); |
53
|
|
|
$res = [ |
54
|
1 |
|
"error" => "invalid format" |
55
|
|
|
]; |
56
|
1 |
|
if ($data["isValid"]) { |
57
|
1 |
|
$api = require(ANAX_INSTALL_PATH . "/config.php"); |
58
|
1 |
|
$key = $api["key"]; |
59
|
1 |
|
$fetch = new \Hab\MeModule\Fetch("GET", "http://api.ipstack.com/$ip?access_key=$key"); |
60
|
1 |
|
$res = $fetch->fetch(); |
61
|
|
|
} |
62
|
1 |
|
return [$res]; |
63
|
|
|
} |
64
|
|
|
|
65
|
1 |
|
public function searchActionGet() |
66
|
|
|
{ |
67
|
1 |
|
$request = $this->di->get("request"); |
68
|
1 |
|
$ip = $request->getGet("ip"); |
69
|
1 |
|
$validator = new \Hab\MeModule\ValidateIP($ip); |
70
|
1 |
|
$data = $validator->sendRes(); |
71
|
|
|
$res = [ |
72
|
1 |
|
"error" => "invalid format" |
73
|
|
|
]; |
74
|
1 |
|
if ($data["isValid"]) { |
75
|
1 |
|
$api = require(ANAX_INSTALL_PATH . "/config.php"); |
76
|
1 |
|
$key = $api["key"]; |
77
|
1 |
|
$fetch = new \Hab\MeModule\Fetch("GET", "http://api.ipstack.com/$ip?access_key=$key"); |
78
|
1 |
|
$res = $fetch->fetch(); |
79
|
|
|
} |
80
|
1 |
|
return [$res]; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
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