From 81d4af48851c13e486f955d1ea3f8eeaea273ab7 Mon Sep 17 00:00:00 2001 From: Romain Perez Date: Tue, 18 Jul 2023 14:59:05 +0200 Subject: [PATCH 1/9] #197 added config for AdapterPluginManager Signed-off-by: Romain Perez --- .../usage-in-a-laminas-mvc-application.md | 17 ++++++++++++++- .../StorageAdapterPluginManagerFactory.php | 21 ++++++++++++++++++- src/Storage/AdapterPluginManager.php | 2 ++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/docs/book/v3/application-integration/usage-in-a-laminas-mvc-application.md b/docs/book/v3/application-integration/usage-in-a-laminas-mvc-application.md index 68712387..eb0b02f4 100644 --- a/docs/book/v3/application-integration/usage-in-a-laminas-mvc-application.md +++ b/docs/book/v3/application-integration/usage-in-a-laminas-mvc-application.md @@ -37,7 +37,22 @@ return [ ]; ``` -The factory `Laminas\Cache\Service\StorageCacheAbstractServiceFactory` uses the configuration, searches for the configuration key `caches` and creates the storage adapters using the discovered configuration. +## Register a storage adapter + +To register additional storage adapters, use either application or module configuration (such as `config/autoload/*.global.php` or `module/Application/config/module.config.php`, respectively), and define the configuration key `storage_adapters`. + +In this example, the global configuration is used and a separate file is created for the storage adapters configuration. +Create a configuration file with name like `config/autoload/storage_adapters.global.php` and it will [automatically be included](https://docs.laminas.dev/tutorials/advanced-config/#environment-specific-application-configuration): + +```php +return [ + 'storage_adapters' => [ + 'factories' => [ + \My\Custom\Adapter::class => \My\Custom\AdapterFactory::class, + ], + ], +]; +``` ## Create Controller diff --git a/src/Service/StorageAdapterPluginManagerFactory.php b/src/Service/StorageAdapterPluginManagerFactory.php index c257ca42..1df5487c 100644 --- a/src/Service/StorageAdapterPluginManagerFactory.php +++ b/src/Service/StorageAdapterPluginManagerFactory.php @@ -1,5 +1,7 @@ has('config')) { + return $pluginManager; + } + + $config = $container->get('config'); + + // If we do not have a configuration, nothing more to do + if (! isset($config[AdapterPluginManager::CONFIGURATION_KEY]) || ! is_array($config[AdapterPluginManager::CONFIGURATION_KEY])) { + return $pluginManager; + } + + // Wire service configuration + $pluginManager->configure($config[AdapterPluginManager::CONFIGURATION_KEY]); + + return $pluginManager; } } diff --git a/src/Storage/AdapterPluginManager.php b/src/Storage/AdapterPluginManager.php index 2299f91a..0661a3cf 100644 --- a/src/Storage/AdapterPluginManager.php +++ b/src/Storage/AdapterPluginManager.php @@ -16,6 +16,8 @@ */ final class AdapterPluginManager extends AbstractPluginManager { + public const CONFIGURATION_KEY = 'storage_adapters'; + /** * Do not share by default * From 7b2fc83fda30dffd35b100e58b43469a01222ee4 Mon Sep 17 00:00:00 2001 From: Romain Perez Date: Tue, 18 Jul 2023 15:20:56 +0200 Subject: [PATCH 2/9] declare ServiceManagerConfiguration type for better psalm analyze Signed-off-by: Romain Perez --- src/Service/StorageAdapterPluginManagerFactory.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Service/StorageAdapterPluginManagerFactory.php b/src/Service/StorageAdapterPluginManagerFactory.php index 1df5487c..f9881b8f 100644 --- a/src/Service/StorageAdapterPluginManagerFactory.php +++ b/src/Service/StorageAdapterPluginManagerFactory.php @@ -5,8 +5,12 @@ namespace Laminas\Cache\Service; use Laminas\Cache\Storage\AdapterPluginManager; +use Laminas\ServiceManager\ServiceManager; use Psr\Container\ContainerInterface; +/** + * @psalm-import-type ServiceManagerConfiguration from ServiceManager + */ final class StorageAdapterPluginManagerFactory { public function __invoke(ContainerInterface $container): AdapterPluginManager @@ -26,7 +30,9 @@ public function __invoke(ContainerInterface $container): AdapterPluginManager } // Wire service configuration - $pluginManager->configure($config[AdapterPluginManager::CONFIGURATION_KEY]); + /** @var ServiceManagerConfiguration $config */ + $config = $config[AdapterPluginManager::CONFIGURATION_KEY]; + $pluginManager->configure($config); return $pluginManager; } From cd9d8197ec2184c4aec87b3fad4f5169deaa0021 Mon Sep 17 00:00:00 2001 From: Romain Perez Date: Tue, 18 Jul 2023 15:22:22 +0200 Subject: [PATCH 3/9] import function as required by phpcodesniffer Signed-off-by: Romain Perez --- src/Service/StorageAdapterPluginManagerFactory.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Service/StorageAdapterPluginManagerFactory.php b/src/Service/StorageAdapterPluginManagerFactory.php index f9881b8f..5010ad8c 100644 --- a/src/Service/StorageAdapterPluginManagerFactory.php +++ b/src/Service/StorageAdapterPluginManagerFactory.php @@ -8,6 +8,8 @@ use Laminas\ServiceManager\ServiceManager; use Psr\Container\ContainerInterface; +use function is_array; + /** * @psalm-import-type ServiceManagerConfiguration from ServiceManager */ From 0ee950bd73df69433507e6bfa0a0b0fa162c5f63 Mon Sep 17 00:00:00 2001 From: Romain Perez Date: Tue, 18 Jul 2023 15:24:18 +0200 Subject: [PATCH 4/9] move constant Signed-off-by: Romain Perez --- src/ConfigProvider.php | 2 ++ src/Service/StorageAdapterPluginManagerFactory.php | 5 +++-- src/Storage/AdapterPluginManager.php | 2 -- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index 1ca4acac..19fddb36 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -16,6 +16,8 @@ class ConfigProvider { + public const ADAPTER_PLUGIN_MANAGER_CONFIGURATION_KEY = 'storage_adapters'; + /** * Return default configuration for laminas-cache. * diff --git a/src/Service/StorageAdapterPluginManagerFactory.php b/src/Service/StorageAdapterPluginManagerFactory.php index 5010ad8c..cf611ec1 100644 --- a/src/Service/StorageAdapterPluginManagerFactory.php +++ b/src/Service/StorageAdapterPluginManagerFactory.php @@ -4,6 +4,7 @@ namespace Laminas\Cache\Service; +use Laminas\Cache\ConfigProvider; use Laminas\Cache\Storage\AdapterPluginManager; use Laminas\ServiceManager\ServiceManager; use Psr\Container\ContainerInterface; @@ -27,13 +28,13 @@ public function __invoke(ContainerInterface $container): AdapterPluginManager $config = $container->get('config'); // If we do not have a configuration, nothing more to do - if (! isset($config[AdapterPluginManager::CONFIGURATION_KEY]) || ! is_array($config[AdapterPluginManager::CONFIGURATION_KEY])) { + 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[AdapterPluginManager::CONFIGURATION_KEY]; + $config = $config[ConfigProvider::ADAPTER_PLUGIN_MANAGER_CONFIGURATION_KEY]; $pluginManager->configure($config); return $pluginManager; diff --git a/src/Storage/AdapterPluginManager.php b/src/Storage/AdapterPluginManager.php index 0661a3cf..2299f91a 100644 --- a/src/Storage/AdapterPluginManager.php +++ b/src/Storage/AdapterPluginManager.php @@ -16,8 +16,6 @@ */ final class AdapterPluginManager extends AbstractPluginManager { - public const CONFIGURATION_KEY = 'storage_adapters'; - /** * Do not share by default * From 17e2dc10e68284ef82155473e79538113e4fb038 Mon Sep 17 00:00:00 2001 From: Romain Perez Date: Tue, 18 Jul 2023 15:29:40 +0200 Subject: [PATCH 5/9] restore accidentally deleted doc Signed-off-by: Romain Perez --- .../usage-in-a-laminas-mvc-application.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/book/v3/application-integration/usage-in-a-laminas-mvc-application.md b/docs/book/v3/application-integration/usage-in-a-laminas-mvc-application.md index eb0b02f4..419f8733 100644 --- a/docs/book/v3/application-integration/usage-in-a-laminas-mvc-application.md +++ b/docs/book/v3/application-integration/usage-in-a-laminas-mvc-application.md @@ -37,6 +37,8 @@ return [ ]; ``` +The factory `Laminas\Cache\Service\StorageCacheAbstractServiceFactory` uses the configuration, searches for the configuration key `caches` and creates the storage adapters using the discovered configuration. + ## Register a storage adapter To register additional storage adapters, use either application or module configuration (such as `config/autoload/*.global.php` or `module/Application/config/module.config.php`, respectively), and define the configuration key `storage_adapters`. From 187c9031ebabf1a3babc9075fdebf2d0d058cb75 Mon Sep 17 00:00:00 2001 From: Romain Perez Date: Tue, 18 Jul 2023 15:29:52 +0200 Subject: [PATCH 6/9] phpcs Signed-off-by: Romain Perez --- src/Service/StorageAdapterPluginManagerFactory.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Service/StorageAdapterPluginManagerFactory.php b/src/Service/StorageAdapterPluginManagerFactory.php index cf611ec1..1e9535a3 100644 --- a/src/Service/StorageAdapterPluginManagerFactory.php +++ b/src/Service/StorageAdapterPluginManagerFactory.php @@ -28,7 +28,10 @@ public function __invoke(ContainerInterface $container): AdapterPluginManager $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])) { + if ( + ! isset($config[ConfigProvider::ADAPTER_PLUGIN_MANAGER_CONFIGURATION_KEY]) + || ! is_array($config[ConfigProvider::ADAPTER_PLUGIN_MANAGER_CONFIGURATION_KEY]) + ) { return $pluginManager; } From f6c614c38ff4bdb9de6f5545142830953f4ccbad Mon Sep 17 00:00:00 2001 From: Romain Perez Date: Wed, 19 Jul 2023 08:44:06 +0200 Subject: [PATCH 7/9] create docs for adapter plugin manager Signed-off-by: Romain Perez --- .../usage-in-a-laminas-mvc-application.md | 17 ----------- .../book/v3/storage/adapter-plugin-manager.md | 28 +++++++++++++++++++ docs/bookdown.json | 1 + mkdocs.yml | 1 + 4 files changed, 30 insertions(+), 17 deletions(-) create mode 100644 docs/book/v3/storage/adapter-plugin-manager.md diff --git a/docs/book/v3/application-integration/usage-in-a-laminas-mvc-application.md b/docs/book/v3/application-integration/usage-in-a-laminas-mvc-application.md index 419f8733..68712387 100644 --- a/docs/book/v3/application-integration/usage-in-a-laminas-mvc-application.md +++ b/docs/book/v3/application-integration/usage-in-a-laminas-mvc-application.md @@ -39,23 +39,6 @@ return [ The factory `Laminas\Cache\Service\StorageCacheAbstractServiceFactory` uses the configuration, searches for the configuration key `caches` and creates the storage adapters using the discovered configuration. -## Register a storage adapter - -To register additional storage adapters, use either application or module configuration (such as `config/autoload/*.global.php` or `module/Application/config/module.config.php`, respectively), and define the configuration key `storage_adapters`. - -In this example, the global configuration is used and a separate file is created for the storage adapters configuration. -Create a configuration file with name like `config/autoload/storage_adapters.global.php` and it will [automatically be included](https://docs.laminas.dev/tutorials/advanced-config/#environment-specific-application-configuration): - -```php -return [ - 'storage_adapters' => [ - 'factories' => [ - \My\Custom\Adapter::class => \My\Custom\AdapterFactory::class, - ], - ], -]; -``` - ## Create Controller [Create a controller class](https://docs.laminas.dev/laminas-mvc/quick-start/#create-a-controller) and inject the cache with the interface for all cache storage adapters via the constructor, e.g. `module/Application/Controller/IndexController.php`: diff --git a/docs/book/v3/storage/adapter-plugin-manager.md b/docs/book/v3/storage/adapter-plugin-manager.md new file mode 100644 index 00000000..a615245f --- /dev/null +++ b/docs/book/v3/storage/adapter-plugin-manager.md @@ -0,0 +1,28 @@ +# Adapter Plugin Manager + +The `AdapterPluginManager` extends the laminas-servicemanager `AbstractPluginManager`, and has the following behaviors: + +- It will only return `Laminas\Cache\Storage\StorageInterface` instances. +- All services are not shared by default; a new instance will be created each time you call `get()`. + +## Factory + +`Laminas\Cache\Storage\AdapterPluginManager` is mapped to the factory `Laminas\Cache\Service\StorageAdapterPluginManagerFactory` when wired to the dependency injection container. + +The factory will be automatically registered when loading/installing the `Laminas\Cache` module in `laminas-mvc` and/or loading/installing the `ConfigProvider` into a Mezzio application. + +Since version 3.11.0, the factory will look for the `config` service, and use the `storage_adapters` configuration key to seed it with additional services. +This configuration key should map to an array that follows [standard laminas-servicemanager configuration](https://docs.laminas.dev/laminas-servicemanager/configuring-the-service-manager/). + +To add your own storage adapter you can add the following configuration: + +```php +// config/autoload/storage_adapters.global.php +return [ + 'storage_adapters' => [ + 'factories' => [ + \App\MyCustomStorageAdapter::class => \App\Container\MyCustomStorageAdapterFactory::class, + ], + ], +]; +``` diff --git a/docs/bookdown.json b/docs/bookdown.json index 12e8548a..f85f740e 100644 --- a/docs/bookdown.json +++ b/docs/bookdown.json @@ -3,6 +3,7 @@ "target": "html/", "content": [ "book/laminas.cache.storage.adapter.md", + "book/laminas.cache.storage.adapter-plugin-manager.md", "book/laminas.cache.storage.capabilities.md", "book/laminas.cache.storage.plugin.md", "book/laminas.cache.pattern.md", diff --git a/mkdocs.yml b/mkdocs.yml index 79b5402c..15aa6230 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -6,6 +6,7 @@ nav: - Installation: v3/installation.md - Storage: - Adapters: v3/storage/adapter.md + - "Adapter Plugin Manager": v3/storage/adapter-plugin-manager.md - Capabilities: v3/storage/capabilities.md - Plugins: v3/storage/plugin.md - "Cache Patterns": From 349027a0f2f5fe48dbffd772f2611ab90874fd37 Mon Sep 17 00:00:00 2001 From: Romain Perez Date: Thu, 20 Jul 2023 11:02:49 +0200 Subject: [PATCH 8/9] remove old bookdown file Signed-off-by: Romain Perez --- docs/bookdown.json | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 docs/bookdown.json diff --git a/docs/bookdown.json b/docs/bookdown.json deleted file mode 100644 index f85f740e..00000000 --- a/docs/bookdown.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "title": "Laminas\\Cache", - "target": "html/", - "content": [ - "book/laminas.cache.storage.adapter.md", - "book/laminas.cache.storage.adapter-plugin-manager.md", - "book/laminas.cache.storage.capabilities.md", - "book/laminas.cache.storage.plugin.md", - "book/laminas.cache.pattern.md", - "book/laminas.cache.pattern.callback-cache.md", - "book/laminas.cache.pattern.object-cache.md", - "book/laminas.cache.pattern.output-cache.md", - "book/laminas.cache.pattern.capture-cache.md", - "book/laminas.cache.psr.cacheitempooladapter.md" - ] -} From 7b93996c8925127139f8248daf2ad03a75d35f3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20B=C3=B6sing?= <2189546+boesing@users.noreply.github.com> Date: Mon, 31 Jul 2023 12:22:49 +0200 Subject: [PATCH 9/9] docs: drop documentation for the plugin manager configuration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Frank will provide a more detailed configuration for mezzio/MVC/non-laminas applications in the future and thus, we drop this documentation as it does not provide a benefit for endusers. Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com> --- .../book/v3/storage/adapter-plugin-manager.md | 28 ------------------- mkdocs.yml | 1 - 2 files changed, 29 deletions(-) delete mode 100644 docs/book/v3/storage/adapter-plugin-manager.md diff --git a/docs/book/v3/storage/adapter-plugin-manager.md b/docs/book/v3/storage/adapter-plugin-manager.md deleted file mode 100644 index a615245f..00000000 --- a/docs/book/v3/storage/adapter-plugin-manager.md +++ /dev/null @@ -1,28 +0,0 @@ -# Adapter Plugin Manager - -The `AdapterPluginManager` extends the laminas-servicemanager `AbstractPluginManager`, and has the following behaviors: - -- It will only return `Laminas\Cache\Storage\StorageInterface` instances. -- All services are not shared by default; a new instance will be created each time you call `get()`. - -## Factory - -`Laminas\Cache\Storage\AdapterPluginManager` is mapped to the factory `Laminas\Cache\Service\StorageAdapterPluginManagerFactory` when wired to the dependency injection container. - -The factory will be automatically registered when loading/installing the `Laminas\Cache` module in `laminas-mvc` and/or loading/installing the `ConfigProvider` into a Mezzio application. - -Since version 3.11.0, the factory will look for the `config` service, and use the `storage_adapters` configuration key to seed it with additional services. -This configuration key should map to an array that follows [standard laminas-servicemanager configuration](https://docs.laminas.dev/laminas-servicemanager/configuring-the-service-manager/). - -To add your own storage adapter you can add the following configuration: - -```php -// config/autoload/storage_adapters.global.php -return [ - 'storage_adapters' => [ - 'factories' => [ - \App\MyCustomStorageAdapter::class => \App\Container\MyCustomStorageAdapterFactory::class, - ], - ], -]; -``` diff --git a/mkdocs.yml b/mkdocs.yml index 15aa6230..79b5402c 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -6,7 +6,6 @@ nav: - Installation: v3/installation.md - Storage: - Adapters: v3/storage/adapter.md - - "Adapter Plugin Manager": v3/storage/adapter-plugin-manager.md - Capabilities: v3/storage/capabilities.md - Plugins: v3/storage/plugin.md - "Cache Patterns":