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

Normalize adapter configuration #80

Closed
boesing opened this issue Apr 2, 2021 · 1 comment · Fixed by #104
Closed

Normalize adapter configuration #80

boesing opened this issue Apr 2, 2021 · 1 comment · Fixed by #104
Milestone

Comments

@boesing
Copy link
Member

boesing commented Apr 2, 2021

Feature Request

Q A
New Feature yes
BC Break yes (in 3.0)/no (in 2.x, just deprecating it)

Summary

Specify Adapter Configuration

There are multiple specifications of configurations in laminas-cache v2 to create an adapter with plugins and options.

These specifications are:

<?php

use Laminas\Cache\Storage\Adapter\Memory;
use Laminas\Cache\Storage\Plugin\IgnoreUserAbort;
use Laminas\Cache\StorageFactory;

StorageFactory::factory([
    'adapter' => 'memory',
    'options' => [],
    'plugins' => ['Serializer'],
]);

StorageFactory::factory([
    'adapter' => [
        'name' => Memory::class,
        'options' => [],
    ],
    'options' => [], // Yes! These are getting merged with those from `adapter.options` ...
    'plugins' => [
        IgnoreUserAbort::class => ['exitOnAbort' => true],
    ],
]);

StorageFactory::factory([
    'adapter' => Memory::class,
    'options' => [],
    'plugins' => [
        [
            'name' => IgnoreUserAbort::class,
            'options' => ['exitOnAbort' => true],
            'priority' => PHP_INT_MAX,
        ],
    ],
]);

In v3, we should limit the specification to one configuration which can be used with the upcoming StorageAdapterFactory.

use Laminas\Cache\Storage\Adapter\Memory;
use Laminas\Cache\Storage\Plugin\IgnoreUserAbort;

[
    'adapter' => Memory::class,
    'options' => [],
    'plugins' => [
        [
            'name' => IgnoreUserAbort::class,
            'options' => ['exitOnAbort' => true],
            'priority' => PHP_INT_MAX,
        ],
    ],
];

The psalm notation of this configuration would look like this:

/**
 * @psalm-type InternalOptionalPriorityConfigurationType = array{priority?:int}
 * @psalm-type InternalPluginArrayConfigurationType = array{name:string,options?:array<string,mixed>}
 * @psalm-type PluginArrayConfigurationWithPriorityType = InternalPluginArrayConfigurationType&InternalOptionalPriorityConfigurationType
 * @psalm-type StorageAdapterArrayConfigurationType = array{
 *     name: non-empty-string,
 *     options?: array<string,mixed>,
 *     plugins?: list<PluginArrayConfigurationWithPriorityType>
 * }
 */

To help users migrate their existing configurations, we might want to provide a laminas-cli command to migrate from the old structure to the new structure.

@boesing boesing added this to the 2.11.0 milestone Apr 2, 2021
@boesing boesing linked a pull request Apr 3, 2021 that will close this issue
@boesing boesing removed a link to a pull request Apr 3, 2021
@boesing boesing modified the milestones: 2.11.0, 2.12.0 Apr 29, 2021
@boesing boesing linked a pull request May 16, 2021 that will close this issue
@boesing
Copy link
Member Author

boesing commented May 16, 2021

Closed with #104

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant