|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace BsbFlysystem\Adapter\Factory; |
|
6
|
|
|
|
|
7
|
|
|
use Interop\Container\ContainerInterface; |
|
8
|
|
|
use InvalidArgumentException; |
|
9
|
|
|
use League\Flysystem\AdapterInterface; |
|
10
|
|
|
use ProxyManager\Configuration; |
|
11
|
|
|
use ProxyManager\Factory\LazyLoadingValueHolderFactory; |
|
12
|
|
|
use ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy; |
|
13
|
|
|
use Zend\ServiceManager\FactoryInterface; |
|
14
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
|
15
|
|
|
use Zend\Stdlib\ArrayUtils; |
|
16
|
|
|
|
|
17
|
|
|
abstract class AbstractAdapterFactory implements FactoryInterface |
|
|
|
|
|
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var array |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $options; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* AbstractAdapterFactory constructor. |
|
26
|
|
|
* |
|
27
|
|
|
* @param array $options |
|
28
|
|
|
*/ |
|
29
|
58 |
|
public function __construct(array $options = []) |
|
30
|
|
|
{ |
|
31
|
58 |
|
$this->setCreationOptions($options); |
|
32
|
58 |
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Set creation options. |
|
36
|
|
|
*/ |
|
37
|
58 |
|
public function setCreationOptions(array $options) |
|
38
|
|
|
{ |
|
39
|
58 |
|
$this->options = $options; |
|
40
|
58 |
|
} |
|
41
|
|
|
|
|
42
|
10 |
|
public function __invoke(ContainerInterface $container, $requestedName, array $options = null): AdapterInterface |
|
43
|
|
|
{ |
|
44
|
10 |
|
if (null !== $options) { |
|
45
|
|
|
$this->setCreationOptions($options); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
10 |
|
$this->mergeMvcConfig($container, $requestedName); |
|
|
|
|
|
|
49
|
|
|
|
|
50
|
10 |
|
$this->validateConfig(); |
|
51
|
|
|
|
|
52
|
10 |
|
$service = $this->doCreateService($container); |
|
|
|
|
|
|
53
|
|
|
|
|
54
|
10 |
|
return $service; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
2 |
View Code Duplication |
public function createService(ServiceLocatorInterface $serviceLocator): AdapterInterface |
|
58
|
|
|
{ |
|
59
|
2 |
|
if (method_exists($serviceLocator, 'getServiceLocator')) { |
|
60
|
2 |
|
$serviceLocator = $serviceLocator->getServiceLocator(); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
2 |
|
return $this($serviceLocator, func_get_arg(2)); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Merges the options given from the ServiceLocator Config object with the create options of the class. |
|
68
|
|
|
*/ |
|
69
|
13 |
|
protected function mergeMvcConfig(ServiceLocatorInterface $serviceLocator, string $requestedName = null) |
|
70
|
|
|
{ |
|
71
|
13 |
|
$config = $serviceLocator->has('config') ? $serviceLocator->get('config') : []; |
|
72
|
|
|
|
|
73
|
13 |
|
if (! isset($config['bsb_flysystem']['adapters'][$requestedName]['options']) || |
|
74
|
13 |
|
! is_array(($config['bsb_flysystem']['adapters'][$requestedName]['options'])) |
|
75
|
|
|
) { |
|
76
|
2 |
|
return; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
11 |
|
$this->options = ArrayUtils::merge( |
|
80
|
11 |
|
$config['bsb_flysystem']['adapters'][$requestedName]['options'], |
|
81
|
11 |
|
$this->options |
|
82
|
|
|
); |
|
83
|
11 |
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @throws InvalidArgumentException |
|
87
|
|
|
*/ |
|
88
|
1 |
|
public function getLazyFactory(ServiceLocatorInterface $serviceLocator): LazyLoadingValueHolderFactory |
|
89
|
|
|
{ |
|
90
|
1 |
|
$config = $serviceLocator->has('config') ? $serviceLocator->get('config') : []; |
|
91
|
|
|
|
|
92
|
1 |
|
$config['lazy_services'] = ArrayUtils::merge( |
|
93
|
1 |
|
$config['lazy_services'] ?? [], |
|
94
|
1 |
|
$config['bsb_flysystem']['adapter_manager']['lazy_services'] |
|
95
|
|
|
); |
|
96
|
|
|
|
|
97
|
1 |
|
if (! isset($config['lazy_services'])) { |
|
98
|
|
|
throw new \InvalidArgumentException('Missing "lazy_services" config key'); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
1 |
|
$lazyServices = $config['lazy_services']; |
|
102
|
|
|
|
|
103
|
1 |
|
$factoryConfig = new Configuration(); |
|
104
|
|
|
|
|
105
|
1 |
|
if (isset($lazyServices['proxies_namespace'])) { |
|
106
|
|
|
$factoryConfig->setProxiesNamespace($lazyServices['proxies_namespace']); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
1 |
|
if (isset($lazyServices['proxies_target_dir'])) { |
|
110
|
|
|
$factoryConfig->setProxiesTargetDir($lazyServices['proxies_target_dir']); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
1 |
|
if (! isset($lazyServices['write_proxy_files']) || ! $lazyServices['write_proxy_files']) { |
|
114
|
1 |
|
$factoryConfig->setGeneratorStrategy(new EvaluatingGeneratorStrategy()); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
1 |
|
spl_autoload_register($factoryConfig->getProxyAutoloader()); |
|
118
|
|
|
|
|
119
|
1 |
|
return new LazyLoadingValueHolderFactory($factoryConfig); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* Create service. |
|
124
|
|
|
*/ |
|
125
|
|
|
abstract protected function doCreateService(ServiceLocatorInterface $serviceLocator): AdapterInterface; |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* Implement in adapter. |
|
129
|
|
|
* |
|
130
|
|
|
* @throw UnexpectedValueException |
|
131
|
|
|
*/ |
|
132
|
|
|
abstract protected function validateConfig(); |
|
133
|
|
|
} |
|
134
|
|
|
|
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.