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