1 | <?php |
||
23 | class FileHandler |
||
24 | { |
||
25 | const READ_MODE = 1; |
||
26 | const WRITE_MODE = 2; |
||
27 | |||
28 | protected $position = 0; |
||
29 | |||
30 | protected $mode = 0; |
||
31 | |||
32 | /** |
||
33 | * @var File |
||
34 | */ |
||
35 | protected $file; |
||
36 | |||
37 | /** |
||
38 | * Sets file in context. |
||
39 | * |
||
40 | * @param File $file |
||
41 | */ |
||
42 | public function setFile(File $file) |
||
46 | |||
47 | /** |
||
48 | * Returns file in context. |
||
49 | * |
||
50 | * @return File |
||
51 | */ |
||
52 | public function getFile() { |
||
55 | |||
56 | /** |
||
57 | * Writes data to file. Will return the number of bytes written. Will advance pointer by number of bytes written. |
||
58 | * |
||
59 | * @param string $data |
||
60 | * |
||
61 | * @return int |
||
62 | */ |
||
63 | public function write($data) |
||
76 | |||
77 | /** |
||
78 | * Will read and return $bytes bytes from file. Will advance pointer by $bytes bytes. |
||
79 | * |
||
80 | * @param int $bytes |
||
81 | * |
||
82 | * @return string |
||
83 | */ |
||
84 | public function read($bytes) |
||
99 | |||
100 | /** |
||
101 | * Returns current pointer position. |
||
102 | * |
||
103 | * @param integer|null $position |
||
104 | * |
||
105 | * @return int |
||
106 | */ |
||
107 | public function position($position = null) |
||
111 | |||
112 | /** |
||
113 | * Moves pointer to the end of file (for append modes). |
||
114 | * |
||
115 | * @return int |
||
116 | */ |
||
117 | public function seekToEnd() |
||
121 | |||
122 | /** |
||
123 | * Offsets position by $offset |
||
124 | * |
||
125 | * @param int $offset |
||
126 | */ |
||
127 | public function offsetPosition($offset) |
||
131 | |||
132 | /** |
||
133 | * Tells whether pointer is at the end of file. |
||
134 | * |
||
135 | * @return bool |
||
136 | */ |
||
137 | public function atEof() |
||
141 | |||
142 | /** |
||
143 | * Removed all data from file and sets pointer to 0 |
||
144 | * |
||
145 | * @param int $newSize |
||
146 | * |
||
147 | * @return void |
||
148 | */ |
||
149 | public function truncate($newSize = 0) |
||
160 | |||
161 | /** |
||
162 | * Sets handler to read only |
||
163 | */ |
||
164 | public function setReadOnlyMode() |
||
168 | |||
169 | /** |
||
170 | * Sets handler into read/write mode |
||
171 | */ |
||
172 | public function setReadWriteMode() |
||
176 | |||
177 | public function setWriteOnlyMode() |
||
181 | |||
182 | /** |
||
183 | * Checks if pointer allows writing |
||
184 | * |
||
185 | * @return bool |
||
186 | */ |
||
187 | public function isOpenedForWriting() |
||
191 | |||
192 | /** |
||
193 | * Checks if pointer allows reading |
||
194 | * |
||
195 | * @return bool |
||
196 | */ |
||
197 | public function isOpenedForReading() |
||
201 | |||
202 | /** |
||
203 | * @param $resource |
||
204 | */ |
||
205 | public function lock($resource, $operation) |
||
209 | } |
||
210 |