1 | <?php |
||
17 | abstract class AbstractFileProvider implements ProviderInterface |
||
18 | { |
||
19 | use GuessInvalidValuesTrait; |
||
20 | |||
21 | /** @var int */ |
||
22 | const MAX_LATITUDE = 90; |
||
23 | |||
24 | /** @var int */ |
||
25 | const MAX_LONGITUDE = 180; |
||
26 | |||
27 | /** @var string */ |
||
28 | protected $PathToFiles; |
||
29 | |||
30 | /** @var resource */ |
||
31 | protected $FileResource; |
||
32 | |||
33 | /** @var string|bool */ |
||
34 | protected $CurrentFilename = false; |
||
35 | |||
36 | /** @var InterpolationInterface|null */ |
||
37 | protected $Interpolation; |
||
38 | |||
39 | /** @var ResourceReaderInterface */ |
||
40 | protected $ResourceReader; |
||
41 | |||
42 | /** |
||
43 | * @param string $pathToFiles |
||
44 | * @param InterpolationInterface|null $interpolation |
||
45 | */ |
||
46 | 19 | public function __construct($pathToFiles, InterpolationInterface $interpolation = null) |
|
54 | |||
55 | 19 | private function addSlashToPathIfNotThere() |
|
61 | |||
62 | /** |
||
63 | * @param InterpolationInterface $interpolation |
||
64 | */ |
||
65 | 13 | public function setInterpolation(InterpolationInterface $interpolation) |
|
69 | |||
70 | 1 | public function removeInterpolation() |
|
74 | |||
75 | /** |
||
76 | * @param array $latitudeLongitudes array(array($lat, $lng), ...) |
||
77 | * @return bool |
||
78 | * @throws InvalidArgumentException |
||
79 | */ |
||
80 | 8 | public function hasDataFor(array $latitudeLongitudes) |
|
98 | |||
99 | /** |
||
100 | * @param float $latitude |
||
101 | * @param float $longitude |
||
102 | * @return bool |
||
103 | */ |
||
104 | 14 | protected function locationIsInBounds($latitude, $longitude) |
|
111 | |||
112 | /** |
||
113 | * @return bool |
||
114 | */ |
||
115 | 7 | public function usesInterpolation() |
|
119 | |||
120 | /** |
||
121 | * @param float[] $latitudes |
||
122 | * @param float[] $longitudes |
||
123 | * @return array elevations [m] can be false if nothing retrieved |
||
124 | * @throws InvalidArgumentException; |
||
125 | */ |
||
126 | 6 | public function getElevations(array $latitudes, array $longitudes) |
|
141 | |||
142 | /** |
||
143 | * Get elevation for specified location. |
||
144 | * |
||
145 | * Availability of data must be checked in advance via hasDataFor($locations). |
||
146 | * Only 'invalid' locations such as (0.0, 0.0) won't throw an exception but return false. |
||
147 | * |
||
148 | * @param float $latitude |
||
149 | * @param float $longitude |
||
150 | * @return int|bool elevation [m] can be false if nothing retrieved |
||
151 | * @throws InvalidArgumentException; |
||
152 | */ |
||
153 | 10 | public function getElevation($latitude, $longitude) |
|
177 | |||
178 | /** |
||
179 | * @param float $latitude |
||
180 | * @param float $longitude |
||
181 | * @return int|bool can be false if nothing retrieved |
||
182 | */ |
||
183 | 7 | protected function getElevationFromResource($latitude, $longitude) |
|
193 | |||
194 | /** |
||
195 | * @param float $exactRowValue |
||
196 | * @param float $exactColValue |
||
197 | * @return int|bool can be false if nothing retrieved |
||
198 | */ |
||
199 | 6 | protected function getInterpolatedElevationFor($exactRowValue, $exactColValue) |
|
219 | |||
220 | /** |
||
221 | * @param float $latitude |
||
222 | * @param float $longitude |
||
223 | * @return string |
||
224 | */ |
||
225 | abstract protected function getFilenameFor($latitude, $longitude); |
||
226 | |||
227 | abstract protected function initResourceReader(); |
||
228 | |||
229 | /** |
||
230 | * @param string $filename |
||
231 | */ |
||
232 | abstract protected function openResource($filename); |
||
233 | |||
234 | /** |
||
235 | * @param int $row |
||
236 | * @param int $col |
||
237 | * @return int|bool elevation [m] can be false if nothing retrieved |
||
238 | */ |
||
239 | abstract protected function getElevationFor($row, $col); |
||
240 | |||
241 | /** |
||
242 | * @param float $latitude |
||
243 | * @param float $longitude |
||
244 | * @return array array(row, col) |
||
245 | */ |
||
246 | abstract protected function getExactRowAndColFor($latitude, $longitude); |
||
247 | } |
||
248 |