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