1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/** |
3
|
|
|
* This file is part of the daikon-cqrs/boot project. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Daikon\Boot\Service\Provisioner; |
10
|
|
|
|
11
|
|
|
use Auryn\Injector; |
12
|
|
|
use Daikon\Boot\Service\ServiceDefinitionInterface; |
13
|
|
|
use Daikon\Config\ConfigProviderInterface; |
14
|
|
|
use Daikon\Dbal\Connector\ConnectorMap; |
15
|
|
|
use Daikon\Dbal\Storage\StorageAdapterMap; |
16
|
|
|
use Daikon\Interop\Assertion; |
17
|
|
|
|
18
|
|
|
final class StorageAdapterMapProvisioner implements ProvisionerInterface |
19
|
|
|
{ |
20
|
|
|
public function provision( |
21
|
|
|
Injector $injector, |
22
|
|
|
ConfigProviderInterface $configProvider, |
23
|
|
|
ServiceDefinitionInterface $serviceDefinition |
24
|
|
|
): void { |
25
|
|
|
$adapterConfigs = (array)$configProvider->get('databases.storage_adapters', []); |
26
|
|
|
$factory = function (ConnectorMap $connectorMap) use ($injector, $adapterConfigs): StorageAdapterMap { |
27
|
|
|
$adapters = []; |
28
|
|
|
foreach ($adapterConfigs as $adapterKey => $adapterConfigs) { |
29
|
|
|
Assertion::keyNotExists($adapters, $adapterKey, "Storage adapter '$adapterKey' is already defined."); |
30
|
|
|
$adapters[$adapterKey] = $injector->make( |
31
|
|
|
$adapterConfigs['class'], |
32
|
|
|
[ |
33
|
|
|
':connector' => $connectorMap->get($adapterConfigs['connector']), |
34
|
|
|
':settings' => $adapterConfigs['settings'] ?? [] |
35
|
|
|
] |
36
|
|
|
); |
37
|
|
|
} |
38
|
|
|
return new StorageAdapterMap($adapters); |
39
|
|
|
}; |
40
|
|
|
|
41
|
|
|
$injector |
42
|
|
|
->share(StorageAdapterMap::class) |
43
|
|
|
->delegate(StorageAdapterMap::class, $factory); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|