|
1
|
|
|
<?php |
|
2
|
|
|
namespace Oliver\Controller; |
|
3
|
|
|
|
|
4
|
|
|
use Anax\Commons\ContainerInjectableInterface; |
|
5
|
|
|
use Anax\Commons\ContainerInjectableTrait; |
|
6
|
|
|
use Oliver\Weather\Weather; |
|
7
|
|
|
|
|
8
|
|
|
use Oliver\Weather\Exception\BadFormatException; |
|
9
|
|
|
use Oliver\DarkSky\Exception\InvalidLocationException; |
|
10
|
|
|
use Oliver\Weather\Exception\NoHistoryException; |
|
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* |
|
14
|
|
|
*/ |
|
15
|
|
|
class WeatherJsonController implements ContainerInjectableInterface |
|
16
|
|
|
{ |
|
17
|
|
|
use ContainerInjectableTrait; |
|
18
|
|
|
|
|
19
|
|
|
private $title = "Väder (REST API)"; |
|
20
|
|
|
private $description = "<p>Sök efter en plats och få en väderprognos för den kommande veckan eller historik 30 dagar tillbaka i JSON-format."; |
|
21
|
|
|
|
|
22
|
|
|
|
|
23
|
1 |
|
public function indexActionGet() : object |
|
24
|
|
|
{ |
|
25
|
1 |
|
$page = $this->di->get("page"); |
|
26
|
1 |
|
$page->add("weather/index", [ |
|
27
|
1 |
|
"title" => $this->title, |
|
28
|
1 |
|
"description" => $this->description |
|
29
|
|
|
]); |
|
30
|
1 |
|
return $page->render([ |
|
31
|
1 |
|
"title" => $this->title |
|
32
|
|
|
]); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
1 |
|
public function indexActionPost() : string |
|
36
|
|
|
{ |
|
37
|
1 |
|
$request = $this->di->get("request"); |
|
38
|
1 |
|
$response = $this->di->get("response"); |
|
39
|
1 |
|
$coordinates = $request->getPost("coordinates"); |
|
40
|
1 |
|
$option = $request->getPost("option"); |
|
41
|
|
|
|
|
42
|
1 |
|
$route = "weather/api/$option/{$coordinates}"; |
|
43
|
1 |
|
$response->redirect($route); |
|
44
|
1 |
|
return $route; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
2 |
|
public function historyActionGet($coordinates) : array |
|
48
|
|
|
{ |
|
49
|
|
|
try { |
|
50
|
2 |
|
$darkSky = $this->di->get("darkSky"); |
|
51
|
2 |
|
$weather = new Weather($darkSky); |
|
52
|
2 |
|
$result = $weather->fetchWeather($coordinates, "history"); |
|
53
|
1 |
|
return [$result]; |
|
54
|
1 |
|
} catch (BadFormatException | InvalidLocationException | NoHistoryException $e) { |
|
55
|
1 |
|
return [["error" => $e->getMessage()]]; |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
2 |
|
public function forecastActionGet($coordinates) : array |
|
60
|
|
|
{ |
|
61
|
|
|
try { |
|
62
|
2 |
|
$darkSky = $this->di->get("darkSky"); |
|
63
|
2 |
|
$weather = new Weather($darkSky); |
|
64
|
2 |
|
$result = $weather->fetchWeather($coordinates, "forecast"); |
|
65
|
1 |
|
return [$result]; |
|
66
|
1 |
|
} catch (BadFormatException | InvalidLocationException $e) { |
|
67
|
1 |
|
return [["error" => $e->getMessage()]]; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths