Skip to content

Commit 76cc49a

Browse files
authored
Merge pull request #266 from rohm1/rfc/adapter-plugin-manager-config
Allow configuration of `AdapterPluginManager` via config file
2 parents a57a9d7 + 7b93996 commit 76cc49a

File tree

3 files changed

+34
-16
lines changed

3 files changed

+34
-16
lines changed

docs/bookdown.json

-15
This file was deleted.

src/ConfigProvider.php

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
class ConfigProvider
1818
{
19+
public const ADAPTER_PLUGIN_MANAGER_CONFIGURATION_KEY = 'storage_adapters';
20+
1921
/**
2022
* Return default configuration for laminas-cache.
2123
*
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,45 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Laminas\Cache\Service;
46

7+
use Laminas\Cache\ConfigProvider;
58
use Laminas\Cache\Storage\AdapterPluginManager;
9+
use Laminas\ServiceManager\ServiceManager;
610
use Psr\Container\ContainerInterface;
711

12+
use function is_array;
13+
14+
/**
15+
* @psalm-import-type ServiceManagerConfiguration from ServiceManager
16+
*/
817
final class StorageAdapterPluginManagerFactory
918
{
1019
public function __invoke(ContainerInterface $container): AdapterPluginManager
1120
{
12-
return new AdapterPluginManager($container);
21+
$pluginManager = new AdapterPluginManager($container);
22+
23+
// If we do not have a config service, nothing more to do
24+
if (! $container->has('config')) {
25+
return $pluginManager;
26+
}
27+
28+
$config = $container->get('config');
29+
30+
// If we do not have a configuration, nothing more to do
31+
if (
32+
! isset($config[ConfigProvider::ADAPTER_PLUGIN_MANAGER_CONFIGURATION_KEY])
33+
|| ! is_array($config[ConfigProvider::ADAPTER_PLUGIN_MANAGER_CONFIGURATION_KEY])
34+
) {
35+
return $pluginManager;
36+
}
37+
38+
// Wire service configuration
39+
/** @var ServiceManagerConfiguration $config */
40+
$config = $config[ConfigProvider::ADAPTER_PLUGIN_MANAGER_CONFIGURATION_KEY];
41+
$pluginManager->configure($config);
42+
43+
return $pluginManager;
1344
}
1445
}

0 commit comments

Comments
 (0)