Skip to content

Commit

Permalink
Merge pull request #266 from rohm1/rfc/adapter-plugin-manager-config
Browse files Browse the repository at this point in the history
Allow configuration of `AdapterPluginManager` via config file
  • Loading branch information
boesing committed Jul 31, 2023
2 parents a57a9d7 + 7b93996 commit 76cc49a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 16 deletions.
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;
}
}

0 comments on commit 76cc49a

Please sign in to comment.