| 1 | <?php |
||
| 16 | abstract class AbstractResourceReader implements ResourceReaderInterface |
||
| 17 | { |
||
| 18 | /** @var resource|bool */ |
||
| 19 | protected $FileResource = false; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @param resource|bool $resource |
||
| 23 | */ |
||
| 24 | public function __construct($resource = false) |
||
| 25 | { |
||
| 26 | if (false !== $resource) { |
||
| 27 | $this->setResource($resource); |
||
| 28 | } |
||
| 29 | } |
||
| 30 | |||
| 31 | public function __destruct() |
||
| 32 | { |
||
| 33 | $this->closeResource(); |
||
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @param resource $resource |
||
| 38 | * @throws RuntimeException |
||
| 39 | */ |
||
| 40 | public function setResource($resource) |
||
| 41 | { |
||
| 42 | $this->closeResource(); |
||
| 43 | |||
| 44 | $this->FileResource = $resource; |
||
| 45 | |||
| 46 | if (false === $this->FileResource) { |
||
| 47 | throw new RuntimeException('Provided resource is invalid.'); |
||
| 48 | } |
||
| 49 | } |
||
| 50 | |||
| 51 | protected function closeResource() |
||
| 52 | { |
||
| 53 | if (is_resource($this->FileResource)) { |
||
| 54 | fclose($this->FileResource); |
||
| 55 | } |
||
| 56 | } |
||
| 57 | |||
| 58 | abstract public function readHeader(); |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @param int $row |
||
| 62 | * @param int $col |
||
| 63 | * @return int|bool elevation [m] can be false if nothing retrieved or value is unknown |
||
| 64 | */ |
||
| 65 | abstract public function getElevationFor($row, $col); |
||
| 66 | } |
||
| 67 |