1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* LICENSE: The MIT License (the "License") |
5
|
|
|
* you may not use this file except in compliance with the License. |
6
|
|
|
* You may obtain a copy of the License at |
7
|
|
|
* https://github.com/azure/azure-storage-php/LICENSE |
8
|
|
|
* |
9
|
|
|
* Unless required by applicable law or agreed to in writing, software |
10
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
11
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12
|
|
|
* See the License for the specific language governing permissions and |
13
|
|
|
* limitations under the License. |
14
|
|
|
* |
15
|
|
|
* PHP version 5 |
16
|
|
|
* |
17
|
|
|
* @category Microsoft |
18
|
|
|
* @package MicrosoftAzure\Storage\File |
19
|
|
|
* @author Azure Storage PHP SDK <[email protected]> |
20
|
|
|
* @copyright 2017 Microsoft Corporation |
21
|
|
|
* @license https://github.com/azure/azure-storage-php/LICENSE |
22
|
|
|
* @link https://github.com/azure/azure-storage-php |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
namespace MicrosoftAzure\Storage\File; |
26
|
|
|
|
27
|
|
|
use MicrosoftAzure\Storage\File\Internal\IFile; |
28
|
|
|
use MicrosoftAzure\Storage\Common\Internal\ServiceRestProxy; |
29
|
|
|
use MicrosoftAzure\Storage\Common\Internal\ServiceRestTrait; |
30
|
|
|
use MicrosoftAzure\Storage\Common\Internal\Utilities; |
31
|
|
|
use MicrosoftAzure\Storage\Common\Internal\Resources; |
32
|
|
|
use MicrosoftAzure\Storage\Common\Internal\Validate; |
33
|
|
|
use MicrosoftAzure\Storage\Common\LocationMode; |
34
|
|
|
use MicrosoftAzure\Storage\Common\Models\Range; |
35
|
|
|
use MicrosoftAzure\Storage\File\Models\ShareACL; |
36
|
|
|
use MicrosoftAzure\Storage\File\Models\ListSharesOptions; |
37
|
|
|
use MicrosoftAzure\Storage\File\Models\ListSharesResult; |
38
|
|
|
use MicrosoftAzure\Storage\File\Models\CreateShareOptions; |
39
|
|
|
use MicrosoftAzure\Storage\File\Models\CreateDirectoryOptions; |
40
|
|
|
use MicrosoftAzure\Storage\File\Models\FileServiceOptions; |
41
|
|
|
use MicrosoftAzure\Storage\File\Models\GetShareACLResult; |
42
|
|
|
use MicrosoftAzure\Storage\File\Models\GetSharePropertiesResult; |
43
|
|
|
use MicrosoftAzure\Storage\File\Models\GetShareStatsResult; |
44
|
|
|
use MicrosoftAzure\Storage\File\Models\ListDirectoriesAndFilesOptions; |
45
|
|
|
use MicrosoftAzure\Storage\File\Models\ListDirectoriesAndFilesResult; |
46
|
|
|
use MicrosoftAzure\Storage\File\Models\GetDirectoryPropertiesResult; |
47
|
|
|
use MicrosoftAzure\Storage\File\Models\GetDirectoryMetadataResult; |
48
|
|
|
use MicrosoftAzure\Storage\File\Models\GetFileMetadataResult; |
49
|
|
|
use MicrosoftAzure\Storage\File\Models\CreateFileOptions; |
50
|
|
|
use MicrosoftAzure\Storage\File\Models\FileProperties; |
51
|
|
|
use MicrosoftAzure\Storage\File\Models\PutFileRangeOptions; |
52
|
|
|
use MicrosoftAzure\Storage\File\Models\GetFileOptions; |
53
|
|
|
use MicrosoftAzure\Storage\File\Models\GetFileResult; |
54
|
|
|
use MicrosoftAzure\Storage\File\Models\ListFileRangesResult; |
55
|
|
|
use MicrosoftAzure\Storage\File\Models\CopyFileResult; |
56
|
|
|
use MicrosoftAzure\Storage\Common\Internal\Http\HttpFormatter; |
57
|
|
|
use Psr\Http\Message\StreamInterface; |
58
|
|
|
use GuzzleHttp\Psr7; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* This class constructs HTTP requests and receive HTTP responses for File |
62
|
|
|
* service layer. |
63
|
|
|
* |
64
|
|
|
* @category Microsoft |
65
|
|
|
* @package MicrosoftAzure\Storage\File |
66
|
|
|
* @author Azure Storage PHP SDK <[email protected]> |
67
|
|
|
* @copyright 2017 Microsoft Corporation |
68
|
|
|
* @license https://github.com/azure/azure-storage-php/LICENSE |
69
|
|
|
* @link https://github.com/azure/azure-storage-php |
70
|
|
|
*/ |
71
|
|
|
class FileRestProxy extends ServiceRestProxy implements IFile |
72
|
|
|
{ |
73
|
|
|
use ServiceRestTrait; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Creates URI path for file or share. |
77
|
|
|
* |
78
|
|
|
* @param string $share The share name. |
79
|
|
|
* @param string $directory The directory name. |
80
|
|
|
* |
81
|
|
|
* @return string |
82
|
|
|
*/ |
83
|
|
View Code Duplication |
private function createPath($share, $directory = '') |
|
|
|
|
84
|
|
|
{ |
85
|
|
|
if (empty($directory)) { |
86
|
|
|
if (!empty($share)) { |
87
|
|
|
return $share; |
88
|
|
|
} else { |
89
|
|
|
return '/' . $share; |
90
|
|
|
} |
91
|
|
|
} else { |
92
|
|
|
$encodedFile = urlencode($directory); |
93
|
|
|
// Unencode the forward slashes to match what the server expects. |
94
|
|
|
$encodedFile = str_replace('%2F', '/', $encodedFile); |
95
|
|
|
// Unencode the backward slashes to match what the server expects. |
96
|
|
|
$encodedFile = str_replace('%5C', '/', $encodedFile); |
97
|
|
|
// Re-encode the spaces (encoded as space) to the % encoding. |
98
|
|
|
$encodedFile = str_replace('+', '%20', $encodedFile); |
99
|
|
|
// Empty share means accessing default share |
100
|
|
|
if (empty($share)) { |
101
|
|
|
return $encodedFile; |
102
|
|
|
} else { |
103
|
|
|
return '/' . $share . '/' . $encodedFile; |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Helper method to create promise for getShareProperties API call. |
110
|
|
|
* |
111
|
|
|
* @param string $share The share name. |
112
|
|
|
* @param FileServiceOptions $options The optional parameters. |
113
|
|
|
* @param string $operation The operation string. Should be |
114
|
|
|
* 'metadata' to set metadata, |
115
|
|
|
* and 'properties' to set |
116
|
|
|
* properties. |
117
|
|
|
* |
118
|
|
|
* @return \GuzzleHttp\Promise\PromiseInterface |
119
|
|
|
*/ |
120
|
|
|
private function getSharePropertiesAsyncImpl( |
121
|
|
|
$share, |
122
|
|
|
FileServiceOptions $options = null, |
123
|
|
|
$operation = null |
124
|
|
|
) { |
125
|
|
|
Validate::isString($share, 'share'); |
126
|
|
|
Validate::isTrue( |
127
|
|
|
$operation == 'properties' || $operation == 'metadata', |
128
|
|
|
Resources::FILE_SHARE_PROPERTIES_OPERATION_INVALID |
129
|
|
|
); |
130
|
|
|
|
131
|
|
|
$method = Resources::HTTP_GET; |
132
|
|
|
$headers = array(); |
133
|
|
|
$queryParams = array(); |
134
|
|
|
$postParams = array(); |
135
|
|
|
$path = $this->createPath($share); |
136
|
|
|
|
137
|
|
|
if (is_null($options)) { |
138
|
|
|
$options = new FileServiceOptions(); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
$this->addOptionalQueryParam( |
142
|
|
|
$queryParams, |
143
|
|
|
Resources::QP_REST_TYPE, |
144
|
|
|
'share' |
145
|
|
|
); |
146
|
|
|
|
147
|
|
|
$this->addOptionalQueryParam( |
148
|
|
|
$queryParams, |
149
|
|
|
Resources::QP_TIMEOUT, |
150
|
|
|
$options->getTimeout() |
151
|
|
|
); |
152
|
|
|
|
153
|
|
|
if ($operation == 'metadata') { |
154
|
|
|
$this->addOptionalQueryParam( |
155
|
|
|
$queryParams, |
156
|
|
|
Resources::QP_COMP, |
157
|
|
|
$operation |
158
|
|
|
); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
return $this->sendAsync( |
162
|
|
|
$method, |
163
|
|
|
$headers, |
164
|
|
|
$queryParams, |
165
|
|
|
$postParams, |
166
|
|
|
$path, |
167
|
|
|
Resources::STATUS_OK, |
168
|
|
|
Resources::EMPTY_STRING, |
169
|
|
|
$options |
170
|
|
|
)->then(function ($response) { |
171
|
|
|
$responseHeaders = HttpFormatter::formatHeaders($response->getHeaders()); |
172
|
|
|
return GetSharePropertiesResult::create($responseHeaders); |
173
|
|
|
}, null); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* Helper method to create promise for setShareProperties API call. |
178
|
|
|
* |
179
|
|
|
* @param string $share The share name. |
180
|
|
|
* @param array $properties The array that contains |
181
|
|
|
* either the properties or |
182
|
|
|
* the metadata to be set. |
183
|
|
|
* @param FileServiceOptions $options The optional parameters. |
184
|
|
|
* @param string $operation The operation string. Should be |
185
|
|
|
* 'metadata' to set metadata, |
186
|
|
|
* and 'properties' to set |
187
|
|
|
* properties. |
188
|
|
|
* |
189
|
|
|
* @return \GuzzleHttp\Promise\PromiseInterface |
190
|
|
|
*/ |
191
|
|
|
private function setSharePropertiesAsyncImpl( |
192
|
|
|
$share, |
193
|
|
|
array $properties, |
194
|
|
|
FileServiceOptions $options = null, |
195
|
|
|
$operation = 'properties' |
196
|
|
|
) { |
197
|
|
|
Validate::isString($share, 'share'); |
198
|
|
|
Validate::isTrue( |
199
|
|
|
$operation == 'properties' || $operation == 'metadata', |
200
|
|
|
Resources::FILE_SHARE_PROPERTIES_OPERATION_INVALID |
201
|
|
|
); |
202
|
|
|
Validate::isString($share, 'share'); |
203
|
|
|
|
204
|
|
|
$headers = array(); |
205
|
|
|
if ($operation == 'properties') { |
206
|
|
|
$headers[Resources::X_MS_SHARE_QUOTA] = |
207
|
|
|
$properties[Resources::X_MS_SHARE_QUOTA]; |
208
|
|
|
} else { |
209
|
|
|
Utilities::validateMetadata($properties); |
210
|
|
|
$headers = $this->generateMetadataHeaders($properties); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
$method = Resources::HTTP_PUT; |
214
|
|
|
$postParams = array(); |
215
|
|
|
$queryParams = array(); |
216
|
|
|
$path = $this->createPath($share); |
217
|
|
|
|
218
|
|
|
if (is_null($options)) { |
219
|
|
|
$options = new FileServiceOptions(); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
$this->addOptionalQueryParam( |
223
|
|
|
$queryParams, |
224
|
|
|
Resources::QP_TIMEOUT, |
225
|
|
|
$options->getTimeout() |
226
|
|
|
); |
227
|
|
|
|
228
|
|
|
$this->addOptionalQueryParam( |
229
|
|
|
$queryParams, |
230
|
|
|
Resources::QP_REST_TYPE, |
231
|
|
|
'share' |
232
|
|
|
); |
233
|
|
|
$this->addOptionalQueryParam( |
234
|
|
|
$queryParams, |
235
|
|
|
Resources::QP_COMP, |
236
|
|
|
$operation |
237
|
|
|
); |
238
|
|
|
|
239
|
|
|
return $this->sendAsync( |
240
|
|
|
$method, |
241
|
|
|
$headers, |
242
|
|
|
$queryParams, |
243
|
|
|
$postParams, |
244
|
|
|
$path, |
245
|
|
|
Resources::STATUS_OK, |
246
|
|
|
Resources::EMPTY_STRING, |
247
|
|
|
$options |
248
|
|
|
); |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* Creates promise to write range of bytes (more than 4MB) to a file. |
253
|
|
|
* |
254
|
|
|
* @param string $share The share name. |
255
|
|
|
* @param string $path The path of the file. |
256
|
|
|
* @param StreamInterface $content The content to be uploaded. |
257
|
|
|
* @param Range $range The range in the file to be put. |
258
|
|
|
* 4MB length min. |
259
|
|
|
* @param PutFileRangeOptions|null $options The optional parameters. |
260
|
|
|
* |
261
|
|
|
* @return \GuzzleHttp\Promise\PromiseInterface |
262
|
|
|
* |
263
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/put-range |
264
|
|
|
* |
265
|
|
|
*/ |
266
|
|
|
private function multiplePutRangeConcurrentAsync( |
267
|
|
|
$share, |
268
|
|
|
$path, |
269
|
|
|
$content, |
270
|
|
|
Range $range, |
271
|
|
|
PutFileRangeOptions $options = null |
272
|
|
|
) { |
273
|
|
|
$queryParams = array(); |
274
|
|
|
$headers = array(); |
275
|
|
|
$path = $this->createPath($share, $path); |
276
|
|
|
$selfInstance = $this; |
277
|
|
|
|
278
|
|
|
if ($options == null) { |
279
|
|
|
$options = new PutFileRangeOptions(); |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
$this->addOptionalQueryParam( |
283
|
|
|
$queryParams, |
284
|
|
|
Resources::QP_COMP, |
285
|
|
|
'range' |
286
|
|
|
); |
287
|
|
|
|
288
|
|
|
$this->addOptionalQueryParam( |
289
|
|
|
$queryParams, |
290
|
|
|
Resources::QP_TIMEOUT, |
291
|
|
|
$options->getTimeout() |
292
|
|
|
); |
293
|
|
|
|
294
|
|
|
$this->addOptionalHeader( |
295
|
|
|
$headers, |
296
|
|
|
Resources::X_MS_WRITE, |
297
|
|
|
'Update' |
298
|
|
|
); |
299
|
|
|
|
300
|
|
|
$counter = 0; |
301
|
|
|
//create the generator for requests. |
302
|
|
|
$generator = function () use ( |
303
|
|
|
$headers, |
304
|
|
|
$path, |
305
|
|
|
$content, |
306
|
|
|
&$counter, |
307
|
|
|
$queryParams, |
308
|
|
|
$range, |
309
|
|
|
$selfInstance |
310
|
|
|
) { |
311
|
|
|
$size = 0; |
|
|
|
|
312
|
|
|
$chunkContent = ''; |
|
|
|
|
313
|
|
|
$start = 0; |
|
|
|
|
314
|
|
|
|
315
|
|
|
do { |
316
|
|
|
$start = $range->getStart() + (Resources::MB_IN_BYTES_4 * $counter++); |
317
|
|
|
$end = $range->getEnd(); |
318
|
|
|
if ($end != null && $start >= $end) { |
|
|
|
|
319
|
|
|
return null; |
320
|
|
|
} |
321
|
|
|
$chunkContent = $content->read(Resources::MB_IN_BYTES_4); |
322
|
|
|
$size = strlen($chunkContent); |
323
|
|
|
if ($size == 0) { |
324
|
|
|
return null; |
325
|
|
|
} |
326
|
|
|
} while (Utilities::allZero($chunkContent)); |
327
|
|
|
|
328
|
|
|
$chunkRange = new Range($start); |
329
|
|
|
$chunkRange->setLength($size); |
330
|
|
|
|
331
|
|
|
$selfInstance->addOptionalHeader( |
332
|
|
|
$headers, |
333
|
|
|
Resources::X_MS_RANGE, |
334
|
|
|
$chunkRange->getRangeString() |
335
|
|
|
); |
336
|
|
|
|
337
|
|
|
$this->addOptionalHeader( |
338
|
|
|
$headers, |
339
|
|
|
Resources::CONTENT_LENGTH, |
340
|
|
|
$size |
341
|
|
|
); |
342
|
|
|
|
343
|
|
|
return $selfInstance->createRequest( |
344
|
|
|
Resources::HTTP_PUT, |
345
|
|
|
$headers, |
346
|
|
|
$queryParams, |
347
|
|
|
array(), |
348
|
|
|
$path, |
349
|
|
|
LocationMode::PRIMARY_ONLY, |
350
|
|
|
$chunkContent |
351
|
|
|
); |
352
|
|
|
}; |
353
|
|
|
|
354
|
|
|
return $this->sendConcurrentAsync( |
355
|
|
|
$generator, |
356
|
|
|
Resources::STATUS_CREATED, |
357
|
|
|
$options |
358
|
|
|
); |
359
|
|
|
} |
360
|
|
|
|
361
|
|
|
|
362
|
|
|
/** |
363
|
|
|
* Returns a list of the shares under the specified account |
364
|
|
|
* |
365
|
|
|
* @param ListSharesOptions|null $options The optional parameters |
366
|
|
|
* |
367
|
|
|
* @return ListSharesResult |
368
|
|
|
* |
369
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/list-shares |
370
|
|
|
*/ |
371
|
|
|
public function listShares(ListSharesOptions $options = null) |
372
|
|
|
{ |
373
|
|
|
return $this->listSharesAsync($options)->wait(); |
374
|
|
|
} |
375
|
|
|
|
376
|
|
|
/** |
377
|
|
|
* Create a promise to return a list of the shares under the specified account |
378
|
|
|
* |
379
|
|
|
* @param ListSharesOptions|null $options The optional parameters |
380
|
|
|
* |
381
|
|
|
* @return \GuzzleHttp\Promise\PromiseInterface |
382
|
|
|
* |
383
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/list-shares |
384
|
|
|
*/ |
385
|
|
|
public function listSharesAsync(ListSharesOptions $options = null) |
386
|
|
|
{ |
387
|
|
|
$method = Resources::HTTP_GET; |
388
|
|
|
$headers = array(); |
389
|
|
|
$queryParams = array(); |
390
|
|
|
$postParams = array(); |
391
|
|
|
$path = Resources::EMPTY_STRING; |
392
|
|
|
|
393
|
|
|
if (is_null($options)) { |
394
|
|
|
$options = new ListSharesOptions(); |
395
|
|
|
} |
396
|
|
|
|
397
|
|
|
$this->addOptionalQueryParam( |
398
|
|
|
$queryParams, |
399
|
|
|
Resources::QP_COMP, |
400
|
|
|
'list' |
401
|
|
|
); |
402
|
|
|
$this->addOptionalQueryParam( |
403
|
|
|
$queryParams, |
404
|
|
|
Resources::QP_TIMEOUT, |
405
|
|
|
$options->getTimeout() |
406
|
|
|
); |
407
|
|
|
$this->addOptionalQueryParam( |
408
|
|
|
$queryParams, |
409
|
|
|
Resources::QP_PREFIX, |
410
|
|
|
$options->getPrefix() |
411
|
|
|
); |
412
|
|
|
$this->addOptionalQueryParam( |
413
|
|
|
$queryParams, |
414
|
|
|
Resources::QP_MARKER, |
415
|
|
|
$options->getNextMarker() |
416
|
|
|
); |
417
|
|
|
$this->addOptionalQueryParam( |
418
|
|
|
$queryParams, |
419
|
|
|
Resources::QP_MAX_RESULTS, |
420
|
|
|
$options->getMaxResults() |
421
|
|
|
); |
422
|
|
|
$isInclude = $options->getIncludeMetadata(); |
423
|
|
|
$isInclude = $isInclude ? 'metadata' : null; |
424
|
|
|
$this->addOptionalQueryParam( |
425
|
|
|
$queryParams, |
426
|
|
|
Resources::QP_INCLUDE, |
427
|
|
|
$isInclude |
428
|
|
|
); |
429
|
|
|
|
430
|
|
|
$dataSerializer = $this->dataSerializer; |
431
|
|
|
|
432
|
|
|
return $this->sendAsync( |
433
|
|
|
$method, |
434
|
|
|
$headers, |
435
|
|
|
$queryParams, |
436
|
|
|
$postParams, |
437
|
|
|
$path, |
438
|
|
|
Resources::STATUS_OK, |
439
|
|
|
Resources::EMPTY_STRING, |
440
|
|
|
$options |
441
|
|
View Code Duplication |
)->then(function ($response) use ($dataSerializer) { |
|
|
|
|
442
|
|
|
$parsed = $dataSerializer->unserialize($response->getBody()); |
443
|
|
|
return ListSharesResult::create( |
444
|
|
|
$parsed, |
445
|
|
|
Utilities::getLocationFromHeaders($response->getHeaders()) |
446
|
|
|
); |
447
|
|
|
}); |
448
|
|
|
} |
449
|
|
|
|
450
|
|
|
/** |
451
|
|
|
* Creates a new share in the given storage account. |
452
|
|
|
* |
453
|
|
|
* @param string $share The share name. |
454
|
|
|
* @param CreateShareOptions|null $options The optional parameters. |
455
|
|
|
* |
456
|
|
|
* @return void |
457
|
|
|
* |
458
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/create-share |
459
|
|
|
*/ |
460
|
|
|
public function createShare( |
461
|
|
|
$share, |
462
|
|
|
CreateShareOptions $options = null |
463
|
|
|
) { |
464
|
|
|
$this->createShareAsync($share, $options)->wait(); |
465
|
|
|
} |
466
|
|
|
|
467
|
|
|
/** |
468
|
|
|
* Creates promise to create a new share in the given storage account. |
469
|
|
|
* |
470
|
|
|
* @param string $share The share name. |
471
|
|
|
* @param CreateShareOptions|null $options The optional parameters. |
472
|
|
|
* |
473
|
|
|
* @return \GuzzleHttp\Promise\PromiseInterface |
474
|
|
|
* |
475
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/create-share |
476
|
|
|
*/ |
477
|
|
View Code Duplication |
public function createShareAsync( |
|
|
|
|
478
|
|
|
$share, |
479
|
|
|
CreateShareOptions $options = null |
480
|
|
|
) { |
481
|
|
|
Validate::isString($share, 'share'); |
482
|
|
|
Validate::notNullOrEmpty($share, 'share'); |
483
|
|
|
|
484
|
|
|
$method = Resources::HTTP_PUT; |
485
|
|
|
$headers = array(); |
|
|
|
|
486
|
|
|
$postParams = array(); |
487
|
|
|
$queryParams = array(Resources::QP_REST_TYPE => 'share'); |
488
|
|
|
$path = $this->createPath($share); |
489
|
|
|
|
490
|
|
|
if (is_null($options)) { |
491
|
|
|
$options = new CreateShareOptions(); |
492
|
|
|
} |
493
|
|
|
|
494
|
|
|
$metadata = $options->getMetadata(); |
495
|
|
|
$headers = $this->generateMetadataHeaders($metadata); |
496
|
|
|
$this->addOptionalHeader( |
497
|
|
|
$headers, |
498
|
|
|
Resources::X_MS_SHARE_QUOTA, |
499
|
|
|
$options->getQuota() |
500
|
|
|
); |
501
|
|
|
|
502
|
|
|
$this->addOptionalQueryParam( |
503
|
|
|
$queryParams, |
504
|
|
|
Resources::QP_TIMEOUT, |
505
|
|
|
$options->getTimeout() |
506
|
|
|
); |
507
|
|
|
|
508
|
|
|
return $this->sendAsync( |
509
|
|
|
$method, |
510
|
|
|
$headers, |
511
|
|
|
$queryParams, |
512
|
|
|
$postParams, |
513
|
|
|
$path, |
514
|
|
|
Resources::STATUS_CREATED, |
515
|
|
|
Resources::EMPTY_STRING, |
516
|
|
|
$options |
517
|
|
|
); |
518
|
|
|
} |
519
|
|
|
|
520
|
|
|
/** |
521
|
|
|
* Deletes a share in the given storage account. |
522
|
|
|
* |
523
|
|
|
* @param string $share name of the share |
524
|
|
|
* @param FileServiceOptions|null $options optional parameters |
525
|
|
|
* |
526
|
|
|
* @return void |
527
|
|
|
* |
528
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/delete-share |
529
|
|
|
*/ |
530
|
|
|
public function deleteShare( |
531
|
|
|
$share, |
532
|
|
|
FileServiceOptions $options = null |
533
|
|
|
) { |
534
|
|
|
$this->deleteShareAsync($share, $options)->wait(); |
535
|
|
|
} |
536
|
|
|
|
537
|
|
|
/** |
538
|
|
|
* Create a promise for deleting a share. |
539
|
|
|
* |
540
|
|
|
* @param string $share name of the share |
541
|
|
|
* @param FileServiceOptions|null $options optional parameters |
542
|
|
|
* |
543
|
|
|
* @return \GuzzleHttp\Promise\PromiseInterface |
544
|
|
|
* |
545
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/delete-share |
546
|
|
|
*/ |
547
|
|
View Code Duplication |
public function deleteShareAsync( |
|
|
|
|
548
|
|
|
$share, |
549
|
|
|
FileServiceOptions $options = null |
550
|
|
|
) { |
551
|
|
|
Validate::isString($share, 'share'); |
552
|
|
|
Validate::notNullOrEmpty($share, 'share'); |
553
|
|
|
|
554
|
|
|
$method = Resources::HTTP_DELETE; |
555
|
|
|
$headers = array(); |
556
|
|
|
$postParams = array(); |
557
|
|
|
$queryParams = array(); |
558
|
|
|
$path = $this->createPath($share); |
559
|
|
|
|
560
|
|
|
if (is_null($options)) { |
561
|
|
|
$options = new FileServiceOptions(); |
562
|
|
|
} |
563
|
|
|
|
564
|
|
|
$this->addOptionalQueryParam( |
565
|
|
|
$queryParams, |
566
|
|
|
Resources::QP_TIMEOUT, |
567
|
|
|
$options->getTimeout() |
568
|
|
|
); |
569
|
|
|
|
570
|
|
|
$this->addOptionalQueryParam( |
571
|
|
|
$queryParams, |
572
|
|
|
Resources::QP_REST_TYPE, |
573
|
|
|
'share' |
574
|
|
|
); |
575
|
|
|
|
576
|
|
|
return $this->sendAsync( |
577
|
|
|
$method, |
578
|
|
|
$headers, |
579
|
|
|
$queryParams, |
580
|
|
|
$postParams, |
581
|
|
|
$path, |
582
|
|
|
Resources::STATUS_ACCEPTED, |
583
|
|
|
Resources::EMPTY_STRING, |
584
|
|
|
$options |
585
|
|
|
); |
586
|
|
|
} |
587
|
|
|
|
588
|
|
|
/** |
589
|
|
|
* Returns all properties and metadata on the share. |
590
|
|
|
* |
591
|
|
|
* @param string $share name |
592
|
|
|
* @param FileServiceOptions|null $options optional parameters |
593
|
|
|
* |
594
|
|
|
* @return GetSharePropertiesResult |
595
|
|
|
* |
596
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/get-share-properties |
597
|
|
|
*/ |
598
|
|
|
public function getShareProperties( |
599
|
|
|
$share, |
600
|
|
|
FileServiceOptions $options = null |
601
|
|
|
) { |
602
|
|
|
return $this->getSharePropertiesAsync($share, $options)->wait(); |
603
|
|
|
} |
604
|
|
|
|
605
|
|
|
/** |
606
|
|
|
* Create promise to return all properties and metadata on the share. |
607
|
|
|
* |
608
|
|
|
* @param string $share name |
609
|
|
|
* @param FileServiceOptions|null $options optional parameters |
610
|
|
|
* |
611
|
|
|
* @return \GuzzleHttp\Promise\PromiseInterface |
612
|
|
|
* |
613
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/get-share-properties |
614
|
|
|
*/ |
615
|
|
|
public function getSharePropertiesAsync( |
616
|
|
|
$share, |
617
|
|
|
FileServiceOptions $options = null |
618
|
|
|
) { |
619
|
|
|
return $this->getSharePropertiesAsyncImpl($share, $options, 'properties'); |
620
|
|
|
} |
621
|
|
|
|
622
|
|
|
/** |
623
|
|
|
* Sets quota of the share. |
624
|
|
|
* |
625
|
|
|
* @param string $share name |
626
|
|
|
* @param int $quota quota of the share |
627
|
|
|
* @param FileServiceOptions|null $options optional parameters |
628
|
|
|
* |
629
|
|
|
* @return void |
630
|
|
|
* |
631
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/set-share-properties |
632
|
|
|
*/ |
633
|
|
|
public function setShareProperties( |
634
|
|
|
$share, |
635
|
|
|
$quota, |
636
|
|
|
FileServiceOptions $options = null |
637
|
|
|
) { |
638
|
|
|
$this->setSharePropertiesAsync($share, $quota, $options)->wait(); |
639
|
|
|
} |
640
|
|
|
|
641
|
|
|
/** |
642
|
|
|
* Creates promise to set quota the share. |
643
|
|
|
* |
644
|
|
|
* @param string $share name |
645
|
|
|
* @param int $quota quota of the share |
646
|
|
|
* @param FileServiceOptions|null $options optional parameters |
647
|
|
|
* |
648
|
|
|
* @return \GuzzleHttp\Promise\PromiseInterface |
649
|
|
|
* |
650
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/set-share-properties |
651
|
|
|
*/ |
652
|
|
|
public function setSharePropertiesAsync( |
653
|
|
|
$share, |
654
|
|
|
$quota, |
655
|
|
|
FileServiceOptions $options = null |
656
|
|
|
) { |
657
|
|
|
return $this->setSharePropertiesAsyncImpl( |
658
|
|
|
$share, |
659
|
|
|
[Resources::X_MS_SHARE_QUOTA => $quota], |
660
|
|
|
$options, |
661
|
|
|
'properties' |
662
|
|
|
); |
663
|
|
|
} |
664
|
|
|
|
665
|
|
|
/** |
666
|
|
|
* Returns only user-defined metadata for the specified share. |
667
|
|
|
* |
668
|
|
|
* @param string $share name |
669
|
|
|
* @param FileServiceOptions|null $options optional parameters |
670
|
|
|
* |
671
|
|
|
* @return GetSharePropertiesResult |
672
|
|
|
* |
673
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/get-share-metadata |
674
|
|
|
*/ |
675
|
|
|
public function getShareMetadata( |
676
|
|
|
$share, |
677
|
|
|
FileServiceOptions $options = null |
678
|
|
|
) { |
679
|
|
|
return $this->getShareMetadataAsync($share, $options)->wait(); |
680
|
|
|
} |
681
|
|
|
|
682
|
|
|
/** |
683
|
|
|
* Create promise to return only user-defined metadata for the specified |
684
|
|
|
* share. |
685
|
|
|
* |
686
|
|
|
* @param string $share name |
687
|
|
|
* @param FileServiceOptions|null $options optional parameters |
688
|
|
|
* |
689
|
|
|
* @return \GuzzleHttp\Promise\PromiseInterface |
690
|
|
|
* |
691
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/get-share-metadata |
692
|
|
|
*/ |
693
|
|
|
public function getShareMetadataAsync( |
694
|
|
|
$share, |
695
|
|
|
FileServiceOptions $options = null |
696
|
|
|
) { |
697
|
|
|
return $this->getSharePropertiesAsyncImpl($share, $options, 'metadata'); |
698
|
|
|
} |
699
|
|
|
|
700
|
|
|
/** |
701
|
|
|
* Updates metadata of the share. |
702
|
|
|
* |
703
|
|
|
* @param string $share name |
704
|
|
|
* @param array $metadata metadata key/value pair. |
705
|
|
|
* @param FileServiceOptions|null $options optional parameters |
706
|
|
|
* |
707
|
|
|
* @return void |
708
|
|
|
* |
709
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/set-share-metadata |
710
|
|
|
*/ |
711
|
|
|
public function setShareMetadata( |
712
|
|
|
$share, |
713
|
|
|
array $metadata, |
714
|
|
|
FileServiceOptions $options = null |
715
|
|
|
) { |
716
|
|
|
$this->setShareMetadataAsync($share, $metadata, $options)->wait(); |
717
|
|
|
} |
718
|
|
|
|
719
|
|
|
/** |
720
|
|
|
* Creates promise to update metadata headers on the share. |
721
|
|
|
* |
722
|
|
|
* @param string $share name |
723
|
|
|
* @param array $metadata metadata key/value pair. |
724
|
|
|
* @param FileServiceOptions|null $options optional parameters |
725
|
|
|
* |
726
|
|
|
* @return \GuzzleHttp\Promise\PromiseInterface |
727
|
|
|
* |
728
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/set-share-metadata |
729
|
|
|
*/ |
730
|
|
|
public function setShareMetadataAsync( |
731
|
|
|
$share, |
732
|
|
|
array $metadata, |
733
|
|
|
FileServiceOptions $options = null |
734
|
|
|
) { |
735
|
|
|
return $this->setSharePropertiesAsyncImpl( |
736
|
|
|
$share, |
737
|
|
|
$metadata, |
738
|
|
|
$options, |
739
|
|
|
'metadata' |
740
|
|
|
); |
741
|
|
|
} |
742
|
|
|
|
743
|
|
|
/** |
744
|
|
|
* Gets the access control list (ACL) for the share. |
745
|
|
|
* |
746
|
|
|
* @param string $share The share name. |
747
|
|
|
* @param FileServiceOptions|null $options The optional parameters. |
748
|
|
|
* |
749
|
|
|
* @return GetShareACLResult |
750
|
|
|
* |
751
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/get-share-acl |
752
|
|
|
*/ |
753
|
|
|
public function getShareAcl( |
754
|
|
|
$share, |
755
|
|
|
FileServiceOptions $options = null |
756
|
|
|
) { |
757
|
|
|
return $this->getShareAclAsync($share, $options)->wait(); |
758
|
|
|
} |
759
|
|
|
|
760
|
|
|
/** |
761
|
|
|
* Creates the promise to get the access control list (ACL) for the share. |
762
|
|
|
* |
763
|
|
|
* @param string $share The share name. |
764
|
|
|
* @param FileServiceOptions|null $options The optional parameters. |
765
|
|
|
* |
766
|
|
|
* @return \GuzzleHttp\Promise\PromiseInterface |
767
|
|
|
* |
768
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/get-share-acl |
769
|
|
|
*/ |
770
|
|
|
public function getShareAclAsync( |
771
|
|
|
$share, |
772
|
|
|
FileServiceOptions $options = null |
773
|
|
|
) { |
774
|
|
|
Validate::isString($share, 'share'); |
775
|
|
|
|
776
|
|
|
$method = Resources::HTTP_GET; |
777
|
|
|
$headers = array(); |
778
|
|
|
$postParams = array(); |
779
|
|
|
$queryParams = array(); |
780
|
|
|
$path = $this->createPath($share); |
781
|
|
|
$statusCode = Resources::STATUS_OK; |
|
|
|
|
782
|
|
|
|
783
|
|
|
if (is_null($options)) { |
784
|
|
|
$options = new FileServiceOptions(); |
785
|
|
|
} |
786
|
|
|
|
787
|
|
|
$this->addOptionalQueryParam( |
788
|
|
|
$queryParams, |
789
|
|
|
Resources::QP_REST_TYPE, |
790
|
|
|
'share' |
791
|
|
|
); |
792
|
|
|
$this->addOptionalQueryParam( |
793
|
|
|
$queryParams, |
794
|
|
|
Resources::QP_COMP, |
795
|
|
|
'acl' |
796
|
|
|
); |
797
|
|
|
$this->addOptionalQueryParam( |
798
|
|
|
$queryParams, |
799
|
|
|
Resources::QP_TIMEOUT, |
800
|
|
|
$options->getTimeout() |
801
|
|
|
); |
802
|
|
|
|
803
|
|
|
$dataSerializer = $this->dataSerializer; |
804
|
|
|
|
805
|
|
|
$promise = $this->sendAsync( |
806
|
|
|
$method, |
807
|
|
|
$headers, |
808
|
|
|
$queryParams, |
809
|
|
|
$postParams, |
810
|
|
|
$path, |
811
|
|
|
Resources::STATUS_OK, |
812
|
|
|
Resources::EMPTY_STRING, |
813
|
|
|
$options |
814
|
|
|
); |
815
|
|
|
|
816
|
|
|
return $promise->then(function ($response) use ($dataSerializer) { |
817
|
|
|
$responseHeaders = HttpFormatter::formatHeaders($response->getHeaders()); |
818
|
|
|
|
819
|
|
|
$etag = Utilities::tryGetValue($responseHeaders, Resources::ETAG); |
820
|
|
|
$modified = Utilities::tryGetValue( |
821
|
|
|
$responseHeaders, |
822
|
|
|
Resources::LAST_MODIFIED |
823
|
|
|
); |
824
|
|
|
$modifiedDate = Utilities::convertToDateTime($modified); |
825
|
|
|
$parsed = $dataSerializer->unserialize($response->getBody()); |
826
|
|
|
|
827
|
|
|
return GetShareAclResult::create( |
828
|
|
|
$etag, |
829
|
|
|
$modifiedDate, |
830
|
|
|
$parsed |
831
|
|
|
); |
832
|
|
|
}, null); |
833
|
|
|
} |
834
|
|
|
|
835
|
|
|
/** |
836
|
|
|
* Sets the ACL and any share-level access policies for the share. |
837
|
|
|
* |
838
|
|
|
* @param string $share name |
839
|
|
|
* @param ShareACL $acl access control list for share |
840
|
|
|
* @param FileServiceOptions|null $options optional parameters |
841
|
|
|
* |
842
|
|
|
* @return void |
843
|
|
|
* |
844
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/set-share-acl |
845
|
|
|
*/ |
846
|
|
|
public function setShareAcl( |
847
|
|
|
$share, |
848
|
|
|
ShareACL $acl, |
849
|
|
|
FileServiceOptions $options = null |
850
|
|
|
) { |
851
|
|
|
$this->setShareAclAsync($share, $acl, $options)->wait(); |
852
|
|
|
} |
853
|
|
|
|
854
|
|
|
/** |
855
|
|
|
* Creates promise to set the ACL and any share-level access policies |
856
|
|
|
* for the share. |
857
|
|
|
* |
858
|
|
|
* @param string $share name |
859
|
|
|
* @param ShareACL $acl access control list for share |
860
|
|
|
* @param FileServiceOptions|null $options optional parameters |
861
|
|
|
* |
862
|
|
|
* @return \GuzzleHttp\Promise\PromiseInterface |
863
|
|
|
* |
864
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/set-share-acl |
865
|
|
|
*/ |
866
|
|
View Code Duplication |
public function setShareAclAsync( |
|
|
|
|
867
|
|
|
$share, |
868
|
|
|
ShareACL $acl, |
869
|
|
|
FileServiceOptions $options = null |
870
|
|
|
) { |
871
|
|
|
Validate::isString($share, 'share'); |
872
|
|
|
Validate::notNullOrEmpty($acl, 'acl'); |
873
|
|
|
|
874
|
|
|
$method = Resources::HTTP_PUT; |
875
|
|
|
$headers = array(); |
876
|
|
|
$postParams = array(); |
877
|
|
|
$queryParams = array(); |
878
|
|
|
$path = $this->createPath($share); |
879
|
|
|
$body = $acl->toXml($this->dataSerializer); |
|
|
|
|
880
|
|
|
|
881
|
|
|
if (is_null($options)) { |
882
|
|
|
$options = new FileServiceOptions(); |
883
|
|
|
} |
884
|
|
|
|
885
|
|
|
$this->addOptionalQueryParam( |
886
|
|
|
$queryParams, |
887
|
|
|
Resources::QP_REST_TYPE, |
888
|
|
|
'share' |
889
|
|
|
); |
890
|
|
|
$this->addOptionalQueryParam( |
891
|
|
|
$queryParams, |
892
|
|
|
Resources::QP_COMP, |
893
|
|
|
'acl' |
894
|
|
|
); |
895
|
|
|
$this->addOptionalQueryParam( |
896
|
|
|
$queryParams, |
897
|
|
|
Resources::QP_TIMEOUT, |
898
|
|
|
$options->getTimeout() |
899
|
|
|
); |
900
|
|
|
$this->addOptionalHeader( |
901
|
|
|
$headers, |
902
|
|
|
Resources::CONTENT_TYPE, |
903
|
|
|
Resources::URL_ENCODED_CONTENT_TYPE |
904
|
|
|
); |
905
|
|
|
|
906
|
|
|
return $this->sendAsync( |
907
|
|
|
$method, |
908
|
|
|
$headers, |
909
|
|
|
$queryParams, |
910
|
|
|
$postParams, |
911
|
|
|
$path, |
912
|
|
|
Resources::STATUS_OK, |
913
|
|
|
$body, |
|
|
|
|
914
|
|
|
$options |
915
|
|
|
); |
916
|
|
|
} |
917
|
|
|
|
918
|
|
|
/** |
919
|
|
|
* Get the statistics related to the share. |
920
|
|
|
* |
921
|
|
|
* @param string $share The name of the share. |
922
|
|
|
* @param FileServiceOptions|null $options The request options. |
923
|
|
|
* |
924
|
|
|
* @return GetShareStatsResult |
925
|
|
|
* |
926
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/get-share-stats |
927
|
|
|
*/ |
928
|
|
|
public function getShareStats($share, FileServiceOptions $options = null) |
929
|
|
|
{ |
930
|
|
|
return $this->getShareStatsAsync($share, $options)->wait(); |
931
|
|
|
} |
932
|
|
|
|
933
|
|
|
/** |
934
|
|
|
* Get the statistics related to the share. |
935
|
|
|
* |
936
|
|
|
* @param string $share The name of the share. |
937
|
|
|
* @param FileServiceOptions|null $options The request options. |
938
|
|
|
* |
939
|
|
|
* @return \GuzzleHttp\Promise\PromiseInterface |
940
|
|
|
* |
941
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/get-share-stats |
942
|
|
|
*/ |
943
|
|
View Code Duplication |
public function getShareStatsAsync($share, FileServiceOptions $options = null) |
|
|
|
|
944
|
|
|
{ |
945
|
|
|
Validate::isString($share, 'share'); |
946
|
|
|
|
947
|
|
|
$method = Resources::HTTP_GET; |
948
|
|
|
$headers = array(); |
949
|
|
|
$queryParams = array(); |
950
|
|
|
$postParams = array(); |
951
|
|
|
$path = $this->createPath($share); |
952
|
|
|
|
953
|
|
|
if (is_null($options)) { |
954
|
|
|
$options = new FileServiceOptions(); |
955
|
|
|
} |
956
|
|
|
|
957
|
|
|
$this->addOptionalQueryParam( |
958
|
|
|
$queryParams, |
959
|
|
|
Resources::QP_REST_TYPE, |
960
|
|
|
'share' |
961
|
|
|
); |
962
|
|
|
|
963
|
|
|
$this->addOptionalQueryParam( |
964
|
|
|
$queryParams, |
965
|
|
|
Resources::QP_COMP, |
966
|
|
|
'stats' |
967
|
|
|
); |
968
|
|
|
|
969
|
|
|
$this->addOptionalQueryParam( |
970
|
|
|
$queryParams, |
971
|
|
|
Resources::QP_TIMEOUT, |
972
|
|
|
$options->getTimeout() |
973
|
|
|
); |
974
|
|
|
|
975
|
|
|
$dataSerializer = $this->dataSerializer; |
976
|
|
|
|
977
|
|
|
return $this->sendAsync( |
978
|
|
|
$method, |
979
|
|
|
$headers, |
980
|
|
|
$queryParams, |
981
|
|
|
$postParams, |
982
|
|
|
$path, |
983
|
|
|
Resources::STATUS_OK, |
984
|
|
|
Resources::EMPTY_STRING, |
985
|
|
|
$options |
986
|
|
|
)->then(function ($response) use ($dataSerializer) { |
987
|
|
|
$parsed = $dataSerializer->unserialize($response->getBody()); |
988
|
|
|
return GetShareStatsResult::create($parsed); |
989
|
|
|
}, null); |
990
|
|
|
} |
991
|
|
|
|
992
|
|
|
/** |
993
|
|
|
* List directories and files under specified path. |
994
|
|
|
* |
995
|
|
|
* @param string $share The share that |
996
|
|
|
* contains all the |
997
|
|
|
* files and directories. |
998
|
|
|
* @param string $path The path to be listed. |
999
|
|
|
* @param ListDirectoriesAndFilesOptions|null $options Optional parameters. |
1000
|
|
|
* |
1001
|
|
|
* @return ListDirectoriesAndFilesResult |
1002
|
|
|
* |
1003
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/list-directories-and-files |
1004
|
|
|
*/ |
1005
|
|
|
public function listDirectoriesAndFiles( |
1006
|
|
|
$share, |
1007
|
|
|
$path = '', |
1008
|
|
|
ListDirectoriesAndFilesOptions $options = null |
1009
|
|
|
) { |
1010
|
|
|
return $this->listDirectoriesAndFilesAsync($share, $path, $options)->wait(); |
1011
|
|
|
} |
1012
|
|
|
|
1013
|
|
|
/** |
1014
|
|
|
* Creates promise to list directories and files under specified path. |
1015
|
|
|
* |
1016
|
|
|
* @param string $share The share that |
1017
|
|
|
* contains all the |
1018
|
|
|
* files and directories. |
1019
|
|
|
* @param string $path The path to be listed. |
1020
|
|
|
* @param ListDirectoriesAndFilesOptions|null $options Optional parameters. |
1021
|
|
|
* |
1022
|
|
|
* @return \GuzzleHttp\Promise\PromiseInterface |
1023
|
|
|
* |
1024
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/list-directories-and-files |
1025
|
|
|
*/ |
1026
|
|
|
public function listDirectoriesAndFilesAsync( |
1027
|
|
|
$share, |
1028
|
|
|
$path = '', |
1029
|
|
|
ListDirectoriesAndFilesOptions $options = null |
1030
|
|
|
) { |
1031
|
|
|
Validate::isString($share, 'share'); |
1032
|
|
|
Validate::isString($path, 'path'); |
1033
|
|
|
|
1034
|
|
|
$method = Resources::HTTP_GET; |
1035
|
|
|
$headers = array(); |
1036
|
|
|
$postParams = array(); |
1037
|
|
|
$queryParams = array(); |
1038
|
|
|
$path = $this->createPath($share, $path); |
1039
|
|
|
|
1040
|
|
|
if (is_null($options)) { |
1041
|
|
|
$options = new ListDirectoriesAndFilesOptions(); |
1042
|
|
|
} |
1043
|
|
|
|
1044
|
|
|
$this->addOptionalQueryParam( |
1045
|
|
|
$queryParams, |
1046
|
|
|
Resources::QP_REST_TYPE, |
1047
|
|
|
'directory' |
1048
|
|
|
); |
1049
|
|
|
$this->addOptionalQueryParam( |
1050
|
|
|
$queryParams, |
1051
|
|
|
Resources::QP_COMP, |
1052
|
|
|
'list' |
1053
|
|
|
); |
1054
|
|
|
//Not available until 2016-05-31 |
1055
|
|
|
// $this->addOptionalQueryParam( |
1056
|
|
|
// $queryParams, |
1057
|
|
|
// Resources::QP_PREFIX, |
1058
|
|
|
// str_replace('\\', '/', $options->getPrefix()) |
1059
|
|
|
// ); |
1060
|
|
|
$this->addOptionalQueryParam( |
1061
|
|
|
$queryParams, |
1062
|
|
|
Resources::QP_MARKER, |
1063
|
|
|
$options->getNextMarker() |
1064
|
|
|
); |
1065
|
|
|
$this->addOptionalQueryParam( |
1066
|
|
|
$queryParams, |
1067
|
|
|
Resources::QP_MAX_RESULTS, |
1068
|
|
|
$options->getMaxResults() |
1069
|
|
|
); |
1070
|
|
|
|
1071
|
|
|
$this->addOptionalQueryParam( |
1072
|
|
|
$queryParams, |
1073
|
|
|
Resources::QP_TIMEOUT, |
1074
|
|
|
$options->getTimeout() |
1075
|
|
|
); |
1076
|
|
|
|
1077
|
|
|
$dataSerializer = $this->dataSerializer; |
1078
|
|
|
|
1079
|
|
|
return $this->sendAsync( |
1080
|
|
|
$method, |
1081
|
|
|
$headers, |
1082
|
|
|
$queryParams, |
1083
|
|
|
$postParams, |
1084
|
|
|
$path, |
1085
|
|
|
Resources::STATUS_OK, |
1086
|
|
|
Resources::EMPTY_STRING, |
1087
|
|
|
$options |
1088
|
|
View Code Duplication |
)->then(function ($response) use ($dataSerializer) { |
|
|
|
|
1089
|
|
|
$parsed = $dataSerializer->unserialize($response->getBody()); |
1090
|
|
|
return ListDirectoriesAndFilesResult::create( |
1091
|
|
|
$parsed, |
1092
|
|
|
Utilities::getLocationFromHeaders($response->getHeaders()) |
1093
|
|
|
); |
1094
|
|
|
}, null); |
1095
|
|
|
} |
1096
|
|
|
|
1097
|
|
|
/** |
1098
|
|
|
* Creates a new directory in the given share and path. |
1099
|
|
|
* |
1100
|
|
|
* @param string $share The share name. |
1101
|
|
|
* @param string $path The path to create the directory. |
1102
|
|
|
* @param CreateDirectoryOptions|null $options The optional parameters. |
1103
|
|
|
* |
1104
|
|
|
* @return void |
1105
|
|
|
* |
1106
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/create-directory |
1107
|
|
|
*/ |
1108
|
|
|
public function createDirectory( |
1109
|
|
|
$share, |
1110
|
|
|
$path, |
1111
|
|
|
CreateDirectoryOptions $options = null |
1112
|
|
|
) { |
1113
|
|
|
$this->createDirectoryAsync($share, $path, $options)->wait(); |
1114
|
|
|
} |
1115
|
|
|
|
1116
|
|
|
/** |
1117
|
|
|
* Creates a promise to create a new directory in the given share and path. |
1118
|
|
|
* |
1119
|
|
|
* @param string $share The share name. |
1120
|
|
|
* @param string $path The path to create the directory. |
1121
|
|
|
* @param CreateDirectoryOptions|null $options The optional parameters. |
1122
|
|
|
* |
1123
|
|
|
* @return \GuzzleHttp\Promise\PromiseInterface |
1124
|
|
|
* |
1125
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/create-directory |
1126
|
|
|
*/ |
1127
|
|
|
public function createDirectoryAsync( |
1128
|
|
|
$share, |
1129
|
|
|
$path, |
1130
|
|
|
CreateDirectoryOptions $options = null |
1131
|
|
|
) { |
1132
|
|
|
Validate::isString($share, 'share'); |
1133
|
|
|
Validate::isString($path, 'path'); |
1134
|
|
|
Validate::notNullOrEmpty($path, 'path'); |
1135
|
|
|
|
1136
|
|
|
$method = Resources::HTTP_PUT; |
1137
|
|
|
$headers = array(); |
|
|
|
|
1138
|
|
|
$postParams = array(); |
1139
|
|
|
$queryParams = array(Resources::QP_REST_TYPE => 'directory'); |
1140
|
|
|
$path = $this->createPath($share, $path); |
1141
|
|
|
|
1142
|
|
|
if (is_null($options)) { |
1143
|
|
|
$options = new CreateDirectoryOptions(); |
1144
|
|
|
} |
1145
|
|
|
|
1146
|
|
|
$this->addOptionalQueryParam( |
1147
|
|
|
$queryParams, |
1148
|
|
|
Resources::QP_TIMEOUT, |
1149
|
|
|
$options->getTimeout() |
1150
|
|
|
); |
1151
|
|
|
|
1152
|
|
|
$metadata = $options->getMetadata(); |
1153
|
|
|
$headers = $this->generateMetadataHeaders($metadata); |
1154
|
|
|
|
1155
|
|
|
return $this->sendAsync( |
1156
|
|
|
$method, |
1157
|
|
|
$headers, |
1158
|
|
|
$queryParams, |
1159
|
|
|
$postParams, |
1160
|
|
|
$path, |
1161
|
|
|
Resources::STATUS_CREATED, |
1162
|
|
|
Resources::EMPTY_STRING, |
1163
|
|
|
$options |
1164
|
|
|
); |
1165
|
|
|
} |
1166
|
|
|
|
1167
|
|
|
/** |
1168
|
|
|
* Deletes a directory in the given share and path. |
1169
|
|
|
* |
1170
|
|
|
* @param string $share The share name. |
1171
|
|
|
* @param string $path The path to delete the directory. |
1172
|
|
|
* @param FileServiceOptions|null $options The optional parameters. |
1173
|
|
|
* |
1174
|
|
|
* @return void |
1175
|
|
|
* |
1176
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/delete-directory |
1177
|
|
|
*/ |
1178
|
|
|
public function deleteDirectory( |
1179
|
|
|
$share, |
1180
|
|
|
$path, |
1181
|
|
|
FileServiceOptions $options = null |
1182
|
|
|
) { |
1183
|
|
|
$this->deleteDirectoryAsync($share, $path, $options)->wait(); |
1184
|
|
|
} |
1185
|
|
|
|
1186
|
|
|
/** |
1187
|
|
|
* Creates a promise to delete a new directory in the given share and path. |
1188
|
|
|
* |
1189
|
|
|
* @param string $share The share name. |
1190
|
|
|
* @param string $path The path to delete the directory. |
1191
|
|
|
* @param FileServiceOptions|null $options The optional parameters. |
1192
|
|
|
* |
1193
|
|
|
* @return \GuzzleHttp\Promise\PromiseInterface |
1194
|
|
|
* |
1195
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/delete-directory |
1196
|
|
|
*/ |
1197
|
|
View Code Duplication |
public function deleteDirectoryAsync( |
|
|
|
|
1198
|
|
|
$share, |
1199
|
|
|
$path, |
1200
|
|
|
FileServiceOptions $options = null |
1201
|
|
|
) { |
1202
|
|
|
Validate::isString($share, 'share'); |
1203
|
|
|
Validate::isString($path, 'path'); |
1204
|
|
|
|
1205
|
|
|
$method = Resources::HTTP_DELETE; |
1206
|
|
|
$headers = array(); |
1207
|
|
|
$postParams = array(); |
1208
|
|
|
$queryParams = array(Resources::QP_REST_TYPE => 'directory'); |
1209
|
|
|
$path = $this->createPath($share, $path); |
1210
|
|
|
|
1211
|
|
|
if (is_null($options)) { |
1212
|
|
|
$options = new FileServiceOptions(); |
1213
|
|
|
} |
1214
|
|
|
|
1215
|
|
|
$this->addOptionalQueryParam( |
1216
|
|
|
$queryParams, |
1217
|
|
|
Resources::QP_TIMEOUT, |
1218
|
|
|
$options->getTimeout() |
1219
|
|
|
); |
1220
|
|
|
|
1221
|
|
|
return $this->sendAsync( |
1222
|
|
|
$method, |
1223
|
|
|
$headers, |
1224
|
|
|
$queryParams, |
1225
|
|
|
$postParams, |
1226
|
|
|
$path, |
1227
|
|
|
Resources::STATUS_ACCEPTED, |
1228
|
|
|
Resources::EMPTY_STRING, |
1229
|
|
|
$options |
1230
|
|
|
); |
1231
|
|
|
} |
1232
|
|
|
|
1233
|
|
|
/** |
1234
|
|
|
* Gets a directory's properties from the given share and path. |
1235
|
|
|
* |
1236
|
|
|
* @param string $share The share name. |
1237
|
|
|
* @param string $path The path of the directory. |
1238
|
|
|
* @param FileServiceOptions|null $options The optional parameters. |
1239
|
|
|
* |
1240
|
|
|
* @return GetDirectoryPropertiesResult |
1241
|
|
|
* |
1242
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/get-directory-properties |
1243
|
|
|
*/ |
1244
|
|
|
public function getDirectoryProperties( |
1245
|
|
|
$share, |
1246
|
|
|
$path, |
1247
|
|
|
FileServiceOptions $options = null |
1248
|
|
|
) { |
1249
|
|
|
return $this->getDirectoryPropertiesAsync($share, $path, $options)->wait(); |
1250
|
|
|
} |
1251
|
|
|
|
1252
|
|
|
/** |
1253
|
|
|
* Creates promise to get a directory's properties from the given share |
1254
|
|
|
* and path. |
1255
|
|
|
* |
1256
|
|
|
* @param string $share The share name. |
1257
|
|
|
* @param string $path The path of the directory. |
1258
|
|
|
* @param FileServiceOptions|null $options The optional parameters. |
1259
|
|
|
* |
1260
|
|
|
* @return \GuzzleHttp\Promise\PromiseInterface |
1261
|
|
|
* |
1262
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/get-directory-properties |
1263
|
|
|
*/ |
1264
|
|
View Code Duplication |
public function getDirectoryPropertiesAsync( |
|
|
|
|
1265
|
|
|
$share, |
1266
|
|
|
$path, |
1267
|
|
|
FileServiceOptions $options = null |
1268
|
|
|
) { |
1269
|
|
|
Validate::isString($share, 'share'); |
1270
|
|
|
Validate::isString($path, 'path'); |
1271
|
|
|
|
1272
|
|
|
$method = Resources::HTTP_GET; |
1273
|
|
|
$headers = array(); |
1274
|
|
|
$postParams = array(); |
1275
|
|
|
$queryParams = array(Resources::QP_REST_TYPE => 'directory'); |
1276
|
|
|
$path = $this->createPath($share, $path); |
1277
|
|
|
|
1278
|
|
|
if (is_null($options)) { |
1279
|
|
|
$options = new FileServiceOptions(); |
1280
|
|
|
} |
1281
|
|
|
|
1282
|
|
|
$this->addOptionalQueryParam( |
1283
|
|
|
$queryParams, |
1284
|
|
|
Resources::QP_TIMEOUT, |
1285
|
|
|
$options->getTimeout() |
1286
|
|
|
); |
1287
|
|
|
|
1288
|
|
|
return $this->sendAsync( |
1289
|
|
|
$method, |
1290
|
|
|
$headers, |
1291
|
|
|
$queryParams, |
1292
|
|
|
$postParams, |
1293
|
|
|
$path, |
1294
|
|
|
Resources::STATUS_OK, |
1295
|
|
|
Resources::EMPTY_STRING, |
1296
|
|
|
$options |
1297
|
|
|
)->then(function ($response) { |
1298
|
|
|
$parsed = HttpFormatter::formatHeaders($response->getHeaders()); |
1299
|
|
|
return GetDirectoryPropertiesResult::create($parsed); |
1300
|
|
|
}, null); |
1301
|
|
|
} |
1302
|
|
|
|
1303
|
|
|
/** |
1304
|
|
|
* Gets a directory's metadata from the given share and path. |
1305
|
|
|
* |
1306
|
|
|
* @param string $share The share name. |
1307
|
|
|
* @param string $path The path of the directory. |
1308
|
|
|
* @param FileServiceOptions|null $options The optional parameters. |
1309
|
|
|
* |
1310
|
|
|
* @return GetDirectoryMetadataResult |
1311
|
|
|
* |
1312
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/get-directory-metadata |
1313
|
|
|
*/ |
1314
|
|
|
public function getDirectoryMetadata( |
1315
|
|
|
$share, |
1316
|
|
|
$path, |
1317
|
|
|
FileServiceOptions $options = null |
1318
|
|
|
) { |
1319
|
|
|
return $this->getDirectoryMetadataAsync($share, $path, $options)->wait(); |
1320
|
|
|
} |
1321
|
|
|
|
1322
|
|
|
/** |
1323
|
|
|
* Creates promise to get a directory's metadata from the given share |
1324
|
|
|
* and path. |
1325
|
|
|
* |
1326
|
|
|
* @param string $share The share name. |
1327
|
|
|
* @param string $path The path of the directory. |
1328
|
|
|
* @param FileServiceOptions|null $options The optional parameters. |
1329
|
|
|
* |
1330
|
|
|
* @return \GuzzleHttp\Promise\PromiseInterface |
1331
|
|
|
* |
1332
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/get-directory-metadata |
1333
|
|
|
*/ |
1334
|
|
View Code Duplication |
public function getDirectoryMetadataAsync( |
|
|
|
|
1335
|
|
|
$share, |
1336
|
|
|
$path, |
1337
|
|
|
FileServiceOptions $options = null |
1338
|
|
|
) { |
1339
|
|
|
Validate::isString($share, 'share'); |
1340
|
|
|
Validate::isString($path, 'path'); |
1341
|
|
|
|
1342
|
|
|
$method = Resources::HTTP_GET; |
1343
|
|
|
$headers = array(); |
1344
|
|
|
$postParams = array(); |
1345
|
|
|
$queryParams = array(Resources::QP_REST_TYPE => 'directory'); |
1346
|
|
|
$path = $this->createPath($share, $path); |
1347
|
|
|
|
1348
|
|
|
if (is_null($options)) { |
1349
|
|
|
$options = new FileServiceOptions(); |
1350
|
|
|
} |
1351
|
|
|
|
1352
|
|
|
$this->addOptionalQueryParam( |
1353
|
|
|
$queryParams, |
1354
|
|
|
Resources::QP_COMP, |
1355
|
|
|
'metadata' |
1356
|
|
|
); |
1357
|
|
|
|
1358
|
|
|
$this->addOptionalQueryParam( |
1359
|
|
|
$queryParams, |
1360
|
|
|
Resources::QP_TIMEOUT, |
1361
|
|
|
$options->getTimeout() |
1362
|
|
|
); |
1363
|
|
|
|
1364
|
|
|
return $this->sendAsync( |
1365
|
|
|
$method, |
1366
|
|
|
$headers, |
1367
|
|
|
$queryParams, |
1368
|
|
|
$postParams, |
1369
|
|
|
$path, |
1370
|
|
|
Resources::STATUS_OK, |
1371
|
|
|
Resources::EMPTY_STRING, |
1372
|
|
|
$options |
1373
|
|
|
)->then(function ($response) { |
1374
|
|
|
$parsed = HttpFormatter::formatHeaders($response->getHeaders()); |
1375
|
|
|
return GetDirectoryMetadataResult::create($parsed); |
1376
|
|
|
}, null); |
1377
|
|
|
} |
1378
|
|
|
|
1379
|
|
|
/** |
1380
|
|
|
* Sets a directory's metadata from the given share and path. |
1381
|
|
|
* |
1382
|
|
|
* @param string $share The share name. |
1383
|
|
|
* @param string $path The path to delete the directory. |
1384
|
|
|
* @param array $metadata The metadata to be set. |
1385
|
|
|
* @param FileServiceOptions|null $options The optional parameters. |
1386
|
|
|
* |
1387
|
|
|
* @return void |
1388
|
|
|
* |
1389
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/set-directory-metadata |
1390
|
|
|
*/ |
1391
|
|
|
public function setDirectoryMetadata( |
1392
|
|
|
$share, |
1393
|
|
|
$path, |
1394
|
|
|
array $metadata, |
1395
|
|
|
FileServiceOptions $options = null |
1396
|
|
|
) { |
1397
|
|
|
return $this->setDirectoryMetadataAsync( |
1398
|
|
|
$share, |
1399
|
|
|
$path, |
1400
|
|
|
$metadata, |
1401
|
|
|
$options |
1402
|
|
|
)->wait(); |
1403
|
|
|
} |
1404
|
|
|
|
1405
|
|
|
/** |
1406
|
|
|
* Creates promise to set a directory's metadata from the given share |
1407
|
|
|
* and path. |
1408
|
|
|
* |
1409
|
|
|
* @param string $share The share name. |
1410
|
|
|
* @param string $path The path to delete the directory. |
1411
|
|
|
* @param array $metadata The metadata to be set. |
1412
|
|
|
* @param FileServiceOptions|null $options The optional parameters. |
1413
|
|
|
* |
1414
|
|
|
* @return \GuzzleHttp\Promise\PromiseInterface |
1415
|
|
|
* |
1416
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/set-directory-metadata |
1417
|
|
|
*/ |
1418
|
|
View Code Duplication |
public function setDirectoryMetadataAsync( |
|
|
|
|
1419
|
|
|
$share, |
1420
|
|
|
$path, |
1421
|
|
|
array $metadata, |
1422
|
|
|
FileServiceOptions $options = null |
1423
|
|
|
) { |
1424
|
|
|
Validate::isString($share, 'share'); |
1425
|
|
|
Validate::isString($path, 'path'); |
1426
|
|
|
|
1427
|
|
|
$method = Resources::HTTP_PUT; |
1428
|
|
|
$postParams = array(); |
1429
|
|
|
$queryParams = array(Resources::QP_REST_TYPE => 'directory'); |
1430
|
|
|
$path = $this->createPath($share, $path); |
1431
|
|
|
|
1432
|
|
|
Utilities::validateMetadata($metadata); |
1433
|
|
|
$headers = $this->generateMetadataHeaders($metadata); |
1434
|
|
|
if (is_null($options)) { |
1435
|
|
|
$options = new FileServiceOptions(); |
1436
|
|
|
} |
1437
|
|
|
|
1438
|
|
|
$this->addOptionalQueryParam( |
1439
|
|
|
$queryParams, |
1440
|
|
|
Resources::QP_COMP, |
1441
|
|
|
'metadata' |
1442
|
|
|
); |
1443
|
|
|
|
1444
|
|
|
$this->addOptionalQueryParam( |
1445
|
|
|
$queryParams, |
1446
|
|
|
Resources::QP_TIMEOUT, |
1447
|
|
|
$options->getTimeout() |
1448
|
|
|
); |
1449
|
|
|
|
1450
|
|
|
return $this->sendAsync( |
1451
|
|
|
$method, |
1452
|
|
|
$headers, |
1453
|
|
|
$queryParams, |
1454
|
|
|
$postParams, |
1455
|
|
|
$path, |
1456
|
|
|
Resources::STATUS_OK, |
1457
|
|
|
Resources::EMPTY_STRING, |
1458
|
|
|
$options |
1459
|
|
|
); |
1460
|
|
|
} |
1461
|
|
|
|
1462
|
|
|
/** |
1463
|
|
|
* Create a new file. |
1464
|
|
|
* |
1465
|
|
|
* @param string $share The share name. |
1466
|
|
|
* @param string $path The path and name of the file. |
1467
|
|
|
* @param int $size The size of the file. |
1468
|
|
|
* @param CreateFileOptions|null $options The optional parameters. |
1469
|
|
|
* |
1470
|
|
|
* @return void |
1471
|
|
|
* |
1472
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/create-file |
1473
|
|
|
*/ |
1474
|
|
|
public function createFile( |
1475
|
|
|
$share, |
1476
|
|
|
$path, |
1477
|
|
|
$size, |
1478
|
|
|
CreateFileOptions $options = null |
1479
|
|
|
) { |
1480
|
|
|
return $this->createFileAsync( |
1481
|
|
|
$share, |
1482
|
|
|
$path, |
1483
|
|
|
$size, |
1484
|
|
|
$options |
1485
|
|
|
)->wait(); |
1486
|
|
|
} |
1487
|
|
|
|
1488
|
|
|
/** |
1489
|
|
|
* Creates promise to create a new file. |
1490
|
|
|
* |
1491
|
|
|
* @param string $share The share name. |
1492
|
|
|
* @param string $path The path and name of the file. |
1493
|
|
|
* @param int $size The size of the file. |
1494
|
|
|
* @param CreateFileOptions|null $options The optional parameters. |
1495
|
|
|
* |
1496
|
|
|
* @return \GuzzleHttp\Promise\PromiseInterface |
1497
|
|
|
* |
1498
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/create-file |
1499
|
|
|
*/ |
1500
|
|
|
public function createFileAsync( |
1501
|
|
|
$share, |
1502
|
|
|
$path, |
1503
|
|
|
$size, |
1504
|
|
|
CreateFileOptions $options = null |
1505
|
|
|
) { |
1506
|
|
|
Validate::isString($share, 'share'); |
1507
|
|
|
Validate::notNullOrEmpty($share, 'share'); |
1508
|
|
|
Validate::isString($path, 'path'); |
1509
|
|
|
Validate::notNullOrEmpty($path, 'path'); |
1510
|
|
|
Validate::isInteger($size, 'size'); |
1511
|
|
|
|
1512
|
|
|
$method = Resources::HTTP_PUT; |
1513
|
|
|
$headers = array(); |
|
|
|
|
1514
|
|
|
$postParams = array(); |
1515
|
|
|
$queryParams = array(); |
1516
|
|
|
$path = $this->createPath($share, $path); |
1517
|
|
|
|
1518
|
|
|
if (is_null($options)) { |
1519
|
|
|
$options = new CreateFileOptions(); |
1520
|
|
|
} |
1521
|
|
|
|
1522
|
|
|
Utilities::validateMetadata($options->getMetadata()); |
1523
|
|
|
$headers = $this->generateMetadataHeaders($options->getMetadata()); |
1524
|
|
|
|
1525
|
|
|
$this->addOptionalHeader( |
1526
|
|
|
$headers, |
1527
|
|
|
Resources::X_MS_TYPE, |
1528
|
|
|
'file' |
1529
|
|
|
); |
1530
|
|
|
|
1531
|
|
|
$this->addOptionalQueryParam( |
1532
|
|
|
$queryParams, |
1533
|
|
|
Resources::QP_TIMEOUT, |
1534
|
|
|
$options->getTimeout() |
1535
|
|
|
); |
1536
|
|
|
|
1537
|
|
|
$this->addOptionalHeader( |
1538
|
|
|
$headers, |
1539
|
|
|
Resources::X_MS_CONTENT_LENGTH, |
1540
|
|
|
$size |
1541
|
|
|
); |
1542
|
|
|
|
1543
|
|
|
$this->addOptionalHeader( |
1544
|
|
|
$headers, |
1545
|
|
|
Resources::CONTENT_TYPE, |
1546
|
|
|
$options->getContentType() |
1547
|
|
|
); |
1548
|
|
|
|
1549
|
|
|
$this->addOptionalHeader( |
1550
|
|
|
$headers, |
1551
|
|
|
Resources::CONTENT_ENCODING, |
1552
|
|
|
$options->getContentEncoding() |
1553
|
|
|
); |
1554
|
|
|
|
1555
|
|
|
$this->addOptionalHeader( |
1556
|
|
|
$headers, |
1557
|
|
|
Resources::CONTENT_LANGUAGE, |
1558
|
|
|
$options->getContentLanguage() |
1559
|
|
|
); |
1560
|
|
|
|
1561
|
|
|
$this->addOptionalHeader( |
1562
|
|
|
$headers, |
1563
|
|
|
Resources::CACHE_CONTROL, |
1564
|
|
|
$options->getCacheControl() |
1565
|
|
|
); |
1566
|
|
|
|
1567
|
|
|
$this->addOptionalHeader( |
1568
|
|
|
$headers, |
1569
|
|
|
Resources::CONTENT_MD5, |
1570
|
|
|
$options->getContentMD5() |
1571
|
|
|
); |
1572
|
|
|
|
1573
|
|
|
$this->addOptionalHeader( |
1574
|
|
|
$headers, |
1575
|
|
|
Resources::CONTENT_DISPOSITION, |
1576
|
|
|
$options->getContentDisposition() |
1577
|
|
|
); |
1578
|
|
|
|
1579
|
|
|
$this->addOptionalHeader( |
1580
|
|
|
$headers, |
1581
|
|
|
Resources::CONTENT_DISPOSITION, |
1582
|
|
|
$options->getContentDisposition() |
1583
|
|
|
); |
1584
|
|
|
|
1585
|
|
|
return $this->sendAsync( |
1586
|
|
|
$method, |
1587
|
|
|
$headers, |
1588
|
|
|
$queryParams, |
1589
|
|
|
$postParams, |
1590
|
|
|
$path, |
1591
|
|
|
Resources::STATUS_CREATED, |
1592
|
|
|
Resources::EMPTY_STRING, |
1593
|
|
|
$options |
1594
|
|
|
); |
1595
|
|
|
} |
1596
|
|
|
|
1597
|
|
|
/** |
1598
|
|
|
* Deletes a file in the given share and path. |
1599
|
|
|
* |
1600
|
|
|
* @param string $share The share name. |
1601
|
|
|
* @param string $path The path to delete the file. |
1602
|
|
|
* @param FileServiceOptions|null $options The optional parameters. |
1603
|
|
|
* |
1604
|
|
|
* @return void |
1605
|
|
|
* |
1606
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/delete-file2 |
1607
|
|
|
*/ |
1608
|
|
|
public function deleteFile( |
1609
|
|
|
$share, |
1610
|
|
|
$path, |
1611
|
|
|
FileServiceOptions $options = null |
1612
|
|
|
) { |
1613
|
|
|
$this->deleteFileAsync($share, $path, $options)->wait(); |
1614
|
|
|
} |
1615
|
|
|
|
1616
|
|
|
/** |
1617
|
|
|
* Creates a promise to delete a new file in the given share and path. |
1618
|
|
|
* |
1619
|
|
|
* @param string $share The share name. |
1620
|
|
|
* @param string $path The path to delete the file. |
1621
|
|
|
* @param FileServiceOptions|null $options The optional parameters. |
1622
|
|
|
* |
1623
|
|
|
* @return \GuzzleHttp\Promise\PromiseInterface |
1624
|
|
|
* |
1625
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/delete-file2 |
1626
|
|
|
*/ |
1627
|
|
View Code Duplication |
public function deleteFileAsync( |
|
|
|
|
1628
|
|
|
$share, |
1629
|
|
|
$path, |
1630
|
|
|
FileServiceOptions $options = null |
1631
|
|
|
) { |
1632
|
|
|
Validate::isString($share, 'share'); |
1633
|
|
|
Validate::isString($path, 'path'); |
1634
|
|
|
|
1635
|
|
|
$method = Resources::HTTP_DELETE; |
1636
|
|
|
$headers = array(); |
1637
|
|
|
$postParams = array(); |
1638
|
|
|
$queryParams = array(); |
1639
|
|
|
$path = $this->createPath($share, $path); |
1640
|
|
|
|
1641
|
|
|
if (is_null($options)) { |
1642
|
|
|
$options = new FileServiceOptions(); |
1643
|
|
|
} |
1644
|
|
|
|
1645
|
|
|
$this->addOptionalQueryParam( |
1646
|
|
|
$queryParams, |
1647
|
|
|
Resources::QP_TIMEOUT, |
1648
|
|
|
$options->getTimeout() |
1649
|
|
|
); |
1650
|
|
|
|
1651
|
|
|
return $this->sendAsync( |
1652
|
|
|
$method, |
1653
|
|
|
$headers, |
1654
|
|
|
$queryParams, |
1655
|
|
|
$postParams, |
1656
|
|
|
$path, |
1657
|
|
|
Resources::STATUS_ACCEPTED, |
1658
|
|
|
Resources::EMPTY_STRING, |
1659
|
|
|
$options |
1660
|
|
|
); |
1661
|
|
|
} |
1662
|
|
|
|
1663
|
|
|
/** |
1664
|
|
|
* Reads or downloads a file from the server, including its metadata and |
1665
|
|
|
* properties. |
1666
|
|
|
* |
1667
|
|
|
* @param string $share name of the share |
1668
|
|
|
* @param string $path path of the file to be get |
1669
|
|
|
* @param GetFileOptions|null $options optional parameters |
1670
|
|
|
* |
1671
|
|
|
* @return GetFileResult |
1672
|
|
|
* |
1673
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/get-file |
1674
|
|
|
*/ |
1675
|
|
|
public function getFile( |
1676
|
|
|
$share, |
1677
|
|
|
$path, |
1678
|
|
|
GetFileOptions $options = null |
1679
|
|
|
) { |
1680
|
|
|
return $this->getFileAsync($share, $path, $options)->wait(); |
1681
|
|
|
} |
1682
|
|
|
|
1683
|
|
|
/** |
1684
|
|
|
* Creates promise to read or download a file from the server, including its |
1685
|
|
|
* metadata and properties. |
1686
|
|
|
* |
1687
|
|
|
* @param string $share name of the share |
1688
|
|
|
* @param string $path path of the file to be get |
1689
|
|
|
* @param GetFileOptions|null $options optional parameters |
1690
|
|
|
* |
1691
|
|
|
* @return \GuzzleHttp\Promise\PromiseInterface |
1692
|
|
|
* |
1693
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/get-file |
1694
|
|
|
*/ |
1695
|
|
|
public function getFileAsync( |
1696
|
|
|
$share, |
1697
|
|
|
$path, |
1698
|
|
|
GetFileOptions $options = null |
1699
|
|
|
) { |
1700
|
|
|
Validate::isString($share, 'share'); |
1701
|
|
|
Validate::isString($path, 'path'); |
1702
|
|
|
|
1703
|
|
|
$method = Resources::HTTP_GET; |
1704
|
|
|
$headers = array(); |
1705
|
|
|
$postParams = array(); |
1706
|
|
|
$queryParams = array(); |
1707
|
|
|
$path = $this->createPath($share, $path); |
1708
|
|
|
|
1709
|
|
|
if (is_null($options)) { |
1710
|
|
|
$options = new GetFileOptions(); |
1711
|
|
|
} |
1712
|
|
|
|
1713
|
|
|
$this->addOptionalQueryParam( |
1714
|
|
|
$queryParams, |
1715
|
|
|
Resources::QP_TIMEOUT, |
1716
|
|
|
$options->getTimeout() |
1717
|
|
|
); |
1718
|
|
|
|
1719
|
|
|
$this->addOptionalHeader( |
1720
|
|
|
$headers, |
1721
|
|
|
Resources::X_MS_RANGE, |
1722
|
|
|
$options->getRangeString() == '' ? null : $options->getRangeString() |
1723
|
|
|
); |
1724
|
|
|
$this->addOptionalHeader( |
1725
|
|
|
$headers, |
1726
|
|
|
Resources::X_MS_RANGE_GET_CONTENT_MD5, |
1727
|
|
|
$options->getRangeGetContentMD5() ? 'true' : null |
1728
|
|
|
); |
1729
|
|
|
|
1730
|
|
|
$options->setIsStreaming(true); |
1731
|
|
|
|
1732
|
|
|
return $this->sendAsync( |
1733
|
|
|
$method, |
1734
|
|
|
$headers, |
1735
|
|
|
$queryParams, |
1736
|
|
|
$postParams, |
1737
|
|
|
$path, |
1738
|
|
|
array(Resources::STATUS_OK, Resources::STATUS_PARTIAL_CONTENT), |
1739
|
|
|
Resources::EMPTY_STRING, |
1740
|
|
|
$options |
1741
|
|
View Code Duplication |
)->then(function ($response) { |
|
|
|
|
1742
|
|
|
$metadata = Utilities::getMetadataArray( |
1743
|
|
|
HttpFormatter::formatHeaders($response->getHeaders()) |
1744
|
|
|
); |
1745
|
|
|
|
1746
|
|
|
return GetFileResult::create( |
1747
|
|
|
HttpFormatter::formatHeaders($response->getHeaders()), |
1748
|
|
|
$response->getBody(), |
1749
|
|
|
$metadata |
1750
|
|
|
); |
1751
|
|
|
}); |
1752
|
|
|
} |
1753
|
|
|
|
1754
|
|
|
/** |
1755
|
|
|
* Gets a file's properties from the given share and path. |
1756
|
|
|
* |
1757
|
|
|
* @param string $share The share name. |
1758
|
|
|
* @param string $path The path to delete the file. |
1759
|
|
|
* @param FileServiceOptions|null $options The optional parameters. |
1760
|
|
|
* |
1761
|
|
|
* @return FileProperties |
1762
|
|
|
* |
1763
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/get-file-properties |
1764
|
|
|
*/ |
1765
|
|
|
public function getFileProperties( |
1766
|
|
|
$share, |
1767
|
|
|
$path, |
1768
|
|
|
FileServiceOptions $options = null |
1769
|
|
|
) { |
1770
|
|
|
return $this->getFilePropertiesAsync($share, $path, $options)->wait(); |
1771
|
|
|
} |
1772
|
|
|
|
1773
|
|
|
/** |
1774
|
|
|
* Creates promise to get a file's properties from the given share |
1775
|
|
|
* and path. |
1776
|
|
|
* |
1777
|
|
|
* @param string $share The share name. |
1778
|
|
|
* @param string $path The path to delete the file. |
1779
|
|
|
* @param FileServiceOptions|null $options The optional parameters. |
1780
|
|
|
* |
1781
|
|
|
* @return \GuzzleHttp\Promise\PromiseInterface |
1782
|
|
|
* |
1783
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/get-file-properties |
1784
|
|
|
*/ |
1785
|
|
View Code Duplication |
public function getFilePropertiesAsync( |
|
|
|
|
1786
|
|
|
$share, |
1787
|
|
|
$path, |
1788
|
|
|
FileServiceOptions $options = null |
1789
|
|
|
) { |
1790
|
|
|
Validate::isString($share, 'share'); |
1791
|
|
|
Validate::isString($path, 'path'); |
1792
|
|
|
|
1793
|
|
|
$method = Resources::HTTP_HEAD; |
1794
|
|
|
$headers = array(); |
1795
|
|
|
$queryParams = array(); |
1796
|
|
|
$postParams = array(); |
1797
|
|
|
$path = $this->createPath($share, $path); |
1798
|
|
|
|
1799
|
|
|
if (is_null($options)) { |
1800
|
|
|
$options = new FileServiceOptions(); |
1801
|
|
|
} |
1802
|
|
|
|
1803
|
|
|
$this->addOptionalQueryParam( |
1804
|
|
|
$queryParams, |
1805
|
|
|
Resources::QP_TIMEOUT, |
1806
|
|
|
$options->getTimeout() |
1807
|
|
|
); |
1808
|
|
|
|
1809
|
|
|
return $this->sendAsync( |
1810
|
|
|
$method, |
1811
|
|
|
$headers, |
1812
|
|
|
$queryParams, |
1813
|
|
|
$postParams, |
1814
|
|
|
$path, |
1815
|
|
|
Resources::STATUS_OK, |
1816
|
|
|
Resources::EMPTY_STRING, |
1817
|
|
|
$options |
1818
|
|
|
)->then(function ($response) { |
1819
|
|
|
$parsed = HttpFormatter::formatHeaders($response->getHeaders()); |
1820
|
|
|
return FileProperties::createFromHttpHeaders($parsed); |
1821
|
|
|
}, null); |
1822
|
|
|
} |
1823
|
|
|
|
1824
|
|
|
/** |
1825
|
|
|
* Sets properties on the file. |
1826
|
|
|
* |
1827
|
|
|
* @param string $share share name |
1828
|
|
|
* @param string $path path of the file |
1829
|
|
|
* @param FileProperties $properties file properties. |
1830
|
|
|
* @param FileServiceOptions|null $options optional parameters |
1831
|
|
|
* |
1832
|
|
|
* @return void |
1833
|
|
|
* |
1834
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/set-file-properties |
1835
|
|
|
*/ |
1836
|
|
|
public function setFileProperties( |
1837
|
|
|
$share, |
1838
|
|
|
$path, |
1839
|
|
|
FileProperties $properties, |
1840
|
|
|
FileServiceOptions $options = null |
1841
|
|
|
) { |
1842
|
|
|
$this->setFilePropertiesAsync($share, $path, $properties, $options)->wait(); |
1843
|
|
|
} |
1844
|
|
|
|
1845
|
|
|
/** |
1846
|
|
|
* Creates promise to set properties on the file. |
1847
|
|
|
* |
1848
|
|
|
* @param string $share share name |
1849
|
|
|
* @param string $path path of the file |
1850
|
|
|
* @param FileProperties $properties file properties. |
1851
|
|
|
* @param FileServiceOptions|null $options optional parameters |
1852
|
|
|
* |
1853
|
|
|
* @return \GuzzleHttp\Promise\PromiseInterface |
1854
|
|
|
* |
1855
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/set-file-properties |
1856
|
|
|
*/ |
1857
|
|
|
public function setFilePropertiesAsync( |
1858
|
|
|
$share, |
1859
|
|
|
$path, |
1860
|
|
|
FileProperties $properties, |
1861
|
|
|
FileServiceOptions $options = null |
1862
|
|
|
) { |
1863
|
|
|
Validate::isString($share, 'share'); |
1864
|
|
|
Validate::isString($path, 'path'); |
1865
|
|
|
|
1866
|
|
|
$headers = array(); |
1867
|
|
|
|
1868
|
|
|
$method = Resources::HTTP_PUT; |
1869
|
|
|
$postParams = array(); |
1870
|
|
|
$queryParams = array(Resources::QP_COMP => 'properties'); |
1871
|
|
|
$path = $this->createPath($share, $path); |
1872
|
|
|
|
1873
|
|
|
if (is_null($options)) { |
1874
|
|
|
$options = new FileServiceOptions(); |
1875
|
|
|
} |
1876
|
|
|
|
1877
|
|
|
$this->addOptionalQueryParam( |
1878
|
|
|
$queryParams, |
1879
|
|
|
Resources::QP_TIMEOUT, |
1880
|
|
|
$options->getTimeout() |
1881
|
|
|
); |
1882
|
|
|
|
1883
|
|
|
$this->addOptionalHeader( |
1884
|
|
|
$headers, |
1885
|
|
|
Resources::X_MS_CACHE_CONTROL, |
1886
|
|
|
$properties->getCacheControl() |
1887
|
|
|
); |
1888
|
|
|
|
1889
|
|
|
$this->addOptionalHeader( |
1890
|
|
|
$headers, |
1891
|
|
|
Resources::X_MS_CONTENT_TYPE, |
1892
|
|
|
$properties->getContentType() |
1893
|
|
|
); |
1894
|
|
|
|
1895
|
|
|
$this->addOptionalHeader( |
1896
|
|
|
$headers, |
1897
|
|
|
Resources::X_MS_CONTENT_MD5, |
1898
|
|
|
$properties->getContentMD5() |
1899
|
|
|
); |
1900
|
|
|
|
1901
|
|
|
$this->addOptionalHeader( |
1902
|
|
|
$headers, |
1903
|
|
|
Resources::X_MS_CONTENT_ENCODING, |
1904
|
|
|
$properties->getContentEncoding() |
1905
|
|
|
); |
1906
|
|
|
|
1907
|
|
|
$this->addOptionalHeader( |
1908
|
|
|
$headers, |
1909
|
|
|
Resources::X_MS_CONTENT_LANGUAGE, |
1910
|
|
|
$properties->getContentLanguage() |
1911
|
|
|
); |
1912
|
|
|
|
1913
|
|
|
$this->addOptionalHeader( |
1914
|
|
|
$headers, |
1915
|
|
|
Resources::X_MS_CONTENT_DISPOSITION, |
1916
|
|
|
$properties->getContentDisposition() |
1917
|
|
|
); |
1918
|
|
|
|
1919
|
|
|
$this->addOptionalHeader( |
1920
|
|
|
$headers, |
1921
|
|
|
Resources::X_MS_CONTENT_LENGTH, |
1922
|
|
|
$properties->getContentLength() |
1923
|
|
|
); |
1924
|
|
|
|
1925
|
|
|
return $this->sendAsync( |
1926
|
|
|
$method, |
1927
|
|
|
$headers, |
1928
|
|
|
$queryParams, |
1929
|
|
|
$postParams, |
1930
|
|
|
$path, |
1931
|
|
|
Resources::STATUS_OK, |
1932
|
|
|
Resources::EMPTY_STRING, |
1933
|
|
|
$options |
1934
|
|
|
); |
1935
|
|
|
} |
1936
|
|
|
|
1937
|
|
|
/** |
1938
|
|
|
* Gets a file's metadata from the given share and path. |
1939
|
|
|
* |
1940
|
|
|
* @param string $share The share name. |
1941
|
|
|
* @param string $path The path of the file. |
1942
|
|
|
* @param FileServiceOptions|null $options The optional parameters. |
1943
|
|
|
* |
1944
|
|
|
* @return GetFileMetadataResult |
1945
|
|
|
* |
1946
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/get-file-metadata |
1947
|
|
|
*/ |
1948
|
|
|
public function getFileMetadata( |
1949
|
|
|
$share, |
1950
|
|
|
$path, |
1951
|
|
|
FileServiceOptions $options = null |
1952
|
|
|
) { |
1953
|
|
|
return $this->getFileMetadataAsync($share, $path, $options)->wait(); |
1954
|
|
|
} |
1955
|
|
|
|
1956
|
|
|
/** |
1957
|
|
|
* Creates promise to get a file's metadata from the given share |
1958
|
|
|
* and path. |
1959
|
|
|
* |
1960
|
|
|
* @param string $share The share name. |
1961
|
|
|
* @param string $path The path of the file. |
1962
|
|
|
* @param FileServiceOptions|null $options The optional parameters. |
1963
|
|
|
* |
1964
|
|
|
* @return \GuzzleHttp\Promise\PromiseInterface |
1965
|
|
|
* |
1966
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/get-file-metadata |
1967
|
|
|
*/ |
1968
|
|
View Code Duplication |
public function getFileMetadataAsync( |
|
|
|
|
1969
|
|
|
$share, |
1970
|
|
|
$path, |
1971
|
|
|
FileServiceOptions $options = null |
1972
|
|
|
) { |
1973
|
|
|
Validate::isString($share, 'share'); |
1974
|
|
|
Validate::isString($path, 'path'); |
1975
|
|
|
|
1976
|
|
|
$method = Resources::HTTP_GET; |
1977
|
|
|
$headers = array(); |
1978
|
|
|
$postParams = array(); |
1979
|
|
|
$queryParams = array(); |
1980
|
|
|
$path = $this->createPath($share, $path); |
1981
|
|
|
|
1982
|
|
|
if (is_null($options)) { |
1983
|
|
|
$options = new FileServiceOptions(); |
1984
|
|
|
} |
1985
|
|
|
|
1986
|
|
|
$this->addOptionalQueryParam( |
1987
|
|
|
$queryParams, |
1988
|
|
|
Resources::QP_COMP, |
1989
|
|
|
'metadata' |
1990
|
|
|
); |
1991
|
|
|
|
1992
|
|
|
$this->addOptionalQueryParam( |
1993
|
|
|
$queryParams, |
1994
|
|
|
Resources::QP_TIMEOUT, |
1995
|
|
|
$options->getTimeout() |
1996
|
|
|
); |
1997
|
|
|
|
1998
|
|
|
return $this->sendAsync( |
1999
|
|
|
$method, |
2000
|
|
|
$headers, |
2001
|
|
|
$queryParams, |
2002
|
|
|
$postParams, |
2003
|
|
|
$path, |
2004
|
|
|
Resources::STATUS_OK, |
2005
|
|
|
Resources::EMPTY_STRING, |
2006
|
|
|
$options |
2007
|
|
|
)->then(function ($response) { |
2008
|
|
|
$parsed = HttpFormatter::formatHeaders($response->getHeaders()); |
2009
|
|
|
return GetFileMetadataResult::create($parsed); |
2010
|
|
|
}, null); |
2011
|
|
|
} |
2012
|
|
|
|
2013
|
|
|
/** |
2014
|
|
|
* Sets a file's metadata from the given share and path. |
2015
|
|
|
* |
2016
|
|
|
* @param string $share The share name. |
2017
|
|
|
* @param string $path The path to delete the file. |
2018
|
|
|
* @param array $metadata The metadata to be set. |
2019
|
|
|
* @param FileServiceOptions|null $options The optional parameters. |
2020
|
|
|
* |
2021
|
|
|
* @return void |
2022
|
|
|
* |
2023
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/set-file-metadata |
2024
|
|
|
*/ |
2025
|
|
|
public function setFileMetadata( |
2026
|
|
|
$share, |
2027
|
|
|
$path, |
2028
|
|
|
array $metadata, |
2029
|
|
|
FileServiceOptions $options = null |
2030
|
|
|
) { |
2031
|
|
|
return $this->setFileMetadataAsync( |
2032
|
|
|
$share, |
2033
|
|
|
$path, |
2034
|
|
|
$metadata, |
2035
|
|
|
$options |
2036
|
|
|
)->wait(); |
2037
|
|
|
} |
2038
|
|
|
|
2039
|
|
|
/** |
2040
|
|
|
* Creates promise to set a file's metadata from the given share |
2041
|
|
|
* and path. |
2042
|
|
|
* |
2043
|
|
|
* @param string $share The share name. |
2044
|
|
|
* @param string $path The path to delete the file. |
2045
|
|
|
* @param array $metadata The metadata to be set. |
2046
|
|
|
* @param FileServiceOptions|null $options The optional parameters. |
2047
|
|
|
* |
2048
|
|
|
* @return \GuzzleHttp\Promise\PromiseInterface |
2049
|
|
|
* |
2050
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/set-file-metadata |
2051
|
|
|
*/ |
2052
|
|
View Code Duplication |
public function setFileMetadataAsync( |
|
|
|
|
2053
|
|
|
$share, |
2054
|
|
|
$path, |
2055
|
|
|
array $metadata, |
2056
|
|
|
FileServiceOptions $options = null |
2057
|
|
|
) { |
2058
|
|
|
Validate::isString($share, 'share'); |
2059
|
|
|
Validate::isString($path, 'path'); |
2060
|
|
|
|
2061
|
|
|
$method = Resources::HTTP_PUT; |
2062
|
|
|
$postParams = array(); |
2063
|
|
|
$queryParams = array(); |
2064
|
|
|
$path = $this->createPath($share, $path); |
2065
|
|
|
|
2066
|
|
|
Utilities::validateMetadata($metadata); |
2067
|
|
|
$headers = $this->generateMetadataHeaders($metadata); |
2068
|
|
|
if (is_null($options)) { |
2069
|
|
|
$options = new FileServiceOptions(); |
2070
|
|
|
} |
2071
|
|
|
|
2072
|
|
|
$this->addOptionalQueryParam( |
2073
|
|
|
$queryParams, |
2074
|
|
|
Resources::QP_COMP, |
2075
|
|
|
'metadata' |
2076
|
|
|
); |
2077
|
|
|
|
2078
|
|
|
$this->addOptionalQueryParam( |
2079
|
|
|
$queryParams, |
2080
|
|
|
Resources::QP_TIMEOUT, |
2081
|
|
|
$options->getTimeout() |
2082
|
|
|
); |
2083
|
|
|
|
2084
|
|
|
return $this->sendAsync( |
2085
|
|
|
$method, |
2086
|
|
|
$headers, |
2087
|
|
|
$queryParams, |
2088
|
|
|
$postParams, |
2089
|
|
|
$path, |
2090
|
|
|
Resources::STATUS_OK, |
2091
|
|
|
Resources::EMPTY_STRING, |
2092
|
|
|
$options |
2093
|
|
|
); |
2094
|
|
|
} |
2095
|
|
|
|
2096
|
|
|
/** |
2097
|
|
|
* Writes range of bytes to a file. Range can be at most 4MB in length. |
2098
|
|
|
* |
2099
|
|
|
* @param string $share The share name. |
2100
|
|
|
* @param string $path The path of the file. |
2101
|
|
|
* @param string|resource|StreamInterface $content The content to be uploaded. |
2102
|
|
|
* @param Range $range The range in the file to |
2103
|
|
|
* be put. |
2104
|
|
|
* @param PutFileRangeOptions|null $options The optional parameters. |
2105
|
|
|
* |
2106
|
|
|
* @return void |
2107
|
|
|
* |
2108
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/put-range |
2109
|
|
|
*/ |
2110
|
|
|
public function putFileRange( |
2111
|
|
|
$share, |
2112
|
|
|
$path, |
2113
|
|
|
$content, |
2114
|
|
|
Range $range, |
2115
|
|
|
PutFileRangeOptions $options = null |
2116
|
|
|
) { |
2117
|
|
|
$this->putFileRangeAsync( |
2118
|
|
|
$share, |
2119
|
|
|
$path, |
2120
|
|
|
$content, |
2121
|
|
|
$range, |
2122
|
|
|
$options |
2123
|
|
|
)->wait(); |
2124
|
|
|
} |
2125
|
|
|
|
2126
|
|
|
/** |
2127
|
|
|
* Creates promise to write range of bytes to a file. Range can be at most |
2128
|
|
|
* 4MB in length. |
2129
|
|
|
* |
2130
|
|
|
* @param string $share The share name. |
2131
|
|
|
* @param string $path The path of the file. |
2132
|
|
|
* @param string|resource|StreamInterface $content The content to be uploaded. |
2133
|
|
|
* @param Range $range The range in the file to |
2134
|
|
|
* be put. |
2135
|
|
|
* @param PutFileRangeOptions|null $options The optional parameters. |
2136
|
|
|
* |
2137
|
|
|
* @return \GuzzleHttp\Promise\PromiseInterface |
2138
|
|
|
* |
2139
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/put-range |
2140
|
|
|
* |
2141
|
|
|
*/ |
2142
|
|
|
public function putFileRangeAsync( |
2143
|
|
|
$share, |
2144
|
|
|
$path, |
2145
|
|
|
$content, |
2146
|
|
|
Range $range, |
2147
|
|
|
PutFileRangeOptions $options = null |
2148
|
|
|
) { |
2149
|
|
|
Validate::isString($share, 'share'); |
2150
|
|
|
Validate::isString($path, 'path'); |
2151
|
|
|
Validate::notNullOrEmpty($path, 'path'); |
2152
|
|
|
Validate::notNullOrEmpty($share, 'share'); |
2153
|
|
|
Validate::notNull($range->getLength(), Resources::RESOURCE_RANGE_LENGTH_MUST_SET); |
2154
|
|
|
$stream = Psr7\stream_for($content); |
2155
|
|
|
|
2156
|
|
|
$method = Resources::HTTP_PUT; |
2157
|
|
|
$headers = array(); |
2158
|
|
|
$queryParams = array(); |
2159
|
|
|
$postParams = array(); |
2160
|
|
|
$path = $this->createPath($share, $path); |
2161
|
|
|
|
2162
|
|
|
if ($options == null) { |
2163
|
|
|
$options = new PutFileRangeOptions(); |
2164
|
|
|
} |
2165
|
|
|
|
2166
|
|
|
$this->addOptionalQueryParam( |
2167
|
|
|
$queryParams, |
2168
|
|
|
Resources::QP_TIMEOUT, |
2169
|
|
|
$options->getTimeout() |
2170
|
|
|
); |
2171
|
|
|
|
2172
|
|
|
$this->addOptionalHeader( |
2173
|
|
|
$headers, |
2174
|
|
|
Resources::X_MS_RANGE, |
2175
|
|
|
$range->getRangeString() |
2176
|
|
|
); |
2177
|
|
|
|
2178
|
|
|
$this->addOptionalHeader( |
2179
|
|
|
$headers, |
2180
|
|
|
Resources::CONTENT_LENGTH, |
2181
|
|
|
$range->getLength() |
2182
|
|
|
); |
2183
|
|
|
|
2184
|
|
|
$this->addOptionalHeader( |
2185
|
|
|
$headers, |
2186
|
|
|
Resources::X_MS_WRITE, |
2187
|
|
|
'Update' |
2188
|
|
|
); |
2189
|
|
|
|
2190
|
|
|
$this->addOptionalHeader( |
2191
|
|
|
$headers, |
2192
|
|
|
Resources::CONTENT_MD5, |
2193
|
|
|
$options->getContentMD5() |
2194
|
|
|
); |
2195
|
|
|
|
2196
|
|
|
$this->addOptionalQueryParam( |
2197
|
|
|
$queryParams, |
2198
|
|
|
Resources::QP_COMP, |
2199
|
|
|
'range' |
2200
|
|
|
); |
2201
|
|
|
|
2202
|
|
|
return $this->sendAsync( |
2203
|
|
|
$method, |
2204
|
|
|
$headers, |
2205
|
|
|
$queryParams, |
2206
|
|
|
$postParams, |
2207
|
|
|
$path, |
2208
|
|
|
Resources::STATUS_CREATED, |
2209
|
|
|
$stream, |
2210
|
|
|
$options |
2211
|
|
|
); |
2212
|
|
|
} |
2213
|
|
|
|
2214
|
|
|
/** |
2215
|
|
|
* Creates a file from a provided content. |
2216
|
|
|
* |
2217
|
|
|
* @param string $share the share name |
2218
|
|
|
* @param string $path the path of the file |
2219
|
|
|
* @param StreamInterface|resource|string $content the content used to |
2220
|
|
|
* create the file |
2221
|
|
|
* @param CreateFileOptions|null $options optional parameters |
2222
|
|
|
* |
2223
|
|
|
* @return void |
2224
|
|
|
*/ |
2225
|
|
|
public function createFileFromContent( |
2226
|
|
|
$share, |
2227
|
|
|
$path, |
2228
|
|
|
$content, |
2229
|
|
|
CreateFileOptions $options = null |
2230
|
|
|
) { |
2231
|
|
|
$this->createFileFromContentAsync($share, $path, $content, $options)->wait(); |
2232
|
|
|
} |
2233
|
|
|
|
2234
|
|
|
/** |
2235
|
|
|
* Creates a promise to create a file from a provided content. |
2236
|
|
|
* |
2237
|
|
|
* @param string $share the share name |
2238
|
|
|
* @param string $path the path of the file |
2239
|
|
|
* @param StreamInterface|resource|string $content the content used to |
2240
|
|
|
* create the file |
2241
|
|
|
* @param CreateFileOptions|null $options optional parameters |
2242
|
|
|
* |
2243
|
|
|
* @return void |
2244
|
|
|
*/ |
2245
|
|
|
public function createFileFromContentAsync( |
2246
|
|
|
$share, |
2247
|
|
|
$path, |
2248
|
|
|
$content, |
2249
|
|
|
CreateFileOptions $options = null |
2250
|
|
|
) { |
2251
|
|
|
$stream = Psr7\stream_for($content); |
2252
|
|
|
$size = $stream->getSize(); |
2253
|
|
|
|
2254
|
|
|
if ($options == null) { |
2255
|
|
|
$options = new CreateFileOptions(); |
2256
|
|
|
} |
2257
|
|
|
|
2258
|
|
|
//create the file first |
2259
|
|
|
$promise = $this->createFileAsync($share, $path, $size, $options); |
2260
|
|
|
|
2261
|
|
|
//then upload the content |
2262
|
|
|
$range = new Range(0, $size - 1); |
2263
|
|
|
$putOptions = new PutFileRangeOptions($options); |
2264
|
|
|
if ($size > Resources::MB_IN_BYTES_4) { |
2265
|
|
|
return $promise->then(function ($response) use ( |
|
|
|
|
2266
|
|
|
$share, |
2267
|
|
|
$path, |
2268
|
|
|
$stream, |
2269
|
|
|
$range, |
2270
|
|
|
$putOptions |
2271
|
|
|
) { |
2272
|
|
|
return $this->multiplePutRangeConcurrentAsync( |
2273
|
|
|
$share, |
2274
|
|
|
$path, |
2275
|
|
|
$stream, |
2276
|
|
|
$range, |
2277
|
|
|
$putOptions |
2278
|
|
|
); |
2279
|
|
|
}, null); |
2280
|
|
|
} else { |
2281
|
|
|
return $promise->then(function ($response) use ( |
|
|
|
|
2282
|
|
|
$share, |
2283
|
|
|
$path, |
2284
|
|
|
$stream, |
2285
|
|
|
$range, |
2286
|
|
|
$putOptions |
2287
|
|
|
) { |
2288
|
|
|
return $this->putFileRangeAsync( |
2289
|
|
|
$share, |
2290
|
|
|
$path, |
2291
|
|
|
$stream, |
2292
|
|
|
$range, |
2293
|
|
|
$putOptions |
2294
|
|
|
); |
2295
|
|
|
}, null); |
2296
|
|
|
} |
2297
|
|
|
} |
2298
|
|
|
|
2299
|
|
|
/** |
2300
|
|
|
* Clears range of bytes of a file. If the specified range is not 512-byte |
2301
|
|
|
* aligned, the operation will write zeros to the start or end of the range |
2302
|
|
|
* that is not 512-byte aligned and free the rest of the range inside that |
2303
|
|
|
* is 512-byte aligned. |
2304
|
|
|
* |
2305
|
|
|
* @param string $share The share name. |
2306
|
|
|
* @param string $path The path of the file. |
2307
|
|
|
* @param Range $range The range in the file to |
2308
|
|
|
* be cleared. |
2309
|
|
|
* @param FileServiceOptions|null $options The optional parameters. |
2310
|
|
|
* |
2311
|
|
|
* @return void |
2312
|
|
|
* |
2313
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/put-range |
2314
|
|
|
*/ |
2315
|
|
|
public function clearFileRange( |
2316
|
|
|
$share, |
2317
|
|
|
$path, |
2318
|
|
|
Range $range, |
2319
|
|
|
FileServiceOptions $options = null |
2320
|
|
|
) { |
2321
|
|
|
$this->clearFileRangeAsync($share, $path, $range, $options)->wait(); |
2322
|
|
|
} |
2323
|
|
|
|
2324
|
|
|
/** |
2325
|
|
|
* Creates promise to clear range of bytes of a file. If the specified range |
2326
|
|
|
* is not 512-byte aligned, the operation will write zeros to the start or |
2327
|
|
|
* end of the range that is not 512-byte aligned and free the rest of the |
2328
|
|
|
* range inside that is 512-byte aligned. |
2329
|
|
|
* |
2330
|
|
|
* @param string $share The share name. |
2331
|
|
|
* @param string $path The path of the file. |
2332
|
|
|
* @param Range $range The range in the file to |
2333
|
|
|
* be cleared. |
2334
|
|
|
* @param FileServiceOptions|null $options The optional parameters. |
2335
|
|
|
* |
2336
|
|
|
* @return \GuzzleHttp\Promise\PromiseInterface |
2337
|
|
|
* |
2338
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/put-range |
2339
|
|
|
* |
2340
|
|
|
*/ |
2341
|
|
|
public function clearFileRangeAsync( |
2342
|
|
|
$share, |
2343
|
|
|
$path, |
2344
|
|
|
Range $range, |
2345
|
|
|
FileServiceOptions $options = null |
2346
|
|
|
) { |
2347
|
|
|
Validate::isString($share, 'share'); |
2348
|
|
|
Validate::isString($path, 'path'); |
2349
|
|
|
Validate::notNullOrEmpty($path, 'path'); |
2350
|
|
|
Validate::notNullOrEmpty($share, 'share'); |
2351
|
|
|
|
2352
|
|
|
$method = Resources::HTTP_PUT; |
2353
|
|
|
$headers = array(); |
2354
|
|
|
$queryParams = array(); |
2355
|
|
|
$postParams = array(); |
2356
|
|
|
$path = $this->createPath($share, $path); |
2357
|
|
|
|
2358
|
|
|
if (is_null($options)) { |
2359
|
|
|
$options = new FileServiceOptions(); |
2360
|
|
|
} |
2361
|
|
|
|
2362
|
|
|
$this->addOptionalHeader( |
2363
|
|
|
$headers, |
2364
|
|
|
Resources::X_MS_RANGE, |
2365
|
|
|
$range->getRangeString() |
2366
|
|
|
); |
2367
|
|
|
|
2368
|
|
|
$this->addOptionalQueryParam( |
2369
|
|
|
$queryParams, |
2370
|
|
|
Resources::QP_TIMEOUT, |
2371
|
|
|
$options->getTimeout() |
2372
|
|
|
); |
2373
|
|
|
|
2374
|
|
|
$this->addOptionalHeader( |
2375
|
|
|
$headers, |
2376
|
|
|
Resources::X_MS_WRITE, |
2377
|
|
|
'Clear' |
2378
|
|
|
); |
2379
|
|
|
|
2380
|
|
|
$this->addOptionalQueryParam( |
2381
|
|
|
$queryParams, |
2382
|
|
|
Resources::QP_COMP, |
2383
|
|
|
'range' |
2384
|
|
|
); |
2385
|
|
|
|
2386
|
|
|
return $this->sendAsync( |
2387
|
|
|
$method, |
2388
|
|
|
$headers, |
2389
|
|
|
$queryParams, |
2390
|
|
|
$postParams, |
2391
|
|
|
$path, |
2392
|
|
|
Resources::STATUS_CREATED, |
2393
|
|
|
Resources::EMPTY_STRING, |
2394
|
|
|
$options |
2395
|
|
|
); |
2396
|
|
|
} |
2397
|
|
|
|
2398
|
|
|
/** |
2399
|
|
|
* Lists range of bytes of a file. |
2400
|
|
|
* |
2401
|
|
|
* @param string $share The share name. |
2402
|
|
|
* @param string $path The path of the file. |
2403
|
|
|
* @param Range $range The range in the file to |
2404
|
|
|
* be listed. |
2405
|
|
|
* @param FileServiceOptions|null $options The optional parameters. |
2406
|
|
|
* |
2407
|
|
|
* @return ListFileRangesResult |
2408
|
|
|
* |
2409
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/list-ranges |
2410
|
|
|
*/ |
2411
|
|
|
public function listFileRange( |
2412
|
|
|
$share, |
2413
|
|
|
$path, |
2414
|
|
|
Range $range = null, |
2415
|
|
|
FileServiceOptions $options = null |
2416
|
|
|
) { |
2417
|
|
|
return $this->listFileRangeAsync($share, $path, $range, $options)->wait(); |
2418
|
|
|
} |
2419
|
|
|
|
2420
|
|
|
/** |
2421
|
|
|
* Creates promise to list range of bytes of a file. |
2422
|
|
|
* |
2423
|
|
|
* @param string $share The share name. |
2424
|
|
|
* @param string $path The path of the file. |
2425
|
|
|
* @param Range $range The range in the file to |
2426
|
|
|
* be listed. |
2427
|
|
|
* @param FileServiceOptions|null $options The optional parameters. |
2428
|
|
|
* |
2429
|
|
|
* @return \GuzzleHttp\Promise\PromiseInterface |
2430
|
|
|
* |
2431
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/list-ranges |
2432
|
|
|
* |
2433
|
|
|
*/ |
2434
|
|
|
public function listFileRangeAsync( |
2435
|
|
|
$share, |
2436
|
|
|
$path, |
2437
|
|
|
Range $range = null, |
2438
|
|
|
FileServiceOptions $options = null |
2439
|
|
|
) { |
2440
|
|
|
Validate::isString($share, 'share'); |
2441
|
|
|
Validate::isString($path, 'path'); |
2442
|
|
|
Validate::notNullOrEmpty($path, 'path'); |
2443
|
|
|
Validate::notNullOrEmpty($share, 'share'); |
2444
|
|
|
|
2445
|
|
|
$method = Resources::HTTP_GET; |
2446
|
|
|
$headers = array(); |
2447
|
|
|
$queryParams = array(); |
2448
|
|
|
$postParams = array(); |
2449
|
|
|
$path = $this->createPath($share, $path); |
2450
|
|
|
|
2451
|
|
|
if (is_null($options)) { |
2452
|
|
|
$options = new FileServiceOptions(); |
2453
|
|
|
} |
2454
|
|
|
|
2455
|
|
|
if ($range != null) { |
2456
|
|
|
$this->addOptionalHeader( |
2457
|
|
|
$headers, |
2458
|
|
|
Resources::X_MS_RANGE, |
2459
|
|
|
$range->getRangeString() |
2460
|
|
|
); |
2461
|
|
|
} |
2462
|
|
|
|
2463
|
|
|
$this->addOptionalQueryParam( |
2464
|
|
|
$queryParams, |
2465
|
|
|
Resources::QP_COMP, |
2466
|
|
|
'rangelist' |
2467
|
|
|
); |
2468
|
|
|
|
2469
|
|
|
$this->addOptionalQueryParam( |
2470
|
|
|
$queryParams, |
2471
|
|
|
Resources::QP_TIMEOUT, |
2472
|
|
|
$options->getTimeout() |
2473
|
|
|
); |
2474
|
|
|
|
2475
|
|
|
$dataSerializer = $this->dataSerializer; |
2476
|
|
|
|
2477
|
|
|
return $this->sendAsync( |
2478
|
|
|
$method, |
2479
|
|
|
$headers, |
2480
|
|
|
$queryParams, |
2481
|
|
|
$postParams, |
2482
|
|
|
$path, |
2483
|
|
|
Resources::STATUS_OK, |
2484
|
|
|
Resources::EMPTY_STRING, |
2485
|
|
|
$options |
2486
|
|
View Code Duplication |
)->then(function ($response) use ($dataSerializer) { |
|
|
|
|
2487
|
|
|
$responseHeaders = HttpFormatter::formatHeaders($response->getHeaders()); |
2488
|
|
|
$parsed = $dataSerializer->unserialize($response->getBody()); |
2489
|
|
|
return ListFileRangesResult::create($responseHeaders, $parsed); |
2490
|
|
|
}, null); |
2491
|
|
|
} |
2492
|
|
|
|
2493
|
|
|
/** |
2494
|
|
|
* Informs server to copy file from $sourcePath to $path. |
2495
|
|
|
* To copy a file to another file within the same storage account, you may |
2496
|
|
|
* use Shared Key to authenticate the source file. If you are copying a file |
2497
|
|
|
* from another storage account, or if you are copying a blob from the same |
2498
|
|
|
* storage account or another storage account, then you must authenticate |
2499
|
|
|
* the source file or blob using a shared access signature. If the source is |
2500
|
|
|
* a public blob, no authentication is required to perform the copy |
2501
|
|
|
* operation. |
2502
|
|
|
* Here are some examples of source object URLs: |
2503
|
|
|
* https://myaccount.file.core.windows.net/myshare/mydirectorypath/myfile |
2504
|
|
|
* https://myaccount.blob.core.windows.net/mycontainer/myblob?sastoken |
2505
|
|
|
* |
2506
|
|
|
* @param string $share The share name. |
2507
|
|
|
* @param string $path The path of the file. |
2508
|
|
|
* @param string $sourcePath The path of the source. |
2509
|
|
|
* @param array $metadata The metadata of the file. |
2510
|
|
|
* If specified, source metadata |
2511
|
|
|
* will not be copied. |
2512
|
|
|
* @param FileServiceOptions|null $options The optional parameters. |
2513
|
|
|
* |
2514
|
|
|
* @return CopyFileResult |
2515
|
|
|
* |
2516
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/copy-file |
2517
|
|
|
*/ |
2518
|
|
|
public function copyFile( |
2519
|
|
|
$share, |
2520
|
|
|
$path, |
2521
|
|
|
$sourcePath, |
2522
|
|
|
array $metadata = array(), |
2523
|
|
|
FileServiceOptions $options = null |
2524
|
|
|
) { |
2525
|
|
|
return $this->copyFileAsync( |
2526
|
|
|
$share, |
2527
|
|
|
$path, |
2528
|
|
|
$sourcePath, |
2529
|
|
|
$metadata, |
2530
|
|
|
$options |
2531
|
|
|
)->wait(); |
2532
|
|
|
} |
2533
|
|
|
|
2534
|
|
|
/** |
2535
|
|
|
* Creates promise to inform server to copy file from $sourcePath to $path. |
2536
|
|
|
* |
2537
|
|
|
* To copy a file to another file within the same storage account, you may |
2538
|
|
|
* use Shared Key to authenticate the source file. If you are copying a file |
2539
|
|
|
* from another storage account, or if you are copying a blob from the same |
2540
|
|
|
* storage account or another storage account, then you must authenticate |
2541
|
|
|
* the source file or blob using a shared access signature. If the source is |
2542
|
|
|
* a public blob, no authentication is required to perform the copy |
2543
|
|
|
* operation. |
2544
|
|
|
* Here are some examples of source object URLs: |
2545
|
|
|
* https://myaccount.file.core.windows.net/myshare/mydirectorypath/myfile |
2546
|
|
|
* https://myaccount.blob.core.windows.net/mycontainer/myblob?sastoken |
2547
|
|
|
* |
2548
|
|
|
* @param string $share The share name. |
2549
|
|
|
* @param string $path The path of the file. |
2550
|
|
|
* @param string $sourcePath The path of the source. |
2551
|
|
|
* @param array $metadata The metadata of the file. |
2552
|
|
|
* If specified, source metadata |
2553
|
|
|
* will not be copied. |
2554
|
|
|
* @param FileServiceOptions|null $options The optional parameters. |
2555
|
|
|
* |
2556
|
|
|
* @return \GuzzleHttp\Promise\PromiseInterface |
2557
|
|
|
* |
2558
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/copy-file |
2559
|
|
|
* |
2560
|
|
|
*/ |
2561
|
|
|
public function copyFileAsync( |
2562
|
|
|
$share, |
2563
|
|
|
$path, |
2564
|
|
|
$sourcePath, |
2565
|
|
|
array $metadata = array(), |
2566
|
|
|
FileServiceOptions $options = null |
2567
|
|
|
) { |
2568
|
|
|
Validate::isString($share, 'share'); |
2569
|
|
|
Validate::isString($path, 'path'); |
2570
|
|
|
Validate::isString($sourcePath, 'sourcePath'); |
2571
|
|
|
Validate::notNullOrEmpty($path, 'path'); |
2572
|
|
|
Validate::notNullOrEmpty($share, 'share'); |
2573
|
|
|
Validate::notNullOrEmpty($sourcePath, 'sourcePath'); |
2574
|
|
|
|
2575
|
|
|
$method = Resources::HTTP_PUT; |
2576
|
|
|
$headers = array(); |
|
|
|
|
2577
|
|
|
$queryParams = array(); |
2578
|
|
|
$postParams = array(); |
2579
|
|
|
$path = $this->createPath($share, $path); |
2580
|
|
|
|
2581
|
|
|
Utilities::validateMetadata($metadata); |
2582
|
|
|
$headers = $this->generateMetadataHeaders($metadata); |
2583
|
|
|
|
2584
|
|
|
if (is_null($options)) { |
2585
|
|
|
$options = new FileServiceOptions(); |
2586
|
|
|
} |
2587
|
|
|
|
2588
|
|
|
$this->addOptionalHeader( |
2589
|
|
|
$headers, |
2590
|
|
|
Resources::X_MS_COPY_SOURCE, |
2591
|
|
|
$sourcePath |
2592
|
|
|
); |
2593
|
|
|
|
2594
|
|
|
$this->addOptionalQueryParam( |
2595
|
|
|
$queryParams, |
2596
|
|
|
Resources::QP_TIMEOUT, |
2597
|
|
|
$options->getTimeout() |
2598
|
|
|
); |
2599
|
|
|
|
2600
|
|
|
return $this->sendAsync( |
2601
|
|
|
$method, |
2602
|
|
|
$headers, |
2603
|
|
|
$queryParams, |
2604
|
|
|
$postParams, |
2605
|
|
|
$path, |
2606
|
|
|
Resources::STATUS_ACCEPTED, |
2607
|
|
|
Resources::EMPTY_STRING, |
2608
|
|
|
$options |
2609
|
|
|
)->then(function ($response) { |
2610
|
|
|
$headers = HttpFormatter::formatHeaders($response->getHeaders()); |
2611
|
|
|
return CopyFileResult::create($headers); |
2612
|
|
|
}, null); |
2613
|
|
|
} |
2614
|
|
|
|
2615
|
|
|
/** |
2616
|
|
|
* Abort a file copy operation |
2617
|
|
|
* |
2618
|
|
|
* @param string $share name of the share |
2619
|
|
|
* @param string $path path of the file |
2620
|
|
|
* @param string $copyID copy operation identifier. |
2621
|
|
|
* @param FileServiceOptions|null $options optional parameters |
2622
|
|
|
* |
2623
|
|
|
* @return void |
2624
|
|
|
* |
2625
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/abort-copy-file |
2626
|
|
|
*/ |
2627
|
|
|
public function abortCopy( |
2628
|
|
|
$share, |
2629
|
|
|
$path, |
2630
|
|
|
$copyID, |
2631
|
|
|
FileServiceOptions $options = null |
2632
|
|
|
) { |
2633
|
|
|
return $this->abortCopyAsync( |
2634
|
|
|
$share, |
2635
|
|
|
$path, |
2636
|
|
|
$copyID, |
2637
|
|
|
$options |
2638
|
|
|
)->wait(); |
2639
|
|
|
} |
2640
|
|
|
|
2641
|
|
|
/** |
2642
|
|
|
* Creates promise to abort a file copy operation |
2643
|
|
|
* |
2644
|
|
|
* @param string $share name of the share |
2645
|
|
|
* @param string $path path of the file |
2646
|
|
|
* @param string $copyID copy operation identifier. |
2647
|
|
|
* @param FileServiceOptions|null $options optional parameters |
2648
|
|
|
* |
2649
|
|
|
* @return void |
2650
|
|
|
* |
2651
|
|
|
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/abort-copy-file |
2652
|
|
|
*/ |
2653
|
|
|
public function abortCopyAsync( |
2654
|
|
|
$share, |
2655
|
|
|
$path, |
2656
|
|
|
$copyID, |
2657
|
|
|
FileServiceOptions $options = null |
2658
|
|
|
) { |
2659
|
|
|
Validate::isString($share, 'share'); |
2660
|
|
|
Validate::isString($path, 'path'); |
2661
|
|
|
Validate::isString($copyID, 'copyID'); |
2662
|
|
|
Validate::notNullOrEmpty($share, 'share'); |
2663
|
|
|
Validate::notNullOrEmpty($path, 'path'); |
2664
|
|
|
Validate::notNullOrEmpty($copyID, 'copyID'); |
2665
|
|
|
|
2666
|
|
|
$method = Resources::HTTP_PUT; |
2667
|
|
|
$headers = array(); |
2668
|
|
|
$postParams = array(); |
2669
|
|
|
$queryParams = array(); |
2670
|
|
|
$path = $this->createPath($share, $path); |
2671
|
|
|
|
2672
|
|
|
if (is_null($options)) { |
2673
|
|
|
$options = new FileServiceOptions(); |
2674
|
|
|
} |
2675
|
|
|
|
2676
|
|
|
$this->addOptionalQueryParam( |
2677
|
|
|
$queryParams, |
2678
|
|
|
Resources::QP_TIMEOUT, |
2679
|
|
|
$options->getTimeout() |
2680
|
|
|
); |
2681
|
|
|
|
2682
|
|
|
$this->addOptionalQueryParam( |
2683
|
|
|
$queryParams, |
2684
|
|
|
Resources::QP_COMP, |
2685
|
|
|
'copy' |
2686
|
|
|
); |
2687
|
|
|
|
2688
|
|
|
$this->addOptionalQueryParam( |
2689
|
|
|
$queryParams, |
2690
|
|
|
Resources::QP_COPY_ID, |
2691
|
|
|
$copyID |
2692
|
|
|
); |
2693
|
|
|
|
2694
|
|
|
$this->addOptionalHeader( |
2695
|
|
|
$headers, |
2696
|
|
|
Resources::X_MS_COPY_ACTION, |
2697
|
|
|
'abort' |
2698
|
|
|
); |
2699
|
|
|
|
2700
|
|
|
return $this->sendAsync( |
2701
|
|
|
$method, |
2702
|
|
|
$headers, |
2703
|
|
|
$queryParams, |
2704
|
|
|
$postParams, |
2705
|
|
|
$path, |
2706
|
|
|
Resources::STATUS_NO_CONTENT, |
2707
|
|
|
Resources::EMPTY_STRING, |
2708
|
|
|
$options |
2709
|
|
|
); |
2710
|
|
|
} |
2711
|
|
|
} |
2712
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.