|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace WShafer\PSR11FlySystem\Config; |
|
5
|
|
|
|
|
6
|
|
|
use WShafer\PSR11FlySystem\Exception\MissingConfigException; |
|
7
|
|
|
|
|
8
|
|
|
class FileSystemConfig |
|
9
|
|
|
{ |
|
10
|
|
|
/** @var array */ |
|
11
|
|
|
protected $fileSystems = []; |
|
12
|
|
|
|
|
13
|
|
|
/** @var array */ |
|
14
|
|
|
protected $config = []; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* FileSystemConfig constructor. |
|
18
|
|
|
* |
|
19
|
|
|
* @param array $config |
|
20
|
|
|
*/ |
|
21
|
12 |
|
public function __construct(array $config) |
|
22
|
|
|
{ |
|
23
|
12 |
|
$this->config = $config; |
|
24
|
|
|
|
|
25
|
12 |
|
if ($this->isManager()) { |
|
26
|
3 |
|
$this->buildManagerFileSystemConfigs(); |
|
27
|
|
|
} |
|
28
|
11 |
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Get the adaptor |
|
32
|
|
|
* |
|
33
|
|
|
* @return string |
|
34
|
|
|
*/ |
|
35
|
12 |
|
public function getAdaptor() |
|
36
|
|
|
{ |
|
37
|
12 |
|
return $this->config['adaptor'] ?? 'default'; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Get the cache |
|
42
|
|
|
* |
|
43
|
|
|
* @return string |
|
44
|
|
|
*/ |
|
45
|
1 |
|
public function getCache() |
|
46
|
|
|
{ |
|
47
|
1 |
|
return $this->config['cache'] ?? 'default'; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Get the plugins |
|
52
|
|
|
* |
|
53
|
|
|
* @return array |
|
54
|
|
|
*/ |
|
55
|
1 |
|
public function getPlugins() |
|
56
|
|
|
{ |
|
57
|
1 |
|
return $this->config['plugins'] ?? []; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Is this defined as a file manager? |
|
62
|
|
|
* |
|
63
|
|
|
* @return bool |
|
64
|
|
|
*/ |
|
65
|
12 |
|
public function isManager() |
|
66
|
|
|
{ |
|
67
|
12 |
|
if ($this->getAdaptor() == 'manager') { |
|
68
|
3 |
|
return true; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
11 |
|
return false; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Get the configured File Systems. |
|
76
|
|
|
* Used for manager configuration |
|
77
|
|
|
* |
|
78
|
|
|
* @return FileSystemConfig[] |
|
79
|
|
|
*/ |
|
80
|
1 |
|
public function getFileSystems() |
|
81
|
|
|
{ |
|
82
|
1 |
|
return $this->fileSystems; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Build out the file system configs for use |
|
87
|
|
|
* by the manager. |
|
88
|
|
|
*/ |
|
89
|
3 |
|
protected function buildManagerFileSystemConfigs() |
|
90
|
|
|
{ |
|
91
|
3 |
|
if (empty($this->config['fileSystems'])) { |
|
92
|
1 |
|
throw new MissingConfigException( |
|
93
|
1 |
|
'Missing file systems for manager' |
|
94
|
|
|
); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
2 |
|
foreach ($this->config['fileSystems'] as $name => $fileSystem) { |
|
98
|
2 |
|
$this->fileSystems[$name] = new self($fileSystem); |
|
99
|
|
|
} |
|
100
|
2 |
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|