Total Complexity | 5 |
Total Lines | 38 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 1 | Features | 0 |
1 | <?php |
||
17 | class GoogleCloudStorage |
||
18 | { |
||
19 | /** |
||
20 | * @var \Google\Cloud\Storage\Bucket $bucket |
||
21 | */ |
||
22 | private $bucket; |
||
23 | |||
24 | /** |
||
25 | * GoogleCloudStorage constructor. |
||
26 | * @param string $bucket |
||
27 | * @param bool $userProject |
||
28 | * @param array $config |
||
29 | */ |
||
30 | public function __construct(array $config, string $bucket, $userProject = false) |
||
31 | { |
||
32 | $storage = new StorageClient($config); |
||
33 | $this->bucket = $storage->bucket($bucket, $userProject); |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * @param string $dir |
||
38 | * @param array $options |
||
39 | */ |
||
40 | public function uploadDirectory(string $dir, array $options = []) |
||
41 | { |
||
42 | foreach (scandir($dir) as $key => $filename) { |
||
43 | $path = $dir . DIRECTORY_SEPARATOR . $filename; |
||
44 | |||
45 | if (is_file($path)) { |
||
46 | $this->bucket->upload(fopen($path, 'r'), $options); |
||
47 | } |
||
48 | } |
||
49 | } |
||
50 | |||
51 | public function download(string $name, string $save_to) |
||
55 | } |
||
56 | } |