Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Allow standalone usage as a component #94

Merged

Conversation

weierophinney
Copy link
Member

This patch accomplishes a number of tasks in order to better faciliate usage of the package as a standalone component, in both Expressive and zend-mvc applications. Specifically:

  • Updates the PatternPluginManager to accept $options, cast them to PatternOptions instances, and inject them in created plugins. Doing so allows moving that logic out of the PatternFactory, and better facilitates re-use of the plugin manager.
  • Updates the StorageCacheFactory and StorageCacheAbstractServiceFactory to seed the StorageFactory with plugin manager/adapter plugin manager instances pulled from the container provided at invocation, if available (falling back to creating new instances with the provided container as the parent container).
  • Adds factories for each of the plugin managers (pattern plugins, storage plugins, and storage adapter plugins).

These last two changes allow configuring plugin managers with custom plugins, which then become available to the cache storage when requested.

Finally, this patch adds:

  • Zend\Cache\ConfigProvider, which maps the abstract service factory and all plugin managers by default.
  • Zend\Cache\Module, which does the same, but for zend-mvc contexts.

These changes are backwards compatible, but will make the component a better citizen of zend-mvc v3 and Expressive applications.

The various pattern classes require that options are passed as a
`PatternOptions` instance, which is something `PatternFactory` currently
does, but which makes the plugin manager useless standalone. This patch
updates the plugin manager: on detection of a non-empty `$options`
argument, it will call `setOptions()` on the returned plugin, after
first casting `$options` to a `PatternOptions` instance.

PatternFactory was updated to cast `PatternOptions` to an array, and then pass
`$options` to the plugin manager when retrieving a pattern plugin.
To allow using custom plugins and adapters in a re-usable way, the
StorageCacheFactory and StorageCacheAbstractServiceFactory should not
use default instances, but allow using services associated with each.

This patch introduces the PluginManagerLookupTrait, which has methods
for seeding the StorageFactory with plugin manager instances. If the
services exist for either, the service is retrieved from the container;
otherwise, a default instance is created, using the application
container as the parent/creation context.

Tests were added to verify the behavior.
All new factories are in the `Zend\Cache\Service` namespace, and map as
follows:

- `PatternPluginManagerFactory` => `Zend\Cache\PatternPluginManager`
- `StoragePluginManagerFactory` => `Zend\Cache\Storage\PluginManager`
- `StorageAdapterPluginManagerFactory` => `Zend\Cache\Storage\AdapterPluginManager`
Added:

- `ConfigProvider`, which enables the
  `StorageCacheAbstractServiceFactory` by default, as well as maps new
  entries for the `PatternPluginManager`, storage `PluginManager`, and
  storage `AdapterPluginManager`.
- `Module`, which does the same as the above, but in a zend-mvc context.
@weierophinney weierophinney added this to the 2.7.0 milestone Apr 11, 2016
@weierophinney
Copy link
Member Author

@marc-mabe This is part of the ZF3 initiative. We're setting up components to be installed individually, and zend-component-installer will then register them as modules in zend-mvc applications, or within the config merger in Expressive applications. By doing so, developers will not need to manually register default factory configuration, simplifying documentation and setup.

If you're okay with this, I'll merge and tag a new 2.7.0 release, which will also include the APCu changes you've already merged.

@weierophinney weierophinney merged commit b1fc99f into zendframework:develop Apr 12, 2016
weierophinney added a commit that referenced this pull request Apr 12, 2016
weierophinney added a commit that referenced this pull request Apr 12, 2016
@weierophinney weierophinney deleted the feature/config-provider branch April 12, 2016 15:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant