|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BsbFlysystem\Service\Factory; |
|
4
|
|
|
|
|
5
|
|
|
use BsbFlysystem\Exception\UnexpectedValueException; |
|
6
|
|
|
use BsbFlysystem\Service\AdapterManager; |
|
7
|
|
|
use Interop\Container\ContainerInterface; |
|
8
|
|
|
use Zend\ServiceManager\FactoryInterface; |
|
9
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
|
10
|
|
|
use Zend\Stdlib\ArrayUtils; |
|
11
|
|
|
|
|
12
|
|
|
class AdapterManagerFactory implements FactoryInterface |
|
|
|
|
|
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var array mapping adapter types to plugin configuration |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $adapterMap = [ |
|
18
|
|
|
'factories' => [ |
|
19
|
|
|
'awss3' => \BsbFlysystem\Adapter\Factory\AwsS3AdapterFactory::class, |
|
20
|
|
|
'awss3v3' => \BsbFlysystem\Adapter\Factory\AwsS3v3AdapterFactory::class, |
|
21
|
|
|
'azure' => \BsbFlysystem\Adapter\Factory\AzureAdapterFactory::class, |
|
22
|
|
|
'copy' => \BsbFlysystem\Adapter\Factory\CopyAdapterFactory::class, |
|
23
|
|
|
'dropbox' => \BsbFlysystem\Adapter\Factory\DropboxAdapterFactory::class, |
|
24
|
|
|
'ftp' => \BsbFlysystem\Adapter\Factory\FtpAdapterFactory::class, |
|
25
|
|
|
'local' => \BsbFlysystem\Adapter\Factory\LocalAdapterFactory::class, |
|
26
|
|
|
'rackspace' => \BsbFlysystem\Adapter\Factory\RackspaceAdapterFactory::class, |
|
27
|
|
|
'replicate' => \BsbFlysystem\Adapter\Factory\ReplicateAdapterFactory::class, |
|
28
|
|
|
'sftp' => \BsbFlysystem\Adapter\Factory\SftpAdapterFactory::class, |
|
29
|
|
|
'webdav' => \BsbFlysystem\Adapter\Factory\WebDAVAdapterFactory::class, |
|
30
|
|
|
'ziparchive' => \BsbFlysystem\Adapter\Factory\ZipArchiveAdapterFactory::class, |
|
31
|
|
|
'vfs' => \BsbFlysystem\Adapter\Factory\VfsAdapterFactory::class, |
|
32
|
|
|
'null' => \Zend\ServiceManager\Factory\InvokableFactory::class, |
|
33
|
|
|
], |
|
34
|
|
|
'aliases' => [ |
|
35
|
|
|
'null' => \League\Flysystem\Adapter\NullAdapter::class, |
|
36
|
|
|
] |
|
37
|
|
|
]; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Create service |
|
41
|
|
|
* |
|
42
|
|
|
* @param ServiceLocatorInterface $serviceLocator |
|
43
|
|
|
* @return AdapterManager |
|
44
|
|
|
*/ |
|
45
|
|
View Code Duplication |
public function createService(ServiceLocatorInterface $serviceLocator) |
|
|
|
|
|
|
46
|
|
|
{ |
|
47
|
|
|
if (method_exists($serviceLocator, 'getServiceLocator')) { |
|
48
|
|
|
$serviceLocator = $serviceLocator->getServiceLocator(); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
return $this($serviceLocator, null); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @inheritdoc |
|
56
|
|
|
*/ |
|
57
|
5 |
|
public function __invoke(ContainerInterface $container, $requestedName, array $options = null) |
|
58
|
|
|
{ |
|
59
|
5 |
|
$config = $container->get('config'); |
|
60
|
5 |
|
$config = $config['bsb_flysystem']; |
|
61
|
5 |
|
$serviceConfig = isset($config['adapter_manager']['config']) ? $config['adapter_manager']['config'] : []; |
|
62
|
5 |
|
$adapterMap = $this->adapterMap; |
|
63
|
|
|
|
|
64
|
5 |
|
if (isset($config['adapter_map'])) { |
|
65
|
1 |
|
$adapterMap = ArrayUtils::merge($this->adapterMap, $config['adapter_map']); |
|
66
|
1 |
|
} |
|
67
|
|
|
|
|
68
|
5 |
|
foreach ($config['adapters'] as $name => $adapterConfig) { |
|
69
|
4 |
|
if (!isset($adapterConfig['type'])) { |
|
70
|
1 |
|
throw new UnexpectedValueException(sprintf( |
|
71
|
1 |
|
"Missing 'type' key for the adapter '%s' configuration", |
|
72
|
|
|
$name |
|
73
|
1 |
|
)); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
3 |
|
$type = strtolower($adapterConfig['type']); |
|
77
|
|
|
|
|
78
|
3 |
|
if (!in_array($type, array_keys($adapterMap['factories']), false)) { |
|
79
|
1 |
|
throw new UnexpectedValueException(sprintf("Unknown adapter type '%s'", $type)); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
2 |
|
foreach (array_keys($adapterMap) as $serviceKind) { |
|
83
|
2 |
|
if (isset($adapterMap[$serviceKind][$type])) { |
|
84
|
2 |
|
$serviceConfig[$serviceKind][$name] = $adapterMap[$serviceKind][$type]; |
|
85
|
|
|
|
|
86
|
2 |
|
if (isset($adapterConfig['shared'])) { |
|
87
|
2 |
|
$serviceConfig['shared'][$name] = filter_var($adapterConfig['shared'], FILTER_VALIDATE_BOOLEAN); |
|
88
|
2 |
|
} |
|
89
|
2 |
|
} |
|
90
|
2 |
|
} |
|
91
|
3 |
|
} |
|
92
|
|
|
|
|
93
|
3 |
|
return new AdapterManager($container, $serviceConfig); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.