1 | <?php |
||
8 | class MainConfig |
||
9 | { |
||
10 | protected $config = []; |
||
11 | |||
12 | protected $adaptors = []; |
||
13 | |||
14 | protected $cache = []; |
||
15 | |||
16 | protected $fileSystems = []; |
||
17 | |||
18 | 24 | public function __construct(array $config) |
|
26 | |||
27 | 24 | public function validateConfigAndSetDefaults(&$config) |
|
28 | { |
||
29 | 24 | if (empty($config) |
|
30 | 24 | || empty($config['flysystem']) |
|
31 | ) { |
||
32 | 3 | throw new MissingConfigException( |
|
33 | 3 | 'No config key of "flysystem" found in config array.' |
|
34 | ); |
||
35 | } |
||
36 | |||
37 | 23 | if (empty($config['flysystem']['adaptors'])) { |
|
38 | 1 | throw new MissingConfigException( |
|
39 | 1 | 'No config key of "adaptors" found in flysystem config array.' |
|
40 | ); |
||
41 | } |
||
42 | |||
43 | 23 | if (empty($config['flysystem']['fileSystems']['default'])) { |
|
44 | 23 | $config['flysystem']['fileSystems']['default'] = []; |
|
45 | } |
||
46 | |||
47 | 23 | if (empty($config['flysystem']['caches']['default'])) { |
|
48 | 23 | $config['flysystem']['caches']['default']['type'] = 'memory'; |
|
49 | } |
||
50 | 23 | } |
|
51 | |||
52 | /** |
||
53 | * @param $fileSystem |
||
54 | * @return FileSystemConfig|null |
||
55 | */ |
||
56 | 2 | public function getFileSystemConfig($fileSystem) |
|
57 | { |
||
58 | 2 | return $this->fileSystems[$fileSystem] ?? null; |
|
59 | } |
||
60 | |||
61 | /** |
||
62 | * @param $adaptor |
||
63 | * @return AdaptorConfig|null |
||
64 | */ |
||
65 | 2 | public function getAdaptorConfig($adaptor) |
|
66 | { |
||
67 | 2 | return $this->adaptors[$adaptor] ?? null; |
|
68 | } |
||
69 | |||
70 | /** |
||
71 | * @param $cache |
||
72 | * |
||
73 | * @return CacheConfig|null |
||
74 | */ |
||
75 | 3 | public function getCacheConfig($cache) |
|
79 | |||
80 | 2 | public function hasFileSystemConfig($fileSystem) : bool |
|
84 | |||
85 | 2 | public function hasAdaptorConfig($adaptor) : bool |
|
89 | |||
90 | 2 | public function hasCacheConfig($cache) : bool |
|
94 | |||
95 | 23 | protected function buildAdaptorConfigs() |
|
101 | |||
102 | 23 | protected function buildCacheConfigs() |
|
103 | { |
||
104 | 23 | foreach ($this->config['flysystem']['caches'] as $name => $cache) { |
|
108 | |||
109 | 23 | protected function buildFileSystemConfigs() |
|
115 | } |
||
116 |