|
1
|
|
|
<?php |
|
2
|
|
|
namespace Moody\ControllerIP; |
|
3
|
|
|
|
|
4
|
|
|
use Anax\Commons\ContainerInjectableInterface; |
|
5
|
|
|
use Anax\Commons\ContainerInjectableTrait; |
|
6
|
|
|
|
|
7
|
|
|
// use Anax\Route\Exception\ForbiddenException; |
|
8
|
|
|
// use Anax\Route\Exception\NotFoundException; |
|
9
|
|
|
// use Anax\Route\Exception\InternalErrorException; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* A sample controller to show how a controller class can be implemented. |
|
13
|
|
|
* The controller will be injected with $di if implementing the interface |
|
14
|
|
|
* ContainerInjectableInterface, like this sample class does. |
|
15
|
|
|
* The controller is mounted on a particular route and can then handle all |
|
16
|
|
|
* requests for that mount point. |
|
17
|
|
|
* |
|
18
|
|
|
* @SuppressWarnings(PHPMD.TooManyPublicMethods) |
|
19
|
|
|
*/ |
|
20
|
|
|
class IpController implements ContainerInjectableInterface |
|
21
|
|
|
{ |
|
22
|
|
|
use ContainerInjectableTrait; |
|
23
|
|
|
|
|
24
|
|
|
private $ipAddress; |
|
25
|
|
|
private $object; |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
2 |
|
public function result($ipAddress, $object) : string |
|
29
|
|
|
{ |
|
30
|
2 |
|
if ($object->getProtocol($ipAddress)) { |
|
31
|
1 |
|
return "The IP $ipAddress is a valid " . $object->getProtocol($ipAddress) ." address." ; |
|
32
|
|
|
} |
|
33
|
1 |
|
return "The IP $ipAddress is not a valid ip-Address."; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
1 |
|
public function indexAction() : object |
|
37
|
|
|
{ |
|
38
|
|
|
// Deal with the action and return a response. |
|
39
|
1 |
|
$protocol = null; |
|
|
|
|
|
|
40
|
1 |
|
$host = null; |
|
|
|
|
|
|
41
|
1 |
|
$address = null; |
|
|
|
|
|
|
42
|
|
|
|
|
43
|
1 |
|
$title = "Ip validator"; |
|
44
|
1 |
|
$page = $this->di->get("page"); |
|
45
|
1 |
|
$request = $this->di->get("request"); |
|
46
|
1 |
|
$this->ipAddress = $request->getGet("ip"); |
|
47
|
1 |
|
$ip = $this->ipAddress; |
|
|
|
|
|
|
48
|
|
|
|
|
49
|
1 |
|
$this->object = new IpValidate(); |
|
50
|
1 |
|
$protocol = $this->result($this->ipAddress, $this->object); |
|
51
|
1 |
|
$host = $this->object->getDomain($this->ipAddress); |
|
52
|
1 |
|
$address = $this->object->getAddress($this->ipAddress); |
|
53
|
1 |
|
$ip = $this->object->getCurrentIp($this->ipAddress); |
|
|
|
|
|
|
54
|
1 |
|
$Domain = $this->object->getDomain($this->ipAddress); |
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
1 |
|
$data["ip"] = $ip; |
|
|
|
|
|
|
58
|
1 |
|
$data["protocol"] = $protocol; |
|
59
|
1 |
|
$data["host"] = $host; |
|
60
|
1 |
|
$data["address"] = $address; |
|
61
|
1 |
|
$data["Domain"] = $Domain; |
|
62
|
|
|
|
|
63
|
|
|
|
|
64
|
1 |
|
$page->add("id/index", $data); |
|
65
|
1 |
|
return $page->render([ |
|
66
|
1 |
|
"title" => $title, |
|
67
|
|
|
]); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|