|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Micro framework package. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Stanislau Komar <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Micro\Plugin\Filesystem; |
|
15
|
|
|
|
|
16
|
|
|
use Micro\Framework\Kernel\Configuration\Exception\InvalidConfigurationException; |
|
17
|
|
|
use Micro\Framework\Kernel\Configuration\PluginConfiguration; |
|
18
|
|
|
use Micro\Plugin\Filesystem\Configuration\Adapter\FilesystemAdapterConfigurationInterface; |
|
19
|
|
|
use Micro\Plugin\Filesystem\Configuration\FilesystemPluginConfigurationInterface; |
|
20
|
|
|
|
|
21
|
|
|
class FilesystemPluginConfiguration extends PluginConfiguration implements FilesystemPluginConfigurationInterface |
|
22
|
|
|
{ |
|
23
|
|
|
public const CFG_ADAPTER_TYPE = 'MICRO_FS_%s_TYPE'; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* {@inheritDoc} |
|
27
|
|
|
*/ |
|
28
|
3 |
|
public function createAdapterConfiguration(string $adapterName, string $adapterCfgClass): FilesystemAdapterConfigurationInterface |
|
29
|
|
|
{ |
|
30
|
3 |
|
if (!class_exists($adapterCfgClass)) { |
|
31
|
1 |
|
throw new InvalidConfigurationException(sprintf('Adapter "%s" can not be configured. Configuration class "%s" not exists.', $adapterName, $adapterCfgClass)); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
2 |
|
return new $adapterCfgClass($this->configuration, $adapterName); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* {@inheritDoc} |
|
39
|
|
|
*/ |
|
40
|
1 |
|
public function getAdapterType(string $adapterName): string |
|
41
|
|
|
{ |
|
42
|
1 |
|
return mb_strtolower( |
|
43
|
1 |
|
$this->configuration->get( |
|
44
|
1 |
|
sprintf(self::CFG_ADAPTER_TYPE, mb_strtoupper($adapterName)), |
|
45
|
1 |
|
null, |
|
46
|
1 |
|
false |
|
47
|
1 |
|
) |
|
48
|
1 |
|
); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @param string $adapterName |
|
53
|
|
|
* |
|
54
|
|
|
* @throws \Exception |
|
55
|
|
|
* |
|
56
|
|
|
* @return FilesystemAdapterConfigurationInterface |
|
57
|
|
|
*/ |
|
58
|
1 |
|
public function getAdapterConfiguration(string $adapterName): FilesystemAdapterConfigurationInterface |
|
59
|
|
|
{ |
|
60
|
1 |
|
$message = <<<EOF |
|
61
|
|
|
No configuration available for filesystem adapter `%s`. |
|
62
|
|
|
Please, implement your adapter or install exiting like as |
|
63
|
|
|
* `micro/micro/plugin-filesystem-s3` |
|
64
|
|
|
* `micro/micro/plugin-filesystem-local` |
|
65
|
1 |
|
EOF; |
|
66
|
|
|
|
|
67
|
1 |
|
throw new InvalidConfigurationException(sprintf($message, $adapterName)); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|