Skip to content

Commit

Permalink
Add template types, improving type inference for plugin manager imple…
Browse files Browse the repository at this point in the history
…mentations

Signed-off-by: George Steel <george@net-glue.co.uk>
gsteel committed Jul 12, 2022

Verified

This commit was signed with the committer’s verified signature.
gsteel George Steel
1 parent c6f8f09 commit ce93f59
Showing 2 changed files with 16 additions and 6 deletions.
11 changes: 8 additions & 3 deletions src/AdapterPluginManager.php
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@

namespace Laminas\Paginator;

use Laminas\Paginator\Adapter\AdapterInterface;
use Laminas\ServiceManager\AbstractPluginManager;
use Laminas\ServiceManager\Exception\InvalidServiceException;
use Laminas\ServiceManager\Factory\InvokableFactory;
@@ -23,8 +24,10 @@
* Plugin manager implementation for paginator adapters.
*
* Enforces that adapters retrieved are instances of
* Adapter\AdapterInterface. Additionally, it registers a number of default
* AdapterInterface. Additionally, it registers a number of default
* adapters available.
*
* @extends AbstractPluginManager<AdapterInterface>
*/
class AdapterPluginManager extends AbstractPluginManager
{
@@ -97,21 +100,22 @@ class AdapterPluginManager extends AbstractPluginManager
];

/** @var string */
protected $instanceOf = Adapter\AdapterInterface::class;
protected $instanceOf = AdapterInterface::class;

/**
* Validate that a plugin is an adapter (v3)
*
* @param mixed $instance
* @throws InvalidServiceException
* @psalm-assert AdapterInterface $instance
*/
public function validate($instance)
{
if (! $instance instanceof $this->instanceOf) {
throw new InvalidServiceException(sprintf(
'Plugin of type %s is invalid; must implement %s',
is_object($instance) ? get_class($instance) : gettype($instance),
Adapter\AdapterInterface::class
AdapterInterface::class
));
}
}
@@ -122,6 +126,7 @@ public function validate($instance)
* @param mixed $plugin
* @throws Exception\RuntimeException
* @return void
* @psalm-assert AdapterInterface $instance
*/
public function validatePlugin($plugin)
{
11 changes: 8 additions & 3 deletions src/ScrollingStylePluginManager.php
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@

namespace Laminas\Paginator;

use Laminas\Paginator\ScrollingStyle\ScrollingStyleInterface;
use Laminas\ServiceManager\AbstractPluginManager;
use Laminas\ServiceManager\Exception\InvalidServiceException;
use Laminas\ServiceManager\Factory\InvokableFactory;
@@ -21,8 +22,10 @@
* Plugin manager implementation for scrolling style adapters
*
* Enforces that adapters retrieved are instances of
* ScrollingStyle\ScrollingStyleInterface. Additionally, it registers a number
* ScrollingStyleInterface. Additionally, it registers a number
* of default adapters available.
*
* @extends AbstractPluginManager<ScrollingStyleInterface>
*/
class ScrollingStylePluginManager extends AbstractPluginManager
{
@@ -73,21 +76,22 @@ class ScrollingStylePluginManager extends AbstractPluginManager
];

/** @var string */
protected $instanceOf = ScrollingStyle\ScrollingStyleInterface::class;
protected $instanceOf = ScrollingStyleInterface::class;

/**
* Validate a plugin (v3)
*
* @param mixed $instance
* @throws InvalidServiceException
* @psalm-assert ScrollingStyleInterface $instance
*/
public function validate($instance)
{
if (! $instance instanceof $this->instanceOf) {
throw new InvalidServiceException(sprintf(
'Plugin of type %s is invalid; must implement %s',
is_object($instance) ? get_class($instance) : gettype($instance),
Adapter\AdapterInterface::class
ScrollingStyleInterface::class
));
}
}
@@ -98,6 +102,7 @@ public function validate($instance)
* @param mixed $plugin
* @throws Exception\InvalidArgumentException
* @return void
* @psalm-assert ScrollingStyleInterface $instance
*/
public function validatePlugin($plugin)
{

0 comments on commit ce93f59

Please sign in to comment.