1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* BsbFlystem |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
* |
9
|
|
|
* @see https://bushbaby.nl/ |
10
|
|
|
* |
11
|
|
|
* @copyright Copyright (c) 2014-2021 bushbaby multimedia. (https://bushbaby.nl) |
12
|
|
|
* @author Bas Kamer <[email protected]> |
13
|
|
|
* @license MIT |
14
|
|
|
* |
15
|
|
|
* @package bushbaby/flysystem |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
declare(strict_types=1); |
19
|
|
|
|
20
|
|
|
namespace BsbFlysystem\Adapter\Factory; |
21
|
|
|
|
22
|
|
|
use BsbFlysystem\Exception\RequirementsException; |
23
|
|
|
use BsbFlysystem\Exception\UnexpectedValueException; |
24
|
|
|
use Google\Cloud\Storage\StorageClient; |
25
|
|
|
use League\Flysystem\AdapterInterface; |
26
|
|
|
use Psr\Container\ContainerInterface; |
27
|
|
|
use Superbalist\Flysystem\GoogleStorage\GoogleStorageAdapter as Adapter; |
28
|
|
|
|
29
|
|
|
class GoogleCloudDriveAdapterFactory extends AbstractAdapterFactory |
30
|
|
|
{ |
31
|
|
|
public function doCreateService(ContainerInterface $container): AdapterInterface |
32
|
|
|
{ |
33
|
|
|
if (! \class_exists(Adapter::class)) { |
34
|
|
|
throw new RequirementsException(['superbalist/flysystem-google-storage'], 'GoogleCloudDrive'); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
$storageClient = new StorageClient([ |
38
|
|
|
'projectId' => $this->options['project_id'], |
39
|
|
|
]); |
40
|
|
|
|
41
|
|
|
$bucket = $storageClient->bucket($this->options['bucket']); |
42
|
|
|
|
43
|
|
|
return new Adapter($storageClient, $bucket); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
protected function validateConfig(): void |
47
|
|
|
{ |
48
|
|
|
if (! isset($this->options['project_id'])) { |
49
|
|
|
throw new UnexpectedValueException("Missing 'project_id' as option"); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
if (! isset($this->options['bucket'])) { |
53
|
|
|
throw new UnexpectedValueException("Missing 'bucket' as option"); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|