forked from bushbaby/BsbFlysystem
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdapterManagerFactory.php
More file actions
113 lines (98 loc) · 4.13 KB
/
Copy pathAdapterManagerFactory.php
File metadata and controls
113 lines (98 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
/**
* BsbFlystem
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @see https://bushbaby.nl/
*
* @copyright Copyright (c) 2014-2020 bushbaby multimedia. (https://bushbaby.nl)
* @author Bas Kamer <baskamer@gmail.com>
* @license MIT
*
* @package bushbaby/flysystem
*/
declare(strict_types=1);
namespace BsbFlysystem\Service\Factory;
use BsbFlysystem\Adapter\Factory\AwsS3v3AdapterFactory;
use BsbFlysystem\Adapter\Factory\AzureAdapterFactory;
use BsbFlysystem\Adapter\Factory\DropboxAdapterFactory;
use BsbFlysystem\Adapter\Factory\FtpAdapterFactory;
use BsbFlysystem\Adapter\Factory\FtpdAdapterFactory;
use BsbFlysystem\Adapter\Factory\GoogleCloudDriveAdapterFactory;
use BsbFlysystem\Adapter\Factory\LocalAdapterFactory;
use BsbFlysystem\Adapter\Factory\RackspaceAdapterFactory;
use BsbFlysystem\Adapter\Factory\ReplicateAdapterFactory;
use BsbFlysystem\Adapter\Factory\SftpAdapterFactory;
use BsbFlysystem\Adapter\Factory\VfsAdapterFactory;
use BsbFlysystem\Adapter\Factory\WebDAVAdapterFactory;
use BsbFlysystem\Adapter\Factory\ZipArchiveAdapterFactory;
use BsbFlysystem\Exception\UnexpectedValueException;
use BsbFlysystem\Service\AdapterManager;
use Laminas\ServiceManager\Factory\InvokableFactory;
use Laminas\Stdlib\ArrayUtils;
use League\Flysystem\Adapter\NullAdapter;
use Psr\Container\ContainerInterface;
class AdapterManagerFactory
{
/**
* @var array mapping adapter types to plugin configuration
*/
protected $adapterMap = [
'factories' => [
'awss3v3' => AwsS3v3AdapterFactory::class,
'azure' => AzureAdapterFactory::class,
'dropbox' => DropboxAdapterFactory::class,
'ftp' => FtpAdapterFactory::class,
'ftpd' => FtpdAdapterFactory::class,
'googlecloudstorage' => GoogleCloudDriveAdapterFactory::class,
'local' => LocalAdapterFactory::class,
'rackspace' => RackspaceAdapterFactory::class,
'replicate' => ReplicateAdapterFactory::class,
'sftp' => SftpAdapterFactory::class,
'webdav' => WebDAVAdapterFactory::class,
'ziparchive' => ZipArchiveAdapterFactory::class,
'vfs' => VfsAdapterFactory::class,
'null' => InvokableFactory::class,
],
'aliases' => [
'null' => NullAdapter::class,
],
];
public function createService(ContainerInterface $container): AdapterManager
{
if (\method_exists($container, 'getServiceLocator')) {
$container = $container->getServiceLocator();
}
return $this($container, null);
}
public function __invoke(ContainerInterface $container, $requestedName, array $options = null): AdapterManager
{
$config = $container->get('config');
$config = $config['bsb_flysystem'];
$serviceConfig = $config['adapter_manager']['config'] ?? [];
$adapterMap = $this->adapterMap;
if (isset($config['adapter_map'])) {
$adapterMap = ArrayUtils::merge($this->adapterMap, $config['adapter_map']);
}
foreach ($config['adapters'] as $name => $adapterConfig) {
if (! isset($adapterConfig['type'])) {
throw new UnexpectedValueException(\sprintf("Missing 'type' key for the adapter '%s' configuration", $name));
}
$type = \strtolower($adapterConfig['type']);
if (! \in_array($type, \array_keys($adapterMap['factories']), false)) {
throw new UnexpectedValueException(\sprintf("Unknown adapter type '%s'", $type));
}
foreach (\array_keys($adapterMap) as $serviceKind) {
if (isset($adapterMap[$serviceKind][$type])) {
$serviceConfig[$serviceKind][$name] = $adapterMap[$serviceKind][$type];
if (isset($adapterConfig['shared'])) {
$serviceConfig['shared'][$name] = \filter_var($adapterConfig['shared'], FILTER_VALIDATE_BOOLEAN);
}
}
}
}
return new AdapterManager($container, $serviceConfig);
}
}