|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AnyCloud\Service\File\Store; |
|
4
|
|
|
|
|
5
|
|
|
use AnyCloud\File\Store\AnyCloud; |
|
6
|
|
|
use AnyCloud\Service\File\Adapter; |
|
7
|
|
|
use AnyCloud\Traits\CommonTrait; |
|
8
|
|
|
use Interop\Container\ContainerInterface; |
|
|
|
|
|
|
9
|
|
|
use League\Flysystem\Filesystem; |
|
10
|
|
|
use Zend\ServiceManager\Factory\FactoryInterface; |
|
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class AnyCloudFactory implements FactoryInterface |
|
13
|
|
|
{ |
|
14
|
|
|
use CommonTrait; |
|
15
|
|
|
|
|
16
|
|
|
private const AWS_BASED = ['aws', 'wasabi', 'digital_ocean', 'scaleway']; |
|
17
|
|
|
|
|
18
|
|
|
protected $options; |
|
19
|
|
|
private $filesystem; |
|
20
|
|
|
private $uri; |
|
21
|
|
|
private $tempUri; |
|
22
|
|
|
private $adapter; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @param ContainerInterface $serviceLocator |
|
26
|
|
|
* @param string $requestedName |
|
27
|
|
|
* @param array|null $options |
|
28
|
|
|
* |
|
29
|
|
|
* @return AnyCloud|object |
|
30
|
|
|
*/ |
|
31
|
|
|
public function __invoke(ContainerInterface $serviceLocator, $requestedName, array $options = null) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->options = $serviceLocator->get('Omeka\Settings'); |
|
34
|
|
|
$this->createFilesystem(); |
|
35
|
|
|
$this->createUri(); |
|
36
|
|
|
|
|
37
|
|
|
return new AnyCloud($this->filesystem, $this->options, $this->uri, $this->adapter); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Create the Filesystem object. |
|
42
|
|
|
*/ |
|
43
|
|
|
private function createFilesystem(): void |
|
44
|
|
|
{ |
|
45
|
|
|
$this->createAwsAdapter(); |
|
46
|
|
|
$this->createAzureAdapter(); |
|
47
|
|
|
$this->createRackspaceAdapter(); |
|
48
|
|
|
$this->createDropboxAdapter(); |
|
49
|
|
|
$this->createGoogleAdapter(); |
|
50
|
|
|
|
|
51
|
|
|
$this->filesystem = new Filesystem($this->adapter); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Create adapter |
|
56
|
|
|
* |
|
57
|
|
|
* @param object $adapter Adapter to create |
|
58
|
|
|
*/ |
|
59
|
|
|
private function createAdapter($adapter): void |
|
60
|
|
|
{ |
|
61
|
|
|
$this->adapter = $adapter->createAdapter($this->options); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Create a temporary URI to store the file before saving |
|
66
|
|
|
* |
|
67
|
|
|
* @param object $adapter Adapter to create a temporary URI for |
|
68
|
|
|
*/ |
|
69
|
|
|
private function createTempUri($adapter): void |
|
70
|
|
|
{ |
|
71
|
|
|
$this->tempUri = $adapter->getUri(); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Create new AWS adapter |
|
76
|
|
|
*/ |
|
77
|
|
|
private function createAwsAdapter(): void |
|
78
|
|
|
{ |
|
79
|
|
|
if (in_array($this->getAdapter(), self::AWS_BASED, true)) { |
|
80
|
|
|
$this->createAdapter(new Adapter\AwsAdapter()); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Create new Azure adapter |
|
86
|
|
|
*/ |
|
87
|
|
|
private function createAzureAdapter(): void |
|
88
|
|
|
{ |
|
89
|
|
|
if ($this->getAdapter() === 'azure') { |
|
90
|
|
|
$adapter = new Adapter\AzureAdapter(); |
|
91
|
|
|
$this->createAdapter($adapter); |
|
92
|
|
|
$this->createTempUri($adapter); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Create new Rackspace adapter |
|
98
|
|
|
*/ |
|
99
|
|
|
private function createRackspaceAdapter(): void |
|
100
|
|
|
{ |
|
101
|
|
|
if ($this->getAdapter() === 'rackspace') { |
|
102
|
|
|
$adapter = new Adapter\RackspaceAdapter(); |
|
103
|
|
|
$this->createAdapter($adapter); |
|
104
|
|
|
$this->createTempUri($adapter); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Create new Dropbox adapter |
|
110
|
|
|
*/ |
|
111
|
|
|
private function createDropboxAdapter(): void |
|
112
|
|
|
{ |
|
113
|
|
|
if ($this->getAdapter() === 'dropbox') { |
|
114
|
|
|
$adapter = new Adapter\DropboxAdapter(); |
|
115
|
|
|
$this->createAdapter($adapter); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* Create new Google adapter |
|
121
|
|
|
*/ |
|
122
|
|
|
private function createGoogleAdapter(): void |
|
123
|
|
|
{ |
|
124
|
|
|
if ($this->getAdapter() === 'google') { |
|
125
|
|
|
$adapter = new Adapter\GoogleAdapter(); |
|
126
|
|
|
$this->createAdapter($adapter); |
|
127
|
|
|
$this->createTempUri($adapter); |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* Create URI for file. |
|
133
|
|
|
*/ |
|
134
|
|
|
private function createUri(): void |
|
135
|
|
|
{ |
|
136
|
|
|
if (in_array($this->getAdapter(), self::AWS_BASED, true)) { |
|
137
|
|
|
$this->uri = dirname($this->filesystem->getAdapter()->getClient()->getObjectUrl($this->getSetting('bucket'), |
|
138
|
|
|
$this->getSetting('key'))); |
|
139
|
|
|
} else { |
|
140
|
|
|
$this->uri = $this->tempUri; |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths