1 | <?php |
||
13 | class NativeShare extends AbstractShare { |
||
14 | /** |
||
15 | * @var Server $server |
||
16 | */ |
||
17 | private $server; |
||
18 | |||
19 | /** |
||
20 | * @var string $name |
||
21 | */ |
||
22 | private $name; |
||
23 | |||
24 | /** |
||
25 | * @var \Icewind\SMB\NativeState $state |
||
26 | */ |
||
27 | private $state; |
||
28 | |||
29 | /** |
||
30 | * @param Server $server |
||
31 | * @param string $name |
||
32 | */ |
||
33 | 508 | public function __construct($server, $name) { |
|
39 | |||
40 | /** |
||
41 | * @throws \Icewind\SMB\Exception\ConnectionException |
||
42 | * @throws \Icewind\SMB\Exception\AuthenticationException |
||
43 | * @throws \Icewind\SMB\Exception\InvalidHostException |
||
44 | */ |
||
45 | 508 | protected function connect() { |
|
52 | |||
53 | /** |
||
54 | * Get the name of the share |
||
55 | * |
||
56 | * @return string |
||
57 | */ |
||
58 | 2 | public function getName() { |
|
61 | |||
62 | 508 | private function buildUrl($path) { |
|
73 | |||
74 | /** |
||
75 | * List the content of a remote folder |
||
76 | * |
||
77 | * @param string $path |
||
78 | * @return \Icewind\SMB\IFileInfo[] |
||
79 | * |
||
80 | * @throws \Icewind\SMB\Exception\NotFoundException |
||
81 | * @throws \Icewind\SMB\Exception\InvalidTypeException |
||
82 | */ |
||
83 | 508 | public function dir($path) { |
|
97 | |||
98 | /** |
||
99 | * @param string $path |
||
100 | * @return \Icewind\SMB\IFileInfo[] |
||
101 | */ |
||
102 | 66 | public function stat($path) { |
|
105 | |||
106 | 226 | public function getStat($path) { |
|
109 | |||
110 | /** |
||
111 | * Create a folder on the share |
||
112 | * |
||
113 | * @param string $path |
||
114 | * @return bool |
||
115 | * |
||
116 | * @throws \Icewind\SMB\Exception\NotFoundException |
||
117 | * @throws \Icewind\SMB\Exception\AlreadyExistsException |
||
118 | */ |
||
119 | 508 | public function mkdir($path) { |
|
122 | |||
123 | /** |
||
124 | * Remove a folder on the share |
||
125 | * |
||
126 | * @param string $path |
||
127 | * @return bool |
||
128 | * |
||
129 | * @throws \Icewind\SMB\Exception\NotFoundException |
||
130 | * @throws \Icewind\SMB\Exception\InvalidTypeException |
||
131 | */ |
||
132 | 508 | public function rmdir($path) { |
|
135 | |||
136 | /** |
||
137 | * Delete a file on the share |
||
138 | * |
||
139 | * @param string $path |
||
140 | * @return bool |
||
141 | * |
||
142 | * @throws \Icewind\SMB\Exception\NotFoundException |
||
143 | * @throws \Icewind\SMB\Exception\InvalidTypeException |
||
144 | */ |
||
145 | 266 | public function del($path) { |
|
146 | 266 | return $this->state->unlink($this->buildUrl($path)); |
|
147 | } |
||
148 | |||
149 | /** |
||
150 | * Rename a remote file |
||
151 | * |
||
152 | * @param string $from |
||
153 | * @param string $to |
||
154 | * @return bool |
||
155 | * |
||
156 | * @throws \Icewind\SMB\Exception\NotFoundException |
||
157 | * @throws \Icewind\SMB\Exception\AlreadyExistsException |
||
158 | */ |
||
159 | 54 | public function rename($from, $to) { |
|
162 | |||
163 | /** |
||
164 | * Upload a local file |
||
165 | * |
||
166 | * @param string $source local file |
||
167 | * @param string $target remove file |
||
168 | * @return bool |
||
169 | * |
||
170 | * @throws \Icewind\SMB\Exception\NotFoundException |
||
171 | * @throws \Icewind\SMB\Exception\InvalidTypeException |
||
172 | */ |
||
173 | 226 | public function put($source, $target) { |
|
183 | |||
184 | /** |
||
185 | * Download a remote file |
||
186 | * |
||
187 | * @param string $source remove file |
||
188 | * @param string $target local file |
||
189 | * @return bool |
||
190 | * |
||
191 | * @throws \Icewind\SMB\Exception\NotFoundException |
||
192 | * @throws \Icewind\SMB\Exception\InvalidTypeException |
||
193 | * @throws \Icewind\SMB\Exception\InvalidPathException |
||
194 | * @throws \Icewind\SMB\Exception\InvalidResourceException |
||
195 | */ |
||
196 | 88 | public function get($source, $target) { |
|
197 | 88 | if (!$target) { |
|
198 | 18 | throw new InvalidPathException('Invalid target path: Filename cannot be empty'); |
|
199 | } |
||
200 | 70 | $targetHandle = @fopen($target, 'wb'); |
|
201 | 70 | if (!$targetHandle) { |
|
202 | 2 | $error = error_get_last(); |
|
203 | 2 | if (is_array($error)) { |
|
204 | 2 | $reason = $error['message']; |
|
205 | 2 | } else { |
|
206 | $reason = 'Unknown error'; |
||
207 | } |
||
208 | 2 | throw new InvalidResourceException('Failed opening local file "' . $target . '" for writing: ' . $reason); |
|
209 | } |
||
210 | |||
211 | 68 | $sourceHandle = $this->state->open($this->buildUrl($source), 'r'); |
|
212 | 64 | if (!$sourceHandle) { |
|
213 | fclose($targetHandle); |
||
214 | throw new InvalidResourceException('Failed opening remote file "' . $source . '" for reading'); |
||
215 | } |
||
216 | |||
217 | 64 | while ($data = $this->state->read($sourceHandle, 4096)) { |
|
218 | 64 | fwrite($targetHandle, $data); |
|
219 | 64 | } |
|
220 | 64 | $this->state->close($sourceHandle); |
|
221 | 64 | return true; |
|
222 | } |
||
223 | |||
224 | /** |
||
225 | * Open a readable stream top a remote file |
||
226 | * |
||
227 | * @param string $source |
||
228 | * @return resource a read only stream with the contents of the remote file |
||
229 | * |
||
230 | * @throws \Icewind\SMB\Exception\NotFoundException |
||
231 | * @throws \Icewind\SMB\Exception\InvalidTypeException |
||
232 | */ |
||
233 | 58 | public function read($source) { |
|
238 | |||
239 | /** |
||
240 | * Open a readable stream top a remote file |
||
241 | * |
||
242 | * @param string $source |
||
243 | * @return resource a read only stream with the contents of the remote file |
||
244 | * |
||
245 | * @throws \Icewind\SMB\Exception\NotFoundException |
||
246 | * @throws \Icewind\SMB\Exception\InvalidTypeException |
||
247 | */ |
||
248 | 58 | public function write($source) { |
|
253 | |||
254 | /** |
||
255 | * Get extended attributes for the path |
||
256 | * |
||
257 | * @param string $path |
||
258 | * @param string $attribute attribute to get the info |
||
259 | * @return string the attribute value |
||
260 | */ |
||
261 | 28 | public function getAttribute($path, $attribute) { |
|
264 | |||
265 | /** |
||
266 | * Get extended attributes for the path |
||
267 | * |
||
268 | * @param string $path |
||
269 | * @param string $attribute attribute to get the info |
||
270 | * @param mixed $value |
||
271 | * @return string the attribute value |
||
272 | */ |
||
273 | 16 | public function setAttribute($path, $attribute, $value) { |
|
281 | |||
282 | /** |
||
283 | * @param string $path |
||
284 | * @param int $mode a combination of FileInfo::MODE_READONLY, FileInfo::MODE_ARCHIVE, FileInfo::MODE_SYSTEM and FileInfo::MODE_HIDDEN, FileInfo::NORMAL |
||
285 | * @return mixed |
||
286 | */ |
||
287 | 16 | public function setMode($path, $mode) { |
|
290 | |||
291 | /** |
||
292 | * @param string $path |
||
293 | * @return INotifyHandler |
||
294 | */ |
||
295 | public function notify($path) { |
||
301 | |||
302 | 508 | public function __destruct() { |
|
305 | } |
||
306 |