|
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
|
1 |
|
*/ |
|
17
|
|
|
|
|
18
|
1 |
|
declare(strict_types=1); |
|
19
|
1 |
|
|
|
20
|
|
|
namespace BsbFlysystem\Adapter\Factory; |
|
21
|
|
|
|
|
22
|
|
|
use BsbFlysystem\Exception\RequirementsException; |
|
23
|
|
|
use BsbFlysystem\Exception\UnexpectedValueException; |
|
24
|
|
|
use League\Flysystem\AdapterInterface; |
|
25
|
|
|
use League\Flysystem\Rackspace\RackspaceAdapter as Adapter; |
|
26
|
|
|
use OpenCloud\OpenStack; |
|
27
|
|
|
use ProxyManager\Factory\LazyLoadingValueHolderFactory; |
|
28
|
1 |
|
use Psr\Container\ContainerInterface; |
|
29
|
1 |
|
|
|
30
|
1 |
|
class RackspaceAdapterFactory extends AbstractAdapterFactory |
|
31
|
|
|
{ |
|
32
|
|
|
public function doCreateService(ContainerInterface $container): AdapterInterface |
|
33
|
|
|
{ |
|
34
|
|
|
if (! \class_exists(Adapter::class) || |
|
35
|
|
|
! \class_exists(LazyLoadingValueHolderFactory::class) |
|
36
|
|
|
) { |
|
37
|
|
|
throw new RequirementsException(['league/flysystem-rackspace', 'ocramius/proxy-manager'], 'Rackspace'); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** @var AdapterInterface $proxy */ |
|
41
|
|
|
$proxy = $this->getLazyFactory($container)->createProxy( |
|
42
|
|
|
Adapter::class, |
|
43
|
|
|
function (&$wrappedObject, $proxy, $method, $parameters, &$initializer) { |
|
44
|
|
|
$client = new OpenStack( |
|
45
|
|
|
$this->options['url'], |
|
46
|
|
|
$this->options['secret'], |
|
47
|
|
|
$this->options['options'] |
|
48
|
1 |
|
); |
|
49
|
|
|
|
|
50
|
|
|
$store = $client->objectStoreService( |
|
51
|
1 |
|
$this->options['objectstore']['name'], |
|
52
|
|
|
$this->options['objectstore']['region'], |
|
53
|
|
|
$this->options['objectstore']['url_type'] |
|
54
|
10 |
|
); |
|
55
|
|
|
|
|
56
|
10 |
|
$container = $store->getContainer($this->options['objectstore']['container']); |
|
57
|
1 |
|
|
|
58
|
|
|
$wrappedObject = new Adapter($container, $this->options['prefix']); |
|
59
|
|
|
|
|
60
|
9 |
|
return true; |
|
61
|
2 |
|
} |
|
62
|
|
|
); |
|
63
|
|
|
|
|
64
|
7 |
|
return $proxy; |
|
65
|
2 |
|
} |
|
66
|
5 |
|
|
|
67
|
1 |
|
protected function validateConfig(): void |
|
68
|
4 |
|
{ |
|
69
|
1 |
|
if (! isset($this->options['url'])) { |
|
70
|
3 |
|
throw new UnexpectedValueException("Missing 'url' as option"); |
|
71
|
1 |
|
} |
|
72
|
|
|
|
|
73
|
|
View Code Duplication |
if (! isset($this->options['secret']) || ! \is_array($this->options['secret'])) { |
|
74
|
2 |
|
throw new UnexpectedValueException("Missing 'secret' as option"); |
|
75
|
1 |
|
} |
|
76
|
|
|
|
|
77
|
|
|
if (! isset($this->options['objectstore']) || ! \is_array($this->options['objectstore'])) { |
|
78
|
2 |
|
throw new UnexpectedValueException("Missing 'objectstore' as option"); |
|
79
|
2 |
|
} elseif (! isset($this->options['objectstore']['name'])) { |
|
80
|
|
|
throw new UnexpectedValueException("Missing 'objectstore.name' as option"); |
|
81
|
|
|
} elseif (! isset($this->options['objectstore']['region'])) { |
|
82
|
2 |
|
throw new UnexpectedValueException("Missing 'objectstore.region' as option"); |
|
83
|
2 |
|
} elseif (! isset($this->options['objectstore']['container'])) { |
|
84
|
|
|
throw new UnexpectedValueException("Missing 'objectstore.container' as option"); |
|
85
|
2 |
|
} |
|
86
|
|
|
|
|
87
|
|
|
if (! isset($this->options['objectstore']['url_type'])) { |
|
88
|
|
|
$this->options['objectstore']['url_type'] = null; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
if (! isset($this->options['options'])) { |
|
92
|
|
|
$this->options['options'] = []; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
if (! isset($this->options['prefix'])) { |
|
96
|
|
|
$this->options['prefix'] = null; |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|