1 | <?php |
||
10 | class FileReader extends Reader |
||
11 | { |
||
12 | /** |
||
13 | * The file name. |
||
14 | * |
||
15 | * @var string |
||
16 | */ |
||
17 | protected $filename; |
||
18 | |||
19 | /** |
||
20 | * The file size. |
||
21 | * |
||
22 | * @var int |
||
23 | */ |
||
24 | protected $length; |
||
25 | |||
26 | /** |
||
27 | * The open file descriptor. |
||
28 | * |
||
29 | * @var resource |
||
30 | */ |
||
31 | protected $fd; |
||
32 | |||
33 | /** |
||
34 | * Initializes the instance. |
||
35 | * |
||
36 | * @param string $filename The file name to be read. |
||
37 | * |
||
38 | * @throws Exception Throws an Exception in case of errors. |
||
39 | */ |
||
40 | 4 | public function __construct($filename) |
|
59 | |||
60 | /** |
||
61 | * Destruct the instance. |
||
62 | */ |
||
63 | public function __destruct() |
||
64 | { |
||
65 | if (isset($this->fd)) { |
||
66 | @fclose($this->fd); |
||
|
|||
67 | $this->fd = null; |
||
68 | } |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * {@inheritdoc} |
||
73 | * |
||
74 | * @see Reader::setPosition() |
||
75 | */ |
||
76 | 29 | public function setPosition($position) |
|
82 | |||
83 | /** |
||
84 | * {@inheritdoc} |
||
85 | * |
||
86 | * @see Reader::getPosition() |
||
87 | */ |
||
88 | 4 | public function getPosition() |
|
97 | |||
98 | /** |
||
99 | * {@inheritdoc} |
||
100 | * |
||
101 | * @see Reader::getLength() |
||
102 | */ |
||
103 | 4 | public function getLength() |
|
107 | |||
108 | /** |
||
109 | * {@inheritdoc} |
||
110 | * |
||
111 | * @see Reader::readString() |
||
112 | */ |
||
113 | 29 | public function readString($length) |
|
126 | } |
||
127 |
If you suppress an error, we recommend checking for the error condition explicitly: