1 | <?php |
||
22 | class LatLongValue implements DataValue { |
||
23 | |||
24 | private $latitude; |
||
25 | private $longitude; |
||
26 | |||
27 | /** |
||
28 | * @param float|int $latitude Latitude in degrees within the range [-360, 360] |
||
29 | * @param float|int $longitude Longitude in degrees within the range [-360, 360] |
||
30 | * |
||
31 | * @throws InvalidArgumentException |
||
32 | */ |
||
33 | 37 | public function __construct( float $latitude, float $longitude ) { |
|
40 | |||
41 | 37 | private function assertIsLatitude( float $latitude ) { |
|
46 | |||
47 | 33 | private function assertIsLongitude( float $longitude ) { |
|
52 | |||
53 | /** |
||
54 | * @see Serializable::serialize |
||
55 | * |
||
56 | * @return string |
||
57 | */ |
||
58 | 17 | public function serialize(): string { |
|
66 | |||
67 | /** |
||
68 | * @see Serializable::unserialize |
||
69 | * |
||
70 | * @param string $value |
||
71 | * |
||
72 | * @throws InvalidArgumentException |
||
73 | */ |
||
74 | 7 | public function unserialize( $value ) { |
|
83 | |||
84 | 2 | public static function getType(): string { |
|
87 | |||
88 | 7 | public function getSortKey(): float { |
|
89 | 7 | return $this->latitude; |
|
90 | } |
||
91 | |||
92 | 7 | public function getValue(): self { |
|
95 | |||
96 | 8 | public function getLatitude(): float { |
|
99 | |||
100 | 1 | public function getLongitude(): float { |
|
103 | |||
104 | /** |
||
105 | * @return float[] |
||
106 | */ |
||
107 | 8 | public function getArrayValue(): array { |
|
113 | |||
114 | /** |
||
115 | * Constructs a new instance from the provided array. Round-trips with @see getArrayValue. |
||
116 | * |
||
117 | * @throws InvalidArgumentException |
||
118 | */ |
||
119 | 7 | public static function newFromArray( $data ): self { |
|
120 | 7 | if ( !is_array( $data ) ) { |
|
121 | throw new IllegalValueException( 'array expected' ); |
||
122 | } |
||
123 | |||
124 | 7 | if ( !array_key_exists( 'latitude', $data ) ) { |
|
125 | throw new IllegalValueException( 'latitude field required' ); |
||
126 | } |
||
127 | |||
128 | 7 | if ( !array_key_exists( 'longitude', $data ) ) { |
|
129 | throw new IllegalValueException( 'longitude field required' ); |
||
130 | } |
||
131 | |||
132 | 7 | return new static( $data['latitude'], $data['longitude'] ); |
|
133 | } |
||
134 | |||
135 | 1 | public function toArray(): array { |
|
141 | |||
142 | /** |
||
143 | * @see \Hashable::getHash |
||
144 | */ |
||
145 | 1 | public function getHash(): string { |
|
148 | |||
149 | /** |
||
150 | * @see \Comparable::equals |
||
151 | * |
||
152 | * @param mixed $target |
||
153 | * |
||
154 | * @return bool |
||
155 | */ |
||
156 | 15 | public function equals( $target ): bool { |
|
164 | |||
165 | 9 | public function getCopy(): self { |
|
168 | |||
169 | } |
||
170 |