Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow configuration of AdapterPluginManager via config file #266

Merged
merged 9 commits into from
Jul 31, 2023
15 changes: 0 additions & 15 deletions docs/bookdown.json

This file was deleted.

2 changes: 2 additions & 0 deletions src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

class ConfigProvider
{
public const ADAPTER_PLUGIN_MANAGER_CONFIGURATION_KEY = 'storage_adapters';

/**
* Return default configuration for laminas-cache.
*
Expand Down
33 changes: 32 additions & 1 deletion src/Service/StorageAdapterPluginManagerFactory.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,45 @@
<?php

declare(strict_types=1);

namespace Laminas\Cache\Service;

use Laminas\Cache\ConfigProvider;
use Laminas\Cache\Storage\AdapterPluginManager;
use Laminas\ServiceManager\ServiceManager;
use Psr\Container\ContainerInterface;

use function is_array;

/**
* @psalm-import-type ServiceManagerConfiguration from ServiceManager
*/
final class StorageAdapterPluginManagerFactory
{
public function __invoke(ContainerInterface $container): AdapterPluginManager
{
return new AdapterPluginManager($container);
$pluginManager = new AdapterPluginManager($container);

// If we do not have a config service, nothing more to do
if (! $container->has('config')) {
return $pluginManager;
}

$config = $container->get('config');

// If we do not have a configuration, nothing more to do
if (
! isset($config[ConfigProvider::ADAPTER_PLUGIN_MANAGER_CONFIGURATION_KEY])
|| ! is_array($config[ConfigProvider::ADAPTER_PLUGIN_MANAGER_CONFIGURATION_KEY])
) {
return $pluginManager;
}

// Wire service configuration
/** @var ServiceManagerConfiguration $config */
$config = $config[ConfigProvider::ADAPTER_PLUGIN_MANAGER_CONFIGURATION_KEY];
$pluginManager->configure($config);

return $pluginManager;
}
}