1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Anax\Controller; |
4
|
|
|
|
5
|
|
|
use Anax\Commons\ContainerInjectableInterface; |
6
|
|
|
use Anax\Commons\ContainerInjectableTrait; |
7
|
|
|
|
8
|
|
|
// use Anax\Route\Exception\ForbiddenException; |
9
|
|
|
// use Anax\Route\Exception\NotFoundException; |
10
|
|
|
// use Anax\Route\Exception\InternalErrorException; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* A sample controller to show how a controller class can be implemented. |
14
|
|
|
* The controller will be injected with $di if implementing the interface |
15
|
|
|
* ContainerInjectableInterface, like this sample class does. |
16
|
|
|
* The controller is mounted on a particular route and can then handle all |
17
|
|
|
* requests for that mount point. |
18
|
|
|
* |
19
|
|
|
* @SuppressWarnings(PHPMD.TooManyPublicMethods) |
20
|
|
|
*/ |
21
|
|
|
class IpJsonController implements ContainerInjectableInterface |
22
|
|
|
{ |
23
|
|
|
use ContainerInjectableTrait; |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var string $db a sample member variable that gets initialised |
29
|
|
|
*/ |
30
|
|
|
private $db = "not active"; |
31
|
|
|
|
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
|
|
|
public function initialize() : void |
42
|
|
|
{ |
43
|
|
|
// Use to initialise member variables. |
44
|
|
|
$this->db = "active"; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function indexActionGet() : array |
48
|
|
|
{ |
49
|
|
|
$request = $this->di->get("request"); |
50
|
|
|
$ip = $request->getGet("ip"); |
51
|
|
|
$domain = "Not found"; |
52
|
|
|
|
53
|
|
|
if (filter_var($ip, FILTER_VALIDATE_IP)) { |
54
|
|
|
if (gethostbyaddr($ip) != $ip) { |
55
|
|
|
$domain = gethostbyaddr($ip); |
56
|
|
|
} |
57
|
|
|
$json = [ |
58
|
|
|
"valid" => "True", |
59
|
|
|
"ip" => $ip, |
60
|
|
|
"domain" => $domain, |
61
|
|
|
]; |
62
|
|
|
} else { |
63
|
|
|
$json = [ |
64
|
|
|
"valid" => "False", |
65
|
|
|
"ip" => $ip, |
66
|
|
|
"domain" => $domain, |
67
|
|
|
]; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
$title = "Ip Validator"; |
|
|
|
|
72
|
|
|
|
73
|
|
|
|
74
|
|
|
|
75
|
|
|
return [$json]; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|