1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Micro framework package. |
5
|
|
|
* |
6
|
|
|
* (c) Stanislau Komar <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Micro\Framework\Kernel\Boot; |
13
|
|
|
|
14
|
|
|
use Micro\Framework\Kernel\Configuration\ApplicationConfigurationFactoryInterface; |
15
|
|
|
use Micro\Framework\Kernel\Configuration\ApplicationConfigurationInterface; |
16
|
|
|
use Micro\Framework\Kernel\Configuration\DefaultApplicationConfigurationFactory; |
17
|
|
|
use Micro\Framework\Kernel\Configuration\Resolver\PluginConfigurationClassResolver; |
18
|
|
|
use Micro\Framework\Kernel\Plugin\ConfigurableInterface; |
19
|
|
|
use Micro\Framework\Kernel\Plugin\PluginBootLoaderInterface; |
20
|
|
|
|
21
|
|
|
class ConfigurationProviderBootLoader implements PluginBootLoaderInterface |
22
|
|
|
{ |
23
|
|
|
private readonly ApplicationConfigurationInterface $applicationConfiguration; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param array<string|mixed>|ApplicationConfigurationInterface|ApplicationConfigurationFactoryInterface $config |
27
|
|
|
*/ |
28
|
3 |
|
public function __construct( |
29
|
|
|
array|ApplicationConfigurationInterface|ApplicationConfigurationFactoryInterface $config |
30
|
|
|
) { |
31
|
3 |
|
$applicationConfig = $config; |
32
|
|
|
|
33
|
3 |
|
if (\is_array($config)) { |
|
|
|
|
34
|
1 |
|
$applicationConfig = new DefaultApplicationConfigurationFactory($config); |
35
|
|
|
} |
36
|
|
|
|
37
|
3 |
|
if ($applicationConfig instanceof ApplicationConfigurationFactoryInterface) { |
|
|
|
|
38
|
2 |
|
$applicationConfig = $applicationConfig->create(); |
39
|
|
|
} |
40
|
|
|
/** |
41
|
|
|
* @psalm-suppress PossiblyInvalidPropertyAssignmentValue |
42
|
|
|
* |
43
|
|
|
* @phpstan-ignore-next-line |
44
|
|
|
*/ |
45
|
3 |
|
$this->applicationConfiguration = $applicationConfig; |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* {@inheritDoc} |
50
|
|
|
*/ |
51
|
3 |
|
public function boot(object $applicationPlugin): void |
52
|
|
|
{ |
53
|
3 |
|
if (!($applicationPlugin instanceof ConfigurableInterface)) { |
54
|
|
|
return; |
55
|
|
|
} |
56
|
|
|
|
57
|
3 |
|
$applicationPlugin->setConfiguration( |
58
|
3 |
|
$this->createPluginConfigurationClassResolver() |
59
|
3 |
|
->resolve(\get_class($applicationPlugin)) |
60
|
3 |
|
); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* {@inheritDoc} |
65
|
|
|
*/ |
66
|
3 |
|
protected function createPluginConfigurationClassResolver(): PluginConfigurationClassResolver |
67
|
|
|
{ |
68
|
3 |
|
return new PluginConfigurationClassResolver($this->applicationConfiguration); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|