Completed
Pull Request — master (#486)
by Dalibor
02:28
created

AzureBlobStorage::createContainer()   B

Complexity

Conditions 4
Paths 6

Size

Total Lines 23
Code Lines 14

Duplication

Lines 23
Ratio 100 %

Importance

Changes 0
Metric Value
dl 23
loc 23
rs 8.7972
c 0
b 0
f 0
cc 4
eloc 14
nc 6
nop 2
1
<?php
2
3
namespace Gaufrette\Adapter;
4
5
use Gaufrette\Adapter;
6
use Gaufrette\Util;
7
use Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface;
8
use MicrosoftAzure\Storage\Blob\Models\Blob;
9
use MicrosoftAzure\Storage\Blob\Models\Container;
10
use MicrosoftAzure\Storage\Blob\Models\CreateBlobOptions;
11
use MicrosoftAzure\Storage\Blob\Models\CreateContainerOptions;
12
use MicrosoftAzure\Storage\Blob\Models\DeleteContainerOptions;
13
use MicrosoftAzure\Storage\Blob\Models\ListBlobsOptions;
14
use MicrosoftAzure\Storage\Common\Exceptions\ServiceException;
15
16
/**
17
 * Microsoft Azure Blob Storage adapter.
18
 *
19
 * @author Luciano Mammino <[email protected]>
20
 * @author Paweł Czyżewski <[email protected]>
21
 */
22
class AzureBlobStorage implements Adapter,
0 ignored issues
show
Coding Style introduced by
The first item in a multi-line implements list must be on the line following the implements keyword
Loading history...
23
                                  MetadataSupporter
0 ignored issues
show
Coding Style introduced by
Expected 4 spaces before interface name; 34 found
Loading history...
24
{
25
    /**
26
     * Error constants.
27
     */
28
    const ERROR_CONTAINER_ALREADY_EXISTS = 'ContainerAlreadyExists';
29
    const ERROR_CONTAINER_NOT_FOUND = 'ContainerNotFound';
30
31
    /**
32
     * @var AzureBlobStorage\BlobProxyFactoryInterface
33
     */
34
    protected $blobProxyFactory;
35
36
    /**
37
     * @var string
38
     */
39
    protected $containerName;
40
41
    /**
42
     * @var bool
43
     */
44
    protected $detectContentType;
45
46
    /**
47
     * @var \MicrosoftAzure\Storage\Blob\Internal\IBlob
48
     */
49
    protected $blobProxy;
50
51
    /**
52
     * @var bool
53
     */
54
    protected $multiContainerMode = false;
55
56
    /**
57
     * @var CreateContainerOptions
58
     */
59
    protected $createContainerOptions;
60
61
    /**
62
     * @param AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
63
     * @param string|null                                $containerName
64
     * @param bool                                       $create
65
     * @param bool                                       $detectContentType
66
     *
67
     * @throws \RuntimeException
68
     */
69
    public function __construct(BlobProxyFactoryInterface $blobProxyFactory, $containerName = null, $create = false, $detectContentType = true)
70
    {
71
        $this->blobProxyFactory = $blobProxyFactory;
72
        $this->containerName = $containerName;
73
        $this->detectContentType = $detectContentType;
74
        if (null === $containerName) {
75
            $this->multiContainerMode = true;
76
        } elseif ($create) {
77
            $this->createContainer($containerName);
78
        }
79
    }
80
81
    /**
82
     * @return CreateContainerOptions
83
     */
84
    public function getCreateContainerOptions()
85
    {
86
        return $this->createContainerOptions;
87
    }
88
89
    /**
90
     * @param CreateContainerOptions $options
91
     */
92
    public function setCreateContainerOptions(CreateContainerOptions $options)
93
    {
94
        $this->createContainerOptions = $options;
95
    }
96
97
    /**
98
     * Creates a new container.
99
     *
100
     * @param string                                                     $containerName
101
     * @param \MicrosoftAzure\Storage\Blob\Models\CreateContainerOptions $options
102
     *
103
     * @throws \RuntimeException if cannot create the container
104
     */
105 View Code Duplication
    public function createContainer($containerName, CreateContainerOptions $options = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
106
    {
107
        $this->init();
108
109
        if (null === $options) {
110
            $options = $this->getCreateContainerOptions();
111
        }
112
113
        try {
114
            $this->blobProxy->createContainer($containerName, $options);
115
        } catch (ServiceException $e) {
0 ignored issues
show
Bug introduced by
The class MicrosoftAzure\Storage\C...ptions\ServiceException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
116
            $errorCode = $this->getErrorCodeFromServiceException($e);
117
118
            if ($errorCode !== self::ERROR_CONTAINER_ALREADY_EXISTS) {
119
                throw new \RuntimeException(sprintf(
120
                    'Failed to create the configured container "%s": %s (%s).',
121
                    $containerName,
122
                    $e->getErrorText(),
123
                    $errorCode
124
                ));
125
            }
126
        }
127
    }
128
129
    /**
130
     * Deletes a container.
131
     *
132
     * @param string                 $containerName
133
     * @param DeleteContainerOptions $options
134
     *
135
     * @throws \RuntimeException if cannot delete the container
136
     */
137 View Code Duplication
    public function deleteContainer($containerName, DeleteContainerOptions $options = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
138
    {
139
        $this->init();
140
141
        try {
142
            $this->blobProxy->deleteContainer($containerName, $options);
143
        } catch (ServiceException $e) {
0 ignored issues
show
Bug introduced by
The class MicrosoftAzure\Storage\C...ptions\ServiceException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
144
            $errorCode = $this->getErrorCodeFromServiceException($e);
145
146
            if ($errorCode !== self::ERROR_CONTAINER_NOT_FOUND) {
147
                throw new \RuntimeException(sprintf(
148
                    'Failed to delete the configured container "%s": %s (%s).',
149
                    $containerName,
150
                    $e->getErrorText(),
151
                    $errorCode
152
                ), $e->getCode());
153
            }
154
        }
155
    }
156
157
    /**
158
     * {@inheritdoc}
159
     * @throws \RuntimeException
160
     * @throws \InvalidArgumentException
161
     */
162 View Code Duplication
    public function read($key)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
163
    {
164
        $this->init();
165
        list($containerName, $key) = $this->tokenizeKey($key);
166
167
        try {
168
            $blob = $this->blobProxy->getBlob($containerName, $key);
169
170
            return stream_get_contents($blob->getContentStream());
171
        } catch (ServiceException $e) {
0 ignored issues
show
Bug introduced by
The class MicrosoftAzure\Storage\C...ptions\ServiceException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
172
            $this->failIfContainerNotFound($e, sprintf('read key "%s"', $key), $containerName);
173
174
            return false;
175
        }
176
    }
177
178
    /**
179
     * {@inheritdoc}
180
     * @throws \RuntimeException
181
     * @throws \InvalidArgumentException
182
     */
183
    public function write($key, $content)
184
    {
185
        $this->init();
186
        list($containerName, $key) = $this->tokenizeKey($key);
187
188
        $options = new CreateBlobOptions();
189
190
        if ($this->detectContentType) {
191
            $contentType = $this->guessContentType($content);
192
193
            $options->setBlobContentType($contentType);
194
        }
195
196
        try {
197
            $this->createContainer($containerName);
198
199
            $this->blobProxy->createBlockBlob($containerName, $key, $content, $options);
200
        } catch (ServiceException $e) {
0 ignored issues
show
Bug introduced by
The class MicrosoftAzure\Storage\C...ptions\ServiceException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
201
            $this->failIfContainerNotFound($e, sprintf('write content for key "%s"', $key), $containerName);
202
203
            return false;
204
        }
205
        if (is_resource($content)) {
206
            return Util\Size::fromResource($content);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return \Gaufrette\Util\S...fromResource($content); (string) is incompatible with the return type declared by the interface Gaufrette\Adapter::write of type integer|boolean.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
207
        }
208
209
        return Util\Size::fromContent($content);
210
    }
211
212
    /**
213
     * {@inheritdoc}
214
     * @throws \RuntimeException
215
     * @throws \InvalidArgumentException
216
     */
217
    public function exists($key)
218
    {
219
        $this->init();
220
        list($containerName, $key) = $this->tokenizeKey($key);
221
222
        $listBlobsOptions = new ListBlobsOptions();
223
        $listBlobsOptions->setPrefix($key);
224
225
        try {
226
            $blobsList = $this->blobProxy->listBlobs($containerName, $listBlobsOptions);
227
228
            foreach ($blobsList->getBlobs() as $blob) {
229
                if ($key === $blob->getName()) {
230
                    return true;
231
                }
232
            }
233
        } catch (ServiceException $e) {
0 ignored issues
show
Bug introduced by
The class MicrosoftAzure\Storage\C...ptions\ServiceException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
234
            $errorCode = $this->getErrorCodeFromServiceException($e);
235
            if ($this->multiContainerMode && self::ERROR_CONTAINER_NOT_FOUND === $errorCode) {
236
                return false;
237
            }
238
            $this->failIfContainerNotFound($e, 'check if key exists', $containerName);
239
240
            throw new \RuntimeException(sprintf(
241
                'Failed to check if key "%s" exists in container "%s": %s (%s).',
242
                $key,
243
                $containerName,
244
                $e->getErrorText(),
245
                $errorCode
246
            ), $e->getCode());
247
        }
248
249
        return false;
250
    }
251
252
    /**
253
     * {@inheritdoc}
254
     * @throws \RuntimeException
255
     */
256
    public function keys()
257
    {
258
        $this->init();
259
260
        try {
261
            if ($this->multiContainerMode) {
262
                $containersList = $this->blobProxy->listContainers();
263
                return call_user_func_array('array_merge', array_map(
264
                    function(Container $container) {
265
                        $containerName = $container->getName();
266
                        return $this->fetchBlobs($containerName, $containerName);
267
                    },
268
                    $containersList->getContainers()
269
                ));
270
            }
271
272
            return $this->fetchBlobs($this->containerName);
273
        } catch (ServiceException $e) {
0 ignored issues
show
Bug introduced by
The class MicrosoftAzure\Storage\C...ptions\ServiceException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
274
            $this->failIfContainerNotFound($e, 'retrieve keys', $this->containerName);
275
            $errorCode = $this->getErrorCodeFromServiceException($e);
276
277
            throw new \RuntimeException(sprintf(
278
                'Failed to list keys for the container "%s": %s (%s).',
279
                $this->containerName,
280
                $e->getErrorText(),
281
                $errorCode
282
            ), $e->getCode());
283
        }
284
    }
285
286
    /**
287
     * {@inheritdoc}
288
     * @throws \RuntimeException
289
     * @throws \InvalidArgumentException
290
     */
291 View Code Duplication
    public function mtime($key)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
292
    {
293
        $this->init();
294
        list($containerName, $key) = $this->tokenizeKey($key);
295
296
        try {
297
            $properties = $this->blobProxy->getBlobProperties($containerName, $key);
298
299
            return $properties->getProperties()->getLastModified()->getTimestamp();
300
        } catch (ServiceException $e) {
0 ignored issues
show
Bug introduced by
The class MicrosoftAzure\Storage\C...ptions\ServiceException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
301
            $this->failIfContainerNotFound($e, sprintf('read mtime for key "%s"', $key), $containerName);
302
303
            return false;
304
        }
305
    }
306
307
    /**
308
     * {@inheritdoc}
309
     * @throws \RuntimeException
310
     * @throws \InvalidArgumentException
311
     */
312 View Code Duplication
    public function delete($key)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
313
    {
314
        $this->init();
315
        list($containerName, $key) = $this->tokenizeKey($key);
316
317
        try {
318
            $this->blobProxy->deleteBlob($containerName, $key);
319
320
            return true;
321
        } catch (ServiceException $e) {
0 ignored issues
show
Bug introduced by
The class MicrosoftAzure\Storage\C...ptions\ServiceException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
322
            $this->failIfContainerNotFound($e, sprintf('delete key "%s"', $key), $containerName);
323
324
            return false;
325
        }
326
    }
327
328
    /**
329
     * {@inheritdoc}
330
     * @throws \RuntimeException
331
     * @throws \InvalidArgumentException
332
     */
333
    public function rename($sourceKey, $targetKey)
334
    {
335
        $this->init();
336
337
        list($sourceContainerName, $sourceKey) = $this->tokenizeKey($sourceKey);
338
        list($targetContainerName, $targetKey) = $this->tokenizeKey($targetKey);
339
340
        try {
341
            $this->createContainer($targetContainerName);
342
            $this->blobProxy->copyBlob($targetContainerName, $targetKey, $sourceContainerName, $sourceKey);
343
            $this->blobProxy->deleteBlob($sourceContainerName, $sourceKey);
344
345
            return true;
346
        } catch (ServiceException $e) {
0 ignored issues
show
Bug introduced by
The class MicrosoftAzure\Storage\C...ptions\ServiceException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
347
            $this->failIfContainerNotFound($e, sprintf('rename key "%s"', $sourceKey), $sourceContainerName);
348
349
            return false;
350
        }
351
    }
352
353
    /**
354
     * {@inheritdoc}
355
     */
356
    public function isDirectory($key)
357
    {
358
        // Windows Azure Blob Storage does not support directories
359
        return false;
360
    }
361
362
    /**
363
     * {@inheritdoc}
364
     * @throws \RuntimeException
365
     * @throws \InvalidArgumentException
366
     */
367 View Code Duplication
    public function setMetadata($key, $content)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
368
    {
369
        $this->init();
370
        list($containerName, $key) = $this->tokenizeKey($key);
371
372
        try {
373
            $this->blobProxy->setBlobMetadata($containerName, $key, $content);
374
        } catch (ServiceException $e) {
0 ignored issues
show
Bug introduced by
The class MicrosoftAzure\Storage\C...ptions\ServiceException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
375
            $errorCode = $this->getErrorCodeFromServiceException($e);
376
377
            throw new \RuntimeException(sprintf(
378
                'Failed to set metadata for blob "%s" in container "%s": %s (%s).',
379
                $key,
380
                $containerName,
381
                $e->getErrorText(),
382
                $errorCode
383
            ), $e->getCode());
384
        }
385
    }
386
387
    /**
388
     * {@inheritdoc}
389
     * @throws \RuntimeException
390
     * @throws \InvalidArgumentException
391
     */
392 View Code Duplication
    public function getMetadata($key)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
393
    {
394
        $this->init();
395
        list($containerName, $key) = $this->tokenizeKey($key);
396
397
        try {
398
            $properties = $this->blobProxy->getBlobProperties($containerName, $key);
399
400
            return $properties->getMetadata();
401
        } catch (ServiceException $e) {
0 ignored issues
show
Bug introduced by
The class MicrosoftAzure\Storage\C...ptions\ServiceException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
402
            $errorCode = $this->getErrorCodeFromServiceException($e);
403
404
            throw new \RuntimeException(sprintf(
405
                'Failed to get metadata for blob "%s" in container "%s": %s (%s).',
406
                $key,
407
                $containerName,
408
                $e->getErrorText(),
409
                $errorCode
410
            ), $e->getCode());
411
        }
412
    }
413
414
    /**
415
     * Lazy initialization, automatically called when some method is called after construction.
416
     */
417
    protected function init()
418
    {
419
        if ($this->blobProxy === null) {
420
            $this->blobProxy = $this->blobProxyFactory->create();
421
        }
422
    }
423
424
    /**
425
     * Throws a runtime exception if a give ServiceException derived from a "container not found" error.
426
     *
427
     * @param ServiceException $exception
428
     * @param string           $action
429
     * @param string           $containerName
430
     *
431
     * @throws \RuntimeException
432
     */
433
    protected function failIfContainerNotFound(ServiceException $exception, $action, $containerName)
434
    {
435
        $errorCode = $this->getErrorCodeFromServiceException($exception);
436
437
        if ($errorCode === self::ERROR_CONTAINER_NOT_FOUND) {
438
            throw new \RuntimeException(sprintf(
439
                'Failed to %s: container "%s" not found.',
440
                $action,
441
                $containerName
442
            ), $exception->getCode());
443
        }
444
    }
445
446
    /**
447
     * Extracts the error code from a service exception.
448
     *
449
     * @param ServiceException $exception
450
     *
451
     * @return string
452
     */
453
    protected function getErrorCodeFromServiceException(ServiceException $exception)
454
    {
455
        $xml = @simplexml_load_string($exception->getResponse()->getBody());
456
457
        if ($xml && isset($xml->Code)) {
458
            return (string) $xml->Code;
459
        }
460
461
        return $exception->getErrorText();
462
    }
463
464
    /**
465
     * @param string|resource $content
466
     *
467
     * @return string
468
     */
469 View Code Duplication
    private function guessContentType($content)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
470
    {
471
        $fileInfo = new \finfo(FILEINFO_MIME_TYPE);
472
473
        if (is_resource($content)) {
474
            return $fileInfo->file(stream_get_meta_data($content)['uri']);
475
        }
476
477
        return $fileInfo->buffer($content);
478
    }
479
480
    /**
481
     * @param string $key
482
     *
483
     * @return array
484
     * @throws \InvalidArgumentException
485
     */
486
    private function tokenizeKey($key)
487
    {
488
        $containerName = $this->containerName;
489
        if (false === $this->multiContainerMode) {
490
            return [$containerName, $key];
491
        }
492
493
        if (false === ($index = strpos($key, '/'))) {
494
            throw new \InvalidArgumentException(sprintf(
495
                'Failed to establish container name from key "%s", container name is required in multi-container mode',
496
                $key
497
            ));
498
        }
499
        $containerName = substr($key, 0, $index);
500
        $key = substr($key, $index + 1);
501
502
        return [$containerName, $key];
503
    }
504
505
    /**
506
     * @param string $containerName
507
     * @param null   $prefix
508
     *
509
     * @return array
510
     */
511
    private function fetchBlobs($containerName, $prefix = null)
512
    {
513
        $blobList = $this->blobProxy->listBlobs($containerName);
514
        return array_map(
515
            function (Blob $blob) use ($prefix) {
516
                $name = $blob->getName();
517
                if (null !== $prefix) {
518
                    $name = $prefix .'/'. $name;
519
                }
520
                return $name;
521
            },
522
            $blobList->getBlobs()
523
        );
524
    }
525
}
526