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 | public function getValue(): self { |
||
93 | return $this; |
||
94 | } |
||
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 | * @deprecated since 2.0.1. When using this static constructor for DataValues of unknown |
||
118 | * types, please use DataValueDeserializer from the data-values/serialization package instead. |
||
119 | * |
||
120 | * @throws InvalidArgumentException |
||
121 | */ |
||
122 | 7 | public static function newFromArray( $data ): self { |
|
123 | 7 | if ( !is_array( $data ) ) { |
|
124 | throw new IllegalValueException( 'array expected' ); |
||
125 | } |
||
126 | |||
127 | 7 | if ( !array_key_exists( 'latitude', $data ) ) { |
|
128 | throw new IllegalValueException( 'latitude field required' ); |
||
129 | } |
||
130 | |||
131 | 7 | if ( !array_key_exists( 'longitude', $data ) ) { |
|
132 | throw new IllegalValueException( 'longitude field required' ); |
||
133 | } |
||
134 | |||
135 | 7 | return new static( $data['latitude'], $data['longitude'] ); |
|
136 | } |
||
137 | |||
138 | 1 | public function toArray(): array { |
|
144 | |||
145 | /** |
||
146 | * @see \Hashable::getHash |
||
147 | */ |
||
148 | 1 | public function getHash(): string { |
|
151 | |||
152 | /** |
||
153 | * @see \Comparable::equals |
||
154 | * |
||
155 | * @param mixed $target |
||
156 | * |
||
157 | * @return bool |
||
158 | */ |
||
159 | 15 | public function equals( $target ): bool { |
|
167 | |||
168 | 9 | public function getCopy(): self { |
|
171 | |||
172 | } |
||
173 |