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