1 | <?php |
||
2 | |||
3 | namespace Anax\Weather; |
||
4 | |||
5 | use Anax\Commons\ContainerInjectableInterface; |
||
6 | use Anax\Commons\ContainerInjectableTrait; |
||
7 | use Anax\Ip2\IpStack; |
||
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 $app if implementing the interface |
||
16 | * AppInjectableInterface, 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 | |||
23 | class WeatherControllerApi implements ContainerInjectableInterface |
||
24 | { |
||
25 | use ContainerInjectableTrait; |
||
26 | |||
27 | // /** |
||
28 | // * This is the index method action, it handles: |
||
29 | // * ANY METHOD mountpoint |
||
30 | // * ANY METHOD mountpoint/ |
||
31 | // * ANY METHOD mountpoint/index |
||
32 | // * |
||
33 | // * @return string |
||
34 | // */ |
||
35 | // public function initAction() : object |
||
36 | // { |
||
37 | // // init session for game start |
||
38 | |||
39 | // $this->app->session->set("game", new DiceGame()); |
||
40 | |||
41 | // return $this->app->response->redirect("diceC/play"); |
||
42 | // } |
||
43 | |||
44 | // /** |
||
45 | // * This is the index method action, it handles: |
||
46 | // * ANY METHOD mountpoint |
||
47 | // * ANY METHOD mountpoint/ |
||
48 | // * ANY METHOD mountpoint/index |
||
49 | // * |
||
50 | // * @return string |
||
51 | // */ |
||
52 | 1 | public function indexActionGet(): object |
|
53 | { |
||
54 | 1 | $title = "Weather API"; |
|
55 | 1 | $page = $this->di->get("page"); |
|
56 | 1 | $url = "{$this->di->request->getBaseUrl()}/weather-api"; |
|
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
57 | 1 | $escapedUrl = htmlspecialchars($url, ENT_QUOTES, 'UTF-8'); |
|
58 | |||
59 | 1 | $data["url"] = $escapedUrl ?? null; |
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
60 | |||
61 | 1 | $page->add('weather/api-index', $data); |
|
62 | 1 | return $page->render([ |
|
63 | 1 | "title" => $title, |
|
64 | ]); |
||
65 | } |
||
66 | 1 | public function searchCordActionPost(): array |
|
67 | { |
||
68 | 1 | $request = $this->di->request; |
|
0 ignored issues
–
show
|
|||
69 | 1 | $wcL = $this->di->weather; |
|
0 ignored issues
–
show
|
|||
70 | 1 | $lat = $request->getPost("lat"); |
|
71 | 1 | $long = $request->getPost("long"); |
|
72 | 1 | $weather = $wcL->getWeather($lat, $long); |
|
73 | |||
74 | 1 | return [$weather]; |
|
75 | } |
||
76 | |||
77 | /** |
||
78 | * |
||
79 | * |
||
80 | * |
||
81 | * |
||
82 | * |
||
83 | * @return object |
||
84 | */ |
||
85 | 1 | public function searchIpActionPost(): array |
|
86 | { |
||
87 | 1 | $ipStack = new IpStack(); |
|
88 | 1 | $request = $this->di->request; |
|
0 ignored issues
–
show
|
|||
89 | 1 | $ipAd = $request->getPost("ip"); |
|
90 | 1 | $ipA = $ipStack->getInfo($ipAd); |
|
91 | 1 | $lat = $ipA["lat"]; |
|
92 | 1 | $long = $ipA["long"]; |
|
93 | 1 | $wcL = $this->di->weather; |
|
0 ignored issues
–
show
|
|||
94 | 1 | $weather = $wcL->getWeather($lat, $long); |
|
95 | |||
96 | 1 | return [$weather]; |
|
0 ignored issues
–
show
|
|||
97 | } |
||
98 | } |
||
99 |