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
Original file line number Diff line number Diff line change
Expand Up @@ -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.
rohm1 marked this conversation as resolved.
Show resolved Hide resolved

## 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`:
Expand Down
28 changes: 28 additions & 0 deletions docs/book/v3/storage/adapter-plugin-manager.md
Original file line number Diff line number Diff line change
@@ -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()`.
boesing marked this conversation as resolved.
Show resolved Hide resolved

## 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.
boesing marked this conversation as resolved.
Show resolved Hide resolved
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,
],
],
];
```
boesing marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions docs/bookdown.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"target": "html/",
"content": [
"book/laminas.cache.storage.adapter.md",
"book/laminas.cache.storage.adapter-plugin-manager.md",
rohm1 marked this conversation as resolved.
Show resolved Hide resolved
"book/laminas.cache.storage.capabilities.md",
"book/laminas.cache.storage.plugin.md",
"book/laminas.cache.pattern.md",
Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down