From abf7403620e2fb935da3987b25572c6b0fc4b702 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20B=C3=B6sing?= <2189546+boesing@users.noreply.github.com> Date: Wed, 8 Apr 2020 14:46:33 +0200 Subject: [PATCH 1/3] Added `Storage\PluginAwareInterface` and `Storage\PluginCapableInterface` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As already mentioned in zendframework/zend-cache#177, I would like to add some more interfaces to avoid issues when implementing new adapters without the `AbstractAdapter`. Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com> --- src/Storage/Adapter/AbstractAdapter.php | 26 +-- src/Storage/PluginAwareInterface.php | 33 +++ src/Storage/PluginCapableInterface.php | 30 +++ src/StorageFactory.php | 22 +- ...erWithStorageAndEventsCapableInterface.php | 191 ++++++++++++++++++ test/StorageFactoryTest.php | 18 ++ 6 files changed, 294 insertions(+), 26 deletions(-) create mode 100644 src/Storage/PluginAwareInterface.php create mode 100644 src/Storage/PluginCapableInterface.php create mode 100644 test/Storage/Adapter/TestAsset/AdapterWithStorageAndEventsCapableInterface.php 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); + } } From 1d4857e3e794f9bbf50cf1f7333c4cb4edd728fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20B=C3=B6sing?= <2189546+boesing@users.noreply.github.com> Date: Mon, 20 Jul 2020 22:57:54 +0200 Subject: [PATCH 2/3] Fix upcoming minor version in deprecation message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com> --- src/StorageFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/StorageFactory.php b/src/StorageFactory.php index 2bf3c697..6c38fbcb 100644 --- a/src/StorageFactory.php +++ b/src/StorageFactory.php @@ -84,7 +84,7 @@ public static function factory($cfg) trigger_error(sprintf( 'Using "%s" to provide plugin capabilities to storage adapters is deprecated as of ' - . 'laminas-cache 2.9; please use "%s" instead', + . 'laminas-cache 2.10; please use "%s" instead', EventsCapableInterface::class, PluginAwareInterface::class ), E_USER_DEPRECATED); From eb0361bb66dbdfd4d3cf2f3c9f6bd06bde015c44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20B=C3=B6sing?= <2189546+boesing@users.noreply.github.com> Date: Tue, 6 Oct 2020 00:27:09 +0200 Subject: [PATCH 3/3] Added CHANGELOG entry MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com> --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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