knasenn /
vaderanax
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Anax\jsonweather; |
||
| 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 JsonWeatherController implements ContainerInjectableInterface |
||
| 22 | { |
||
| 23 | use ContainerInjectableTrait; |
||
| 24 | |||
| 25 | |||
| 26 | |||
| 27 | |||
| 28 | /** |
||
| 29 | * This is the index method action, it handles: |
||
| 30 | * ANY METHOD mountpoint |
||
| 31 | * ANY METHOD mountpoint/ |
||
| 32 | * ANY METHOD mountpoint/index |
||
| 33 | * |
||
| 34 | * @return string |
||
| 35 | */ |
||
| 36 | 1 | public function indexActionGet() : object |
|
| 37 | { |
||
| 38 | 1 | $page = $this->di->get("page"); |
|
| 39 | // $adress = $_SERVER["REMOTE_ADDR"] ?? ""; |
||
| 40 | 1 | $adress = $_SERVER["HTTP_X_FORWARDED_FOR"] ?? ""; |
|
| 41 | |||
| 42 | $data = [ |
||
| 43 | 1 | "test" => "testing", |
|
| 44 | 1 | "adress" => $adress, |
|
| 45 | ]; |
||
| 46 | |||
| 47 | 1 | $page->add("jsonweather/index", $data); |
|
| 48 | |||
| 49 | 1 | return $page->render(); |
|
| 50 | } |
||
| 51 | |||
| 52 | |||
| 53 | |||
| 54 | /** |
||
| 55 | * This is the index method action, it handles: |
||
| 56 | * ANY METHOD mountpoint |
||
| 57 | * ANY METHOD mountpoint/ |
||
| 58 | * ANY METHOD mountpoint/index |
||
| 59 | * |
||
| 60 | * @return string |
||
| 61 | */ |
||
| 62 | 1 | public function indexActionPost() : array |
|
| 63 | { |
||
| 64 | //gets pagestuff? |
||
| 65 | 1 | $page = $this->di->get("page"); |
|
|
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
|
|||
| 66 | //get ip |
||
| 67 | 1 | $ip = $this->di->request->getPOST("ip"); |
|
|
0 ignored issues
–
show
|
|||
| 68 | //get dateChecked |
||
| 69 | 1 | $dateChecked = $this->di->request->getPOST("dateChecked"); |
|
| 70 | |||
| 71 | //Creates validate-class object |
||
| 72 | 1 | $validate = $this->di->get("validator"); |
|
| 73 | //Validates ip |
||
| 74 | 1 | $resValidateIp = $validate->validateIp($ip); |
|
| 75 | //Gets hostname |
||
| 76 | 1 | $resDomain = $validate->getDomain($ip); |
|
| 77 | |||
| 78 | 1 | $curl = new \Aiur\Curl\Curl(); |
|
| 79 | //Gets curl adress |
||
| 80 | 1 | $resCurlAdress = $curl->getCurlAdress($ip, $resValidateIp); |
|
| 81 | |||
| 82 | |||
| 83 | 1 | if (is_array($resCurlAdress)) { |
|
|
0 ignored issues
–
show
|
|||
| 84 | 1 | if (is_float($resCurlAdress[0])) { |
|
| 85 | 1 | if ($dateChecked == "plusweek") { |
|
| 86 | 1 | $resCurlTempWeek = $curl->getCurlTemp($resCurlAdress[0], $resCurlAdress[1], $dateChecked); |
|
| 87 | 1 | } elseif ($dateChecked == "minusmonth") { |
|
| 88 | 1 | $resCurlTempMonth = $curl->getCurlTemp($resCurlAdress[0], $resCurlAdress[1], $dateChecked); |
|
| 89 | } |
||
| 90 | 1 | } elseif (is_string($resCurlAdress[0])) { |
|
| 91 | 1 | $notValid = "Search was not valid!"; |
|
| 92 | } |
||
| 93 | } else { |
||
| 94 | 1 | if ($dateChecked == "plusweek") { |
|
| 95 | 1 | $resCurlTempWeek = $curl->getCurlTemp($resCurlAdress->latitude, $resCurlAdress->longitude, $dateChecked); |
|
|
0 ignored issues
–
show
|
|||
| 96 | 1 | } elseif ($dateChecked == "minusmonth") { |
|
| 97 | 1 | $resCurlTempMonth = $curl->getCurlTemp($resCurlAdress->latitude, $resCurlAdress->longitude, $dateChecked); |
|
| 98 | } |
||
| 99 | } |
||
| 100 | $data = [ |
||
| 101 | 1 | "ipval" => $resValidateIp, |
|
| 102 | 1 | "host" => $resDomain, |
|
| 103 | 1 | "latitude" => $resCurlAdress->latitude ?? "", |
|
| 104 | 1 | "longitude" => $resCurlAdress->longitude ?? "", |
|
| 105 | 1 | "country_name" => $resCurlAdress->country_name ?? "", |
|
|
0 ignored issues
–
show
|
|||
| 106 | 1 | "region_name" => $resCurlAdress->region_name ?? "", |
|
|
0 ignored issues
–
show
|
|||
| 107 | 1 | "resTempWeek" => $resCurlTempWeek->daily->data ?? "", |
|
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
| 108 | 1 | "resTempMonth" => $resCurlTempMonth ?? "", |
|
| 109 | 1 | "notValid" => $notValid ?? "" |
|
| 110 | ]; |
||
| 111 | |||
| 112 | // $page->add("jsonweather/weather", $data); |
||
| 113 | |||
| 114 | |||
| 115 | 1 | return [$data]; |
|
|
0 ignored issues
–
show
|
|||
| 116 | } |
||
| 117 | } |
||
| 118 |