diff --git a/CHANGELOG.md b/CHANGELOG.md index 0fb7c4a2..50054aa3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file, in reverse ### Added +- [#21](https://github.com/laminas/laminas-cache/pull/21) Adds new `PluginAwareInterface` and `PluginCapableInterface` to provide better typehinting against plugin capable storage adapters - [#40](https://github.com/laminas/laminas-cache/pull/40) Adds installation instructions to documentation. ### Changed @@ -14,7 +15,7 @@ All notable changes to this project will be documented in this file, in reverse ### Deprecated -- Nothing. +- [#21](https://github.com/laminas/laminas-cache/pull/21) In case the `StorageFactory` has to create a custom `StorageAdapterInterface` implementation which does not extend the `AbstractAdapter`, the factory will trigger a deprecation message due to the missing `PluginAwareInterface` implementation when a `plugins` configuration was provided. ### Removed diff --git a/src/Storage/Adapter/AbstractAdapter.php b/src/Storage/Adapter/AbstractAdapter.php index b3c213fb..1675a766 100644 --- a/src/Storage/Adapter/AbstractAdapter.php +++ b/src/Storage/Adapter/AbstractAdapter.php @@ -14,16 +14,16 @@ use Laminas\Cache\Storage\Event; use Laminas\Cache\Storage\ExceptionEvent; use Laminas\Cache\Storage\Plugin; +use Laminas\Cache\Storage\PluginAwareInterface; use Laminas\Cache\Storage\PostEvent; use Laminas\Cache\Storage\StorageInterface; use Laminas\EventManager\EventManager; use Laminas\EventManager\EventManagerInterface; -use Laminas\EventManager\EventsCapableInterface; use SplObjectStorage; use stdClass; use Traversable; -abstract class AbstractAdapter implements StorageInterface, EventsCapableInterface +abstract class AbstractAdapter implements StorageInterface, PluginAwareInterface { /** * The used EventManager if any @@ -252,10 +252,7 @@ protected function triggerException($eventName, ArrayObject $args, & $result, \E } /** - * Check if a plugin is registered - * - * @param Plugin\PluginInterface $plugin - * @return bool + * {@inheritdoc} */ public function hasPlugin(Plugin\PluginInterface $plugin) { @@ -264,12 +261,7 @@ public function hasPlugin(Plugin\PluginInterface $plugin) } /** - * Register a plugin - * - * @param Plugin\PluginInterface $plugin - * @param int $priority - * @return AbstractAdapter Provides a fluent interface - * @throws Exception\LogicException + * {@inheritdoc} */ public function addPlugin(Plugin\PluginInterface $plugin, $priority = 1) { @@ -288,11 +280,7 @@ public function addPlugin(Plugin\PluginInterface $plugin, $priority = 1) } /** - * Unregister an already registered plugin - * - * @param Plugin\PluginInterface $plugin - * @return AbstractAdapter Provides a fluent interface - * @throws Exception\LogicException + * {@inheritdoc} */ public function removePlugin(Plugin\PluginInterface $plugin) { @@ -305,9 +293,7 @@ public function removePlugin(Plugin\PluginInterface $plugin) } /** - * Return registry of plugins - * - * @return SplObjectStorage + * {@inheritdoc} */ public function getPluginRegistry() { diff --git a/src/Storage/PluginAwareInterface.php b/src/Storage/PluginAwareInterface.php new file mode 100644 index 00000000..9d8d3870 --- /dev/null +++ b/src/Storage/PluginAwareInterface.php @@ -0,0 +1,33 @@ +prophesize(Cache\Storage\AdapterPluginManager::class); + + $adapters->get('Foo')->willReturn(new AdapterWithStorageAndEventsCapableInterface()); + + Cache\StorageFactory::setAdapterPluginManager($adapters->reveal()); + ErrorHandler::start(E_USER_DEPRECATED); + + Cache\StorageFactory::factory(['adapter' => 'Foo', 'plugins' => ['IgnoreUserAbort']]); + + $stack = ErrorHandler::stop(); + $this->assertInstanceOf(ErrorException::class, $stack); + } }