|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Anax\Models; |
|
4
|
|
|
|
|
5
|
|
|
use Anax\Config\access; |
|
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class Weather |
|
9
|
|
|
*/ |
|
10
|
|
|
class Weather |
|
11
|
|
|
{ |
|
12
|
|
|
private $keys; |
|
13
|
|
|
|
|
14
|
|
|
public function setKeys($config) |
|
15
|
|
|
{ |
|
16
|
|
|
$this->keys = $config; |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Curl from url |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
public function curl($url) |
|
24
|
|
|
{ |
|
25
|
|
|
$curl = curl_init($url); |
|
26
|
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
|
|
|
|
|
|
27
|
|
|
$data = curl_exec($curl); |
|
|
|
|
|
|
28
|
|
|
curl_close($curl); |
|
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
return $data; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function multiCurl($urls) |
|
34
|
|
|
{ |
|
35
|
|
|
$opts = [ |
|
36
|
|
|
CURLOPT_RETURNTRANSFER => true, |
|
37
|
|
|
]; |
|
38
|
|
|
$cAll = []; |
|
39
|
|
|
|
|
40
|
|
|
$mh = curl_multi_init(); |
|
41
|
|
|
|
|
42
|
|
|
foreach ($urls as $url) { |
|
43
|
|
|
$ch = curl_init("$url"); |
|
44
|
|
|
curl_setopt_array($ch, $opts); |
|
|
|
|
|
|
45
|
|
|
curl_multi_add_handle($mh, $ch); |
|
|
|
|
|
|
46
|
|
|
$cAll[] = $ch; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$running = null; |
|
50
|
|
|
do { |
|
51
|
|
|
curl_multi_exec($mh, $running); |
|
52
|
|
|
} while ($running); |
|
53
|
|
|
|
|
54
|
|
|
foreach ($cAll as $ch) { |
|
55
|
|
|
curl_multi_remove_handle($mh, $ch); |
|
56
|
|
|
} |
|
57
|
|
|
curl_multi_close($mh); |
|
58
|
|
|
|
|
59
|
|
|
$response = []; |
|
60
|
|
|
foreach ($cAll as $ch) { |
|
61
|
|
|
$data = curl_multi_getcontent($ch); |
|
62
|
|
|
array_push($response, $data); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
return $response; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function getWeather($lat, $long, $geo) |
|
69
|
|
|
{ |
|
70
|
|
|
$urls; |
|
|
|
|
|
|
71
|
|
|
$accessToken = $this->keys["darkSky"]; |
|
72
|
|
|
|
|
73
|
|
|
if ($geo == "future") { |
|
74
|
|
|
$url = 'https://api.darksky.net/forecast/' . $accessToken . "/" . $lat . "," . $long . "?units=si"; |
|
75
|
|
|
$data = json_decode($this->curl($url)); |
|
76
|
|
|
} else { |
|
77
|
|
|
$days = 5; |
|
78
|
|
|
for ($i = 0; $i < $days; $i++) { |
|
79
|
|
|
$timestamp = "-" . $i . " day"; |
|
80
|
|
|
$time = strtotime($timestamp, time()); |
|
81
|
|
|
$urls[$i] = 'https://api.darksky.net/forecast/' . $accessToken . "/" . $lat . "," . $long . "," . $time . "?units=si"; |
|
82
|
|
|
} |
|
83
|
|
|
$curlResponse = $this->multiCurl($urls); |
|
|
|
|
|
|
84
|
|
|
for ($i = 0; $i < $days; $i++) { |
|
85
|
|
|
$data[$i] = json_decode($curlResponse[$i]); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
$mapUrl = "https://nominatim.openstreetmap.org/reverse?lat=$lat&lon=$long&[email protected]&format=json"; |
|
89
|
|
|
$mapData = json_decode($this->curl($mapUrl)); |
|
90
|
|
|
$weatherData = [ |
|
91
|
|
|
"data" => $data, |
|
|
|
|
|
|
92
|
|
|
"mapData" => $mapData |
|
93
|
|
|
]; |
|
94
|
|
|
return $weatherData; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
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