1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace KW\Models; |
4
|
|
|
|
5
|
|
|
class DarkSkyUmbrella |
6
|
|
|
{ |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @var array $wobj array med info om ett ipnummer, koordinater samt ev väderresultat |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
public $wobj = array( |
13
|
|
|
"ip"=>"", |
14
|
|
|
"valid"=>false, |
15
|
|
|
"type" => "", |
16
|
|
|
"latitude" => 0, |
17
|
|
|
"longitude" => 0, |
18
|
|
|
"city"=>"", |
19
|
|
|
"country"=>"", |
20
|
|
|
"weatherresult"=>[] |
21
|
|
|
); |
22
|
|
|
|
23
|
7 |
|
public function __construct($di) |
24
|
|
|
{ |
25
|
7 |
|
$this->di = $di; |
|
|
|
|
26
|
7 |
|
$this->ipValidate = new IpValidate($this->di); |
|
|
|
|
27
|
7 |
|
$this->ipDomainname = new IpDomainname($this->di); |
|
|
|
|
28
|
7 |
|
$this->ipCheckCoordinates = new IpCheckCoordinates($this->di); |
|
|
|
|
29
|
7 |
|
$this->osmr = new OpenStreetMapReverse($this->di); |
|
|
|
|
30
|
7 |
|
$this->darkSky = new DarkSky($this->di); |
|
|
|
|
31
|
7 |
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Get url-type according to type and position to send to Dark Sky |
35
|
|
|
* |
36
|
|
|
* @return array |
37
|
|
|
*/ |
38
|
7 |
|
public function input($longitude, $latitude, $type, $ipn) |
39
|
|
|
{ |
40
|
7 |
|
if (abs($longitude) >= 180 or abs($latitude) >= 90) { |
41
|
1 |
|
$this->wobj["error"] = "Du angav in felaktiga kooridnater!"; |
42
|
1 |
|
return $this->wobj; |
43
|
|
|
}; |
44
|
6 |
|
$this->wobj["type"] = $type; |
45
|
6 |
|
if ($ipn != "") { |
46
|
3 |
|
$this->wobj["valid"] = $this->ipValidate->validate($ipn); |
47
|
|
|
|
48
|
3 |
|
if ($this->wobj["valid"]) { |
49
|
2 |
|
list($this->wobj["latitude"], $this->wobj["longitude"], |
50
|
2 |
|
$this->wobj["country"], $this->wobj["city"]) |
51
|
2 |
|
= $this->ipCheckCoordinates->ipCheckCoordinates($ipn); |
52
|
2 |
|
if ($this->wobj["country"] == "" and $this->wobj["latitude"] == 0 and $this->wobj["latitude"] == 0) { |
53
|
1 |
|
$this->wobj["error"] = "Ip-adressen matchar ingen geografisk plats. Denna vädertjänst redovisar inga cyberväder"; |
54
|
2 |
|
return $this->wobj; |
55
|
|
|
} |
56
|
|
|
} else { |
57
|
1 |
|
$this->wobj["error"] = "Du angav en felaktig ip-adress!"; |
58
|
2 |
|
return $this->wobj; |
59
|
|
|
} |
60
|
|
|
} else { |
61
|
3 |
|
if ($longitude == "" or $latitude == "") { |
62
|
1 |
|
$this->wobj["error"] = "Du måste ange korrekt longitud och latitud om ipnummer ej anges!"; |
63
|
1 |
|
return $this->wobj; |
64
|
|
|
} |
65
|
2 |
|
$this->wobj["latitude"]= $latitude; |
66
|
2 |
|
$this->wobj["longitude"] = $longitude; |
67
|
2 |
|
list($this->wobj["country"], $this->wobj["city"]) = $this->osmr->osmCheckCoordinates($longitude, $latitude); |
68
|
|
|
} |
69
|
3 |
|
$this->wobj["weatherresult"] = $this->darkSky->weather($this->wobj["longitude"], $this->wobj["latitude"], $type); |
70
|
|
|
|
71
|
3 |
|
return $this->wobj; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|