1 | <?php |
||
2 | namespace Anax\Controller; |
||
3 | |||
4 | use \Anax\darkSkyApi; |
||
5 | |||
6 | use Anax\Commons\ContainerInjectableInterface; |
||
7 | |||
8 | use Anax\Commons\ContainerInjectableTrait; |
||
9 | |||
10 | class DarkSkyController implements ContainerInjectableInterface |
||
11 | { |
||
12 | use ContainerInjectableTrait; |
||
13 | |||
14 | 1 | public function indexAction() : object |
|
15 | { |
||
16 | 1 | $title = " | Ip Json API"; |
|
17 | 1 | $page = $this->di->get("page"); |
|
18 | 1 | $page->add( |
|
19 | 1 | "anax/v2/DarkskyApi/darkSkyApi", |
|
20 | [ |
||
21 | 1 | "header" => "hello", |
|
22 | "text" => "text", |
||
23 | ] |
||
24 | ); |
||
25 | 1 | return $page->render([ |
|
26 | 1 | "title" => "$title" |
|
27 | ]); |
||
28 | } |
||
29 | |||
30 | |||
31 | |||
32 | 1 | public function indexJsonAction() : object |
|
33 | { |
||
34 | 1 | $title = " | Ip Json API"; |
|
35 | 1 | $page = $this->di->get("page"); |
|
36 | 1 | $page->add( |
|
37 | 1 | "anax/v2/DarkskyApi/darkSkyApiJson", |
|
38 | [ |
||
39 | 1 | "header" => "hello", |
|
40 | "text" => "text", |
||
41 | ] |
||
42 | ); |
||
43 | 1 | return $page->render([ |
|
44 | 1 | "title" => "$title" |
|
45 | ]); |
||
46 | } |
||
47 | |||
48 | |||
49 | |||
50 | |||
51 | |||
52 | |||
53 | |||
54 | |||
55 | |||
56 | |||
57 | 1 | public function darkActionPost($ipAdress = null) : object |
|
58 | { |
||
59 | 1 | $keykey = $this->di->get("apikey"); |
|
60 | 1 | $darkSkyKey = $this->di->get("apikeyDarkSky"); |
|
61 | 1 | $time = $this->di->get("request")->getPost("date") ?? ""; |
|
62 | 1 | $ipInfo = array(); |
|
63 | 1 | $ipInfo["IP"] = $this->di->get("request")->getPost("ip") ?? $ipAdress; |
|
64 | 1 | $array = []; |
|
65 | 1 | $apiEx = $this->di->get("ExternalApi"); |
|
66 | 1 | $res = $apiEx->validateipActionGet($ipInfo["IP"], $keykey); |
|
67 | |||
68 | 1 | $obj = json_decode($res); |
|
69 | |||
70 | 1 | if ($obj == null) { |
|
71 | 1 | $objSplit = explode(",", $ipInfo["IP"]); |
|
72 | 1 | $obj = new \stdClass(); |
|
73 | 1 | $obj->latitude = $objSplit[0]; |
|
74 | 1 | $obj->longitude = $objSplit[1]; |
|
75 | } |
||
76 | |||
77 | 1 | $coordinates = (object) ["latitude" => $obj->latitude]; |
|
78 | 1 | $coordinates->longitude = $obj->longitude; |
|
79 | |||
80 | 1 | $darkClass = new \Anax\darkSkyApi\DarkSky(); |
|
81 | 1 | array_push($array, $coordinates); |
|
82 | 1 | $res = $darkClass::wheatherActionGet($array, $darkSkyKey); |
|
83 | |||
84 | 1 | $dates = $darkClass::wheatherSevenActionGet(30, $time); |
|
85 | 1 | $resThirtyDaysRequest = $darkClass::wheatherThirtyActionGet($array, $dates, $darkSkyKey); |
|
86 | |||
87 | // try { |
||
88 | // if (array_key_exists("code",$res)) { |
||
89 | // throw new \Exception("Value must be 1 or below"); |
||
90 | // } |
||
91 | // |
||
92 | // } catch (\Exception $e) { |
||
93 | // return $res[0]; |
||
94 | // } |
||
95 | |||
96 | 1 | $streetname = $darkClass->streetActionGet($coordinates->longitude, $coordinates->latitude); |
|
97 | // |
||
98 | // $refinedDates = []; |
||
99 | // |
||
100 | // array_push($refinedDates, $dark::wheatherActionGet($array, $dates)); |
||
101 | |||
102 | // $datesJson = json_encode($dates); |
||
103 | // print_r(strtotime("2010-05-17 + 1 day")); |
||
104 | 1 | $title = " | Ip Json API"; |
|
105 | 1 | $page = $this->di->get("page"); |
|
106 | 1 | $page->add( |
|
107 | 1 | "anax/v2/DarkskyApi/darkRes", |
|
108 | [ |
||
109 | 1 | "header" => "hello", |
|
110 | 1 | "res" => $res, |
|
111 | 1 | "ogDate" => $time, |
|
112 | 1 | "resThirty" => $resThirtyDaysRequest, |
|
113 | 1 | "streetname" => $streetname |
|
114 | ] |
||
115 | ); |
||
116 | 1 | return $page->render([ |
|
117 | 1 | "title" => "$title" |
|
118 | ]); |
||
119 | } |
||
120 | |||
121 | |||
122 | |||
123 | 2 | public function darkJsonActionGet($ipAdress = null, $datepara = null, $di = null) : string |
|
124 | { |
||
125 | 2 | $this->di = $this->di ?? $di; |
|
126 | |||
127 | 2 | $resArray = []; |
|
128 | 2 | $ipInfo = array(); |
|
129 | |||
130 | 2 | $keykey = $this->di->get("apikey"); |
|
131 | 2 | $time = $this->di->get("request")->getGet("date") ?? $datepara; |
|
132 | 2 | $ipInfo["IP"] = $this->di->get("request")->getGet("ip") ?? $ipAdress; |
|
133 | 2 | $darkSkyKey = $this->di->get("apikeyDarkSky"); |
|
134 | |||
135 | 2 | $array = []; |
|
136 | 2 | $apiEx = $this->di->get("ExternalApi"); |
|
137 | 2 | $res = $apiEx->validateipActionGet($ipInfo["IP"], $keykey); |
|
138 | |||
139 | |||
140 | 2 | $obj = json_decode($res); |
|
141 | 2 | if ($obj == null) { |
|
142 | 1 | $objSplit = explode(",", $ipInfo["IP"]); |
|
143 | 1 | $obj = new \stdClass(); |
|
144 | 1 | $obj->latitude = $objSplit[0]; |
|
145 | 1 | $obj->longitude = $objSplit[1]; |
|
146 | } |
||
147 | |||
148 | 2 | $coordinates = (object) ["latitude" => $obj->latitude]; |
|
149 | 2 | $coordinates->longitude = $obj->longitude; |
|
150 | |||
151 | |||
152 | 2 | $darkClass = new \Anax\darkSkyApi\DarkSky(); |
|
153 | 2 | array_push($array, $coordinates); |
|
154 | 2 | $res = $darkClass::wheatherActionGet($array, $darkSkyKey); |
|
155 | |||
156 | |||
157 | |||
158 | |||
159 | |||
160 | |||
161 | 2 | $dates = $darkClass::wheatherSevenActionGet(30, $time); |
|
162 | 2 | $resThirtyDaysRequest = $darkClass::wheatherThirtyActionGet($array, $dates, $darkSkyKey); |
|
163 | // try { |
||
164 | // if (array_key_exists("code",$res)) { |
||
165 | // throw new \Exception("must be ip or coordinates"); |
||
166 | // } |
||
167 | // |
||
168 | // } catch (\Exception $e) { |
||
169 | // return $res; |
||
170 | // } |
||
171 | 2 | array_push($resArray, json_decode($res[0], JSON_PRETTY_PRINT)); |
|
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
172 | 2 | array_push($resArray, $resThirtyDaysRequest); |
|
173 | |||
174 | 2 | $response = json_encode($resArray, JSON_PRETTY_PRINT); |
|
175 | 2 | return $response; |
|
176 | } |
||
177 | } |
||
178 |