-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #266 from rohm1/rfc/adapter-plugin-manager-config
Allow configuration of `AdapterPluginManager` via config file
- Loading branch information
Showing
3 changed files
with
34 additions
and
16 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |