|
<?php |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Eluceo\iCal\Property\Event; |
|
|
|
use Eluceo\iCal\Property; |
|
|
|
|
|
|
|
|
|
|
|
|
|
class Geo extends Property |
|
{ |
|
|
|
|
|
|
|
private $latitude; |
|
|
|
|
|
|
|
|
|
private $longitude; |
|
|
|
public function __construct(float $latitude, float $longitude) |
|
{ |
|
$this->latitude = $latitude; |
|
$this->longitude = $longitude; |
|
|
|
if ($this->latitude < -90 || $this->latitude > 90) { |
|
throw new \InvalidArgumentException("The geographical latitude must be a value between -90 and 90 degrees. '{$this->latitude}' was given."); |
|
} |
|
|
|
if ($this->longitude < -180 || $this->longitude > 180) { |
|
throw new \InvalidArgumentException("The geographical longitude must be a value between -180 and 180 degrees. '{$this->longitude}' was given."); |
|
} |
|
|
|
parent::__construct('GEO', new Property\RawStringValue($this->getGeoLocationAsString())); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
public static function fromString(string $geoLocationString): self |
|
{ |
|
$geoLocationString = str_replace(',', ';', $geoLocationString); |
|
$geoLocationString = str_replace('GEO:', '', $geoLocationString); |
|
$parts = explode(';', $geoLocationString); |
|
|
|
return new static((float) $parts[0], (float) $parts[1]); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getGeoLocationAsString(string $separator = ';'): string |
|
{ |
|
return number_format($this->latitude, 6) . $separator . number_format($this->longitude, 6); |
|
} |
|
|
|
public function getLatitude(): float |
|
{ |
|
return $this->latitude; |
|
} |
|
|
|
public function getLongitude(): float |
|
{ |
|
return $this->longitude; |
|
} |
|
} |
|
|