|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Eluceo\iCal\Property\Event; |
|
4
|
|
|
|
|
5
|
|
|
use Eluceo\iCal\Property; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* GEO property |
|
9
|
|
|
* |
|
10
|
|
|
* @see https://tools.ietf.org/html/rfc5545#section-3.8.1.6 |
|
11
|
|
|
*/ |
|
12
|
|
|
class Geo extends Property |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var float |
|
16
|
|
|
*/ |
|
17
|
|
|
private $latitude; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var float |
|
21
|
|
|
*/ |
|
22
|
|
|
private $longitude; |
|
23
|
|
|
|
|
24
|
1 |
|
public function __construct($latitude, $longitude) |
|
25
|
|
|
{ |
|
26
|
1 |
|
$this->latitude = $latitude; |
|
27
|
1 |
|
$this->longitude = $longitude; |
|
28
|
|
|
|
|
29
|
1 |
|
if ($this->latitude < -90 || $this->latitude > 90) { |
|
30
|
|
|
throw new \InvalidArgumentException( |
|
31
|
|
|
"The geographical latitude must be a value between -90 and 90 degrees. '{$this->latitude}' was given." |
|
32
|
|
|
); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
1 |
|
if ($this->longitude < -180 || $this->longitude > 180) { |
|
36
|
|
|
throw new \InvalidArgumentException( |
|
37
|
|
|
"The geographical longitude must be a value between -180 and 180 degrees. '{$this->longitude}' was given." |
|
38
|
|
|
); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
1 |
|
parent::__construct('GEO', new Property\RawStringValue($this->getGeoLocationAsString())); |
|
42
|
1 |
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @deprecated This method is used to allow backwards compatibility for Event::setLocation |
|
46
|
|
|
* |
|
47
|
|
|
* @param string $geoLocationString |
|
48
|
|
|
* @return Geo |
|
49
|
|
|
*/ |
|
50
|
|
|
public static function fromString($geoLocationString) |
|
51
|
|
|
{ |
|
52
|
|
|
$geoLocationString = str_replace(',', ';', $geoLocationString); |
|
53
|
|
|
$parts = explode(';', $geoLocationString); |
|
54
|
|
|
|
|
55
|
|
|
return new static((float) $parts[0], (float) $parts[1]); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Returns the coordinates as a string. |
|
60
|
|
|
* |
|
61
|
|
|
* @example 37.386013;-122.082932 |
|
62
|
|
|
* |
|
63
|
|
|
* @param string $separator |
|
64
|
|
|
* @return string |
|
65
|
|
|
*/ |
|
66
|
1 |
|
public function getGeoLocationAsString($separator = ';') |
|
67
|
|
|
{ |
|
68
|
1 |
|
return number_format($this->latitude, 6) . $separator . number_format($this->longitude, 6); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @return float |
|
73
|
|
|
*/ |
|
74
|
|
|
public function getLatitude() |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->latitude; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @return float |
|
81
|
|
|
*/ |
|
82
|
|
|
public function getLongitude() |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->longitude; |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|