Skip to content
Snippets Groups Projects
Commit 46d33288 authored by Demian Katz's avatar Demian Katz
Browse files

Changed AbstractPluginManager interface to eliminate need to override constructor in child classes.

parent eeaa3918
No related merge requests found
...@@ -40,8 +40,6 @@ use Zend\ServiceManager\AbstractPluginManager as Base, ...@@ -40,8 +40,6 @@ use Zend\ServiceManager\AbstractPluginManager as Base,
*/ */
abstract class AbstractPluginManager extends Base abstract class AbstractPluginManager extends Base
{ {
protected $expectedInterface;
/** /**
* Validate the plugin * Validate the plugin
* *
...@@ -55,11 +53,20 @@ abstract class AbstractPluginManager extends Base ...@@ -55,11 +53,20 @@ abstract class AbstractPluginManager extends Base
*/ */
public function validatePlugin($plugin) public function validatePlugin($plugin)
{ {
if (!($plugin instanceof $this->expectedInterface)) { $expectedInterface = $this->getExpectedInterface();
if (!($plugin instanceof $expectedInterface)) {
throw new ServiceManagerRuntimeException( throw new ServiceManagerRuntimeException(
'Plugin ' . get_class($plugin) . ' does not belong to ' 'Plugin ' . get_class($plugin) . ' does not belong to '
. $this->expectedInterface . $expectedInterface
); );
} }
} }
/**
* Return the name of the base class or interface that plug-ins must conform
* to.
*
* @return string
*/
abstract protected function getExpectedInterface();
} }
\ No newline at end of file
...@@ -40,16 +40,13 @@ use Zend\ServiceManager\ConfigInterface; ...@@ -40,16 +40,13 @@ use Zend\ServiceManager\ConfigInterface;
class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager
{ {
/** /**
* Constructor * Return the name of the base class or interface that plug-ins must conform
* to.
* *
* Add a default initializer to ensure the plugin is valid after instance * @return string
* creation.
*
* @param null|ConfigInterface $configuration Configuration
*/ */
public function __construct(ConfigInterface $configuration = null) protected function getExpectedInterface()
{ {
$this->expectedInterface = 'Zend\Session\SaveHandler\SaveHandlerInterface'; return 'Zend\Session\SaveHandler\SaveHandlerInterface';
parent::__construct($configuration);
} }
} }
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment