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

Added PluginAwareInterface and marked EventsCapableInterface as deprecated #177

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 6 additions & 19 deletions src/Storage/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@
use Zend\Cache\Storage\Event;
use Zend\Cache\Storage\ExceptionEvent;
use Zend\Cache\Storage\Plugin;
use Zend\Cache\Storage\PluginAwareInterface;
use Zend\Cache\Storage\PostEvent;
use Zend\Cache\Storage\StorageInterface;
use Zend\EventManager\EventManager;
use Zend\EventManager\EventManagerInterface;
use Zend\EventManager\EventsCapableInterface;

abstract class AbstractAdapter implements StorageInterface, EventsCapableInterface
abstract class AbstractAdapter implements StorageInterface, PluginAwareInterface
{
/**
* The used EventManager if any
Expand Down Expand Up @@ -253,10 +254,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)
{
Expand All @@ -265,12 +263,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)
{
Expand All @@ -289,11 +282,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)
{
Expand All @@ -306,9 +295,7 @@ public function removePlugin(Plugin\PluginInterface $plugin)
}

/**
* Return registry of plugins
*
* @return SplObjectStorage
* {@inheritdoc}
*/
public function getPluginRegistry()
{
Expand Down
34 changes: 34 additions & 0 deletions src/Storage/PluginAwareInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Cache\Storage;

use Zend\Cache\Exception;

interface PluginAwareInterface extends PluginCapableInterface
{
/**
* Register a plugin
*
* @param Plugin\PluginInterface $plugin
* @param int $priority
* @return StorageInterface
* @throws Exception\LogicException
*/
public function addPlugin(Plugin\PluginInterface $plugin, $priority = 1);

/**
* Unregister an already registered plugin
*
* @param Plugin\PluginInterface $plugin
* @return StorageInterface
* @throws Exception\LogicException
*/
public function removePlugin(Plugin\PluginInterface $plugin);
}
31 changes: 31 additions & 0 deletions src/Storage/PluginCapableInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Cache\Storage;

use SplObjectStorage;
use Zend\EventManager\EventsCapableInterface;

interface PluginCapableInterface extends EventsCapableInterface
{
/**
* Check if a plugin is registered
*
* @param Plugin\PluginInterface $plugin
* @return bool
*/
public function hasPlugin(Plugin\PluginInterface $plugin);

/**
* Return registry of plugins
*
* @return SplObjectStorage
*/
public function getPluginRegistry();
}
25 changes: 18 additions & 7 deletions src/StorageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
namespace Zend\Cache;

use Traversable;
use Zend\Cache\Storage\PluginAwareInterface;
use Zend\EventManager\EventsCapableInterface;
use Zend\Stdlib\ArrayUtils;
use Zend\ServiceManager\ServiceManager;
use Zend\Stdlib\ArrayUtils;
use const E_USER_DEPRECATED;

abstract class StorageFactory
{
Expand Down Expand Up @@ -73,12 +75,21 @@ public static function factory($cfg)

// add plugins
if (isset($cfg['plugins'])) {
if (! $adapter instanceof EventsCapableInterface) {
throw new Exception\RuntimeException(sprintf(
"The adapter '%s' doesn't implement '%s' and therefore can't handle plugins",
get_class($adapter),
'Zend\EventManager\EventsCapableInterface'
));
if (! $adapter instanceof PluginAwareInterface) {
if (! $adapter instanceof EventsCapableInterface) {
throw new Exception\RuntimeException(sprintf(
"The adapter '%s' doesn't implement '%s' and therefore can't handle plugins",
get_class($adapter),
EventsCapableInterface::class
));
}

trigger_error(sprintf(
'Using "%s" to provide plugin capabilities to storage adapters is deprecated as of '
. 'zendframework 2.9; please use "%s" instead',
EventsCapableInterface::class,
PluginAwareInterface::class
), E_USER_DEPRECATED);
}

if (! is_array($cfg['plugins'])) {
Expand Down
Loading