1 | <?php |
||
19 | class NativeShare extends AbstractShare { |
||
20 | /** |
||
21 | * @var IServer $server |
||
22 | */ |
||
23 | private $server; |
||
24 | |||
25 | /** |
||
26 | * @var string $name |
||
27 | */ |
||
28 | private $name; |
||
29 | |||
30 | /** |
||
31 | * @var NativeState $state |
||
32 | */ |
||
33 | private $state; |
||
34 | |||
35 | /** |
||
36 | * @param IServer $server |
||
37 | * @param string $name |
||
38 | */ |
||
39 | 256 | public function __construct($server, $name) { |
|
44 | |||
45 | /** |
||
46 | * @throws \Icewind\SMB\Exception\ConnectionException |
||
47 | * @throws \Icewind\SMB\Exception\AuthenticationException |
||
48 | * @throws \Icewind\SMB\Exception\InvalidHostException |
||
49 | */ |
||
50 | 256 | protected function getState() { |
|
59 | |||
60 | /** |
||
61 | * Get the name of the share |
||
62 | * |
||
63 | * @return string |
||
64 | */ |
||
65 | 1 | public function getName() { |
|
68 | |||
69 | 256 | private function buildUrl($path) { |
|
79 | |||
80 | /** |
||
81 | * List the content of a remote folder |
||
82 | * |
||
83 | * @param string $path |
||
84 | * @return \Icewind\SMB\IFileInfo[] |
||
85 | * |
||
86 | * @throws \Icewind\SMB\Exception\NotFoundException |
||
87 | * @throws \Icewind\SMB\Exception\InvalidTypeException |
||
88 | */ |
||
89 | 256 | public function dir($path) { |
|
90 | 256 | $files = []; |
|
91 | |||
92 | 256 | $dh = $this->getState()->opendir($this->buildUrl($path)); |
|
93 | 256 | while ($file = $this->getState()->readdir($dh)) { |
|
94 | 256 | $name = $file['name']; |
|
95 | 256 | if ($name !== '.' and $name !== '..') { |
|
96 | 103 | $fullPath = $path . '/' . $name; |
|
97 | 103 | $files [] = new NativeFileInfo($this, $fullPath, $name, function () use ($fullPath) { |
|
98 | 103 | return $this->getStat($fullPath); |
|
99 | 103 | }); |
|
100 | 103 | } |
|
101 | 256 | } |
|
102 | |||
103 | 256 | $this->getState()->closedir($dh); |
|
104 | 256 | return $files; |
|
105 | } |
||
106 | |||
107 | /** |
||
108 | * @param string $path |
||
109 | * @return \Icewind\SMB\IFileInfo |
||
110 | */ |
||
111 | 33 | public function stat($path) { |
|
114 | |||
115 | 115 | private function getStat($path) { |
|
118 | |||
119 | /** |
||
120 | * Create a folder on the share |
||
121 | * |
||
122 | * @param string $path |
||
123 | * @return bool |
||
124 | * |
||
125 | * @throws \Icewind\SMB\Exception\NotFoundException |
||
126 | * @throws \Icewind\SMB\Exception\AlreadyExistsException |
||
127 | */ |
||
128 | 256 | public function mkdir($path) { |
|
131 | |||
132 | /** |
||
133 | * Remove a folder on the share |
||
134 | * |
||
135 | * @param string $path |
||
136 | * @return bool |
||
137 | * |
||
138 | * @throws \Icewind\SMB\Exception\NotFoundException |
||
139 | * @throws \Icewind\SMB\Exception\InvalidTypeException |
||
140 | */ |
||
141 | 256 | public function rmdir($path) { |
|
144 | |||
145 | /** |
||
146 | * Delete a file on the share |
||
147 | * |
||
148 | * @param string $path |
||
149 | * @return bool |
||
150 | * |
||
151 | * @throws \Icewind\SMB\Exception\NotFoundException |
||
152 | * @throws \Icewind\SMB\Exception\InvalidTypeException |
||
153 | */ |
||
154 | 134 | public function del($path) { |
|
157 | |||
158 | /** |
||
159 | * Rename a remote file |
||
160 | * |
||
161 | * @param string $from |
||
162 | * @param string $to |
||
163 | * @return bool |
||
164 | * |
||
165 | * @throws \Icewind\SMB\Exception\NotFoundException |
||
166 | * @throws \Icewind\SMB\Exception\AlreadyExistsException |
||
167 | */ |
||
168 | 28 | public function rename($from, $to) { |
|
171 | |||
172 | /** |
||
173 | * Upload a local file |
||
174 | * |
||
175 | * @param string $source local file |
||
176 | * @param string $target remove file |
||
177 | * @return bool |
||
178 | * |
||
179 | * @throws \Icewind\SMB\Exception\NotFoundException |
||
180 | * @throws \Icewind\SMB\Exception\InvalidTypeException |
||
181 | */ |
||
182 | 113 | public function put($source, $target) { |
|
183 | 113 | $sourceHandle = fopen($source, 'rb'); |
|
184 | 113 | $targetHandle = $this->getState()->create($this->buildUrl($target)); |
|
185 | |||
186 | 102 | while ($data = fread($sourceHandle, NativeReadStream::CHUNK_SIZE)) { |
|
187 | 102 | $this->getState()->write($targetHandle, $data); |
|
188 | 102 | } |
|
189 | 102 | $this->getState()->close($targetHandle); |
|
190 | 102 | return true; |
|
191 | } |
||
192 | |||
193 | /** |
||
194 | * Download a remote file |
||
195 | * |
||
196 | * @param string $source remove file |
||
197 | * @param string $target local file |
||
198 | * @return bool |
||
199 | * |
||
200 | * @throws \Icewind\SMB\Exception\NotFoundException |
||
201 | * @throws \Icewind\SMB\Exception\InvalidTypeException |
||
202 | * @throws \Icewind\SMB\Exception\InvalidPathException |
||
203 | * @throws \Icewind\SMB\Exception\InvalidResourceException |
||
204 | */ |
||
205 | 44 | public function get($source, $target) { |
|
206 | 44 | if (!$target) { |
|
207 | 9 | throw new InvalidPathException('Invalid target path: Filename cannot be empty'); |
|
208 | } |
||
209 | 35 | $targetHandle = @fopen($target, 'wb'); |
|
210 | 35 | if (!$targetHandle) { |
|
211 | 1 | $error = error_get_last(); |
|
212 | 1 | if (is_array($error)) { |
|
213 | 1 | $reason = $error['message']; |
|
214 | 1 | } else { |
|
215 | $reason = 'Unknown error'; |
||
216 | } |
||
217 | 1 | throw new InvalidResourceException('Failed opening local file "' . $target . '" for writing: ' . $reason); |
|
218 | } |
||
219 | |||
220 | 34 | $sourceHandle = $this->getState()->open($this->buildUrl($source), 'r'); |
|
221 | 32 | if (!$sourceHandle) { |
|
222 | fclose($targetHandle); |
||
223 | throw new InvalidResourceException('Failed opening remote file "' . $source . '" for reading'); |
||
224 | } |
||
225 | |||
226 | 32 | while ($data = $this->getState()->read($sourceHandle, NativeReadStream::CHUNK_SIZE)) { |
|
227 | 32 | fwrite($targetHandle, $data); |
|
228 | 32 | } |
|
229 | 32 | $this->getState()->close($sourceHandle); |
|
230 | 32 | return true; |
|
231 | } |
||
232 | |||
233 | /** |
||
234 | * Open a readable stream to a remote file |
||
235 | * |
||
236 | * @param string $source |
||
237 | * @return resource a read only stream with the contents of the remote file |
||
238 | * |
||
239 | * @throws \Icewind\SMB\Exception\NotFoundException |
||
240 | * @throws \Icewind\SMB\Exception\InvalidTypeException |
||
241 | */ |
||
242 | 29 | public function read($source) { |
|
247 | |||
248 | /** |
||
249 | * Open a writeable stream to a remote file |
||
250 | * Note: This method will truncate the file to 0bytes first |
||
251 | * |
||
252 | * @param string $source |
||
253 | * @return resource a writeable stream |
||
254 | * |
||
255 | * @throws \Icewind\SMB\Exception\NotFoundException |
||
256 | * @throws \Icewind\SMB\Exception\InvalidTypeException |
||
257 | */ |
||
258 | 29 | public function write($source) { |
|
263 | |||
264 | /** |
||
265 | * Open a writeable stream and set the cursor to the end of the stream |
||
266 | * |
||
267 | * @param string $source |
||
268 | * @return resource a writeable stream |
||
269 | * |
||
270 | * @throws \Icewind\SMB\Exception\NotFoundException |
||
271 | * @throws \Icewind\SMB\Exception\InvalidTypeException |
||
272 | */ |
||
273 | 1 | public function append($source) { |
|
274 | 1 | $url = $this->buildUrl($source); |
|
275 | 1 | $handle = $this->getState()->open($url, "a"); |
|
276 | 1 | return NativeWriteStream::wrap($this->getState(), $handle, "a", $url); |
|
277 | } |
||
278 | |||
279 | /** |
||
280 | * Get extended attributes for the path |
||
281 | * |
||
282 | * @param string $path |
||
283 | * @param string $attribute attribute to get the info |
||
284 | * @return string the attribute value |
||
285 | */ |
||
286 | 14 | public function getAttribute($path, $attribute) { |
|
289 | |||
290 | /** |
||
291 | * Set extended attributes for the given path |
||
292 | * |
||
293 | * @param string $path |
||
294 | * @param string $attribute attribute to get the info |
||
295 | * @param string|int $value |
||
296 | * @return mixed the attribute value |
||
297 | */ |
||
298 | 8 | public function setAttribute($path, $attribute, $value) { |
|
305 | |||
306 | /** |
||
307 | * Set DOS comaptible node mode |
||
308 | * |
||
309 | * @param string $path |
||
310 | * @param int $mode a combination of FileInfo::MODE_READONLY, FileInfo::MODE_ARCHIVE, FileInfo::MODE_SYSTEM and FileInfo::MODE_HIDDEN, FileInfo::NORMAL |
||
311 | * @return mixed |
||
312 | */ |
||
313 | 8 | public function setMode($path, $mode) { |
|
316 | |||
317 | /** |
||
318 | * Start smb notify listener |
||
319 | * Note: This is a blocking call |
||
320 | * |
||
321 | * @param string $path |
||
322 | * @return INotifyHandler |
||
323 | */ |
||
324 | public function notify($path) { |
||
333 | |||
334 | 256 | public function __destruct() { |
|
337 | } |
||
338 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: