forked from sebastianfeldmann/phpbu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAzureBlob.php
More file actions
84 lines (77 loc) · 2.38 KB
/
Copy pathAzureBlob.php
File metadata and controls
84 lines (77 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
namespace phpbu\App\Backup\Collector;
use AzureOss\Storage\Blob\BlobContainerClient;
use phpbu\App\Backup\Collector;
use phpbu\App\Backup\File\AzureBlob as BlobFile;
use phpbu\App\Backup\Path;
use phpbu\App\Backup\Target;
use phpbu\App\Util;
/**
* AzureBlob class.
*
* @package phpbu
* @subpackage Backup
* @author Sebastian Feldmann <sebastian@phpbu.de>
* @author Jonathan Bouzekri <jonathan.bouzekri@gmail.com>
* @copyright Sebastian Feldmann <sebastian@phpbu.de>
* @license https://opensource.org/licenses/MIT The MIT License (MIT)
* @link https://phpbu.de/
* @since Class available since Release 5.2.7
*/
class AzureBlob extends Remote implements Collector
{
/**
* @var \AzureOss\Storage\Blob\BlobContainerClient
*/
protected $client;
/**
* AzureBlob constructor.
*
* @param \phpbu\App\Backup\Target $target
* @param \phpbu\App\Backup\Path $path
* @param \AzureOss\Storage\Blob\BlobContainerClient $client
*/
public function __construct(Target $target, Path $path, BlobContainerClient $client)
{
$this->setUp($target, $path);
$this->client = $client;
}
/**
* Collect all created backups.
*/
protected function collectBackups()
{
$prefix = $this->getPrefix($this->path->getPathThatIsNotChanging());
foreach ($this->listBlobs($prefix) as $blob) {
if ($this->isFileMatch($blob->name)) {
$file = new BlobFile($this->client, $blob);
$index = $this->getFileIndex($file);
$this->files[$index] = $file;
}
}
}
/**
* List all blobs in the container matching the given prefix.
*
* Pagination is handled transparently by the Azure Blob SDK.
*
* @param string $prefix
* @return iterable<\AzureOss\Storage\Blob\Models\Blob>
*/
protected function listBlobs(string $prefix): iterable
{
return $this->client->getBlobs($prefix);
}
/**
* Return prefix for querying remote files and folders
*
* @param string $path
* @return string
*/
protected function getPrefix($path): string
{
$prefix = Util\Path::withoutLeadingSlash($path);
$prefix = $prefix ? Util\Path::withTrailingSlash($prefix) : '';
return $prefix;
}
}