Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | n/a |
0 / 0 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
|||
| AbstractReader | n/a |
0 / 0 |
n/a |
0 / 0 |
11 | n/a |
0 / 0 |
|||
| isReadDataOnly | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| setReadDataOnly | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| hasImageLoading | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| setImageLoading | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| openFile | n/a |
0 / 0 |
n/a |
0 / 0 |
4 | |||||
| canRead | n/a |
0 / 0 |
n/a |
0 / 0 |
3 | |||||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This file is part of PHPWord - A pure PHP library for reading and writing |
| 5 | * word processing documents. |
| 6 | * |
| 7 | * PHPWord is free software distributed under the terms of the GNU Lesser |
| 8 | * General Public License version 3 as published by the Free Software Foundation. |
| 9 | * |
| 10 | * For the full copyright and license information, please read the LICENSE |
| 11 | * file that was distributed with this source code. For the full list of |
| 12 | * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. |
| 13 | * |
| 14 | * @see https://github.com/PHPOffice/PHPWord |
| 15 | * |
| 16 | * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
| 17 | */ |
| 18 | |
| 19 | namespace PhpOffice\PhpWord\Reader; |
| 20 | |
| 21 | use PhpOffice\PhpWord\Exception\Exception; |
| 22 | |
| 23 | /** |
| 24 | * Reader abstract class. |
| 25 | * |
| 26 | * @since 0.8.0 |
| 27 | * |
| 28 | * @codeCoverageIgnore Abstract class |
| 29 | */ |
| 30 | abstract class AbstractReader implements ReaderInterface |
| 31 | { |
| 32 | /** |
| 33 | * Read data only? |
| 34 | * |
| 35 | * @var bool |
| 36 | */ |
| 37 | protected $readDataOnly = true; |
| 38 | |
| 39 | /** |
| 40 | * File pointer. |
| 41 | * |
| 42 | * @var bool|resource |
| 43 | */ |
| 44 | protected $fileHandle; |
| 45 | |
| 46 | /** |
| 47 | * Load images. |
| 48 | * |
| 49 | * @var bool |
| 50 | */ |
| 51 | protected $imageLoading = true; |
| 52 | |
| 53 | /** |
| 54 | * Read data only? |
| 55 | * |
| 56 | * @return bool |
| 57 | */ |
| 58 | public function isReadDataOnly() |
| 59 | { |
| 60 | // return $this->readDataOnly; |
| 61 | return true; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Set read data only. |
| 66 | * |
| 67 | * @param bool $value |
| 68 | * |
| 69 | * @return self |
| 70 | */ |
| 71 | public function setReadDataOnly($value = true) |
| 72 | { |
| 73 | $this->readDataOnly = $value; |
| 74 | |
| 75 | return $this; |
| 76 | } |
| 77 | |
| 78 | public function hasImageLoading(): bool |
| 79 | { |
| 80 | return $this->imageLoading; |
| 81 | } |
| 82 | |
| 83 | public function setImageLoading(bool $value): self |
| 84 | { |
| 85 | $this->imageLoading = $value; |
| 86 | |
| 87 | return $this; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Open file for reading. |
| 92 | * |
| 93 | * @param string $filename |
| 94 | * |
| 95 | * @return resource |
| 96 | */ |
| 97 | protected function openFile($filename) |
| 98 | { |
| 99 | // Check if file exists |
| 100 | if (!file_exists($filename) || !is_readable($filename)) { |
| 101 | throw new Exception("Could not open $filename for reading! File does not exist."); |
| 102 | } |
| 103 | |
| 104 | // Open file |
| 105 | $this->fileHandle = fopen($filename, 'rb'); |
| 106 | if ($this->fileHandle === false) { |
| 107 | throw new Exception("Could not open file $filename for reading."); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Can the current ReaderInterface read the file? |
| 113 | * |
| 114 | * @param string $filename |
| 115 | * |
| 116 | * @return bool |
| 117 | */ |
| 118 | public function canRead($filename) |
| 119 | { |
| 120 | // Check if file exists |
| 121 | try { |
| 122 | $this->openFile($filename); |
| 123 | } catch (Exception $e) { |
| 124 | return false; |
| 125 | } |
| 126 | if (is_resource($this->fileHandle)) { |
| 127 | fclose($this->fileHandle); |
| 128 | } |
| 129 | |
| 130 | return true; |
| 131 | } |
| 132 | } |