diff --git a/composer.json b/composer.json index 0df46eb..be2f636 100644 --- a/composer.json +++ b/composer.json @@ -20,8 +20,8 @@ } }, "require": { - "php": ">=5.4", - "zendframework/zendframework": "~2.3|~3.0" + "php": ">=7.2", + "zendframework/zend-mvc": "^3.0" }, "autoload": { "psr-0": { diff --git a/src/Eye4web/Zf2Abac/Assertion/AssertionPluginManager.php b/src/Eye4web/Zf2Abac/Assertion/AssertionPluginManager.php index c2e6069..7be7797 100644 --- a/src/Eye4web/Zf2Abac/Assertion/AssertionPluginManager.php +++ b/src/Eye4web/Zf2Abac/Assertion/AssertionPluginManager.php @@ -7,18 +7,19 @@ class AssertionPluginManager extends AbstractPluginManager { - /** - * {@inheritDoc} - */ - public function validatePlugin($plugin) + protected $instanceOf = AssertionInterface::class; + + public function validate($instance) { - if ($plugin instanceof AssertionInterface) { + if (empty($this->instanceOf) || $instance instanceof $this->instanceOf) { return; } - throw new Exception\RunetimeException(sprintf( - 'Assertions must implement "Eye4web\Zf2Abac\Assertion\AssertionInterface", but "%s" was given', - is_object($plugin) ? get_class($plugin) : gettype($plugin) + throw new InvalidServiceException(sprintf( + 'Plugin manager "%s" expected an instance of type "%s", but "%s" was received', + __CLASS__, + $this->instanceOf, + is_object($instance) ? $instance::class : gettype($instance) )); } diff --git a/src/Eye4web/Zf2Abac/Factory/Assertion/AssertionPluginManagerFactory.php b/src/Eye4web/Zf2Abac/Factory/Assertion/AssertionPluginManagerFactory.php index 7ab32a8..a65043e 100644 --- a/src/Eye4web/Zf2Abac/Factory/Assertion/AssertionPluginManagerFactory.php +++ b/src/Eye4web/Zf2Abac/Factory/Assertion/AssertionPluginManagerFactory.php @@ -7,19 +7,19 @@ use Zend\ServiceManager\ServiceLocatorInterface; use Eye4web\Zf2Abac\Assertion\AssertionPluginManager; -class AssertionPluginManagerFactory implements FactoryInterface +class AssertionPluginManagerFactory implements \Zend\ServiceManager\Factory\FactoryInterface { /** * {@inheritDoc} * @return AssertionPluginManager */ - public function createService(ServiceLocatorInterface $serviceLocator) + public function __invoke(\Psr\Container\ContainerInterface $serviceLocator, $requestedName, array $options = null) { /** @var array $config */ $config = $serviceLocator->get('Config')['eye4web_abac']['assertion_manager']; - $pluginManager = new AssertionPluginManager(new Config($config)); - $pluginManager->setServiceLocator($serviceLocator); + $pluginManager = new AssertionPluginManager($serviceLocator, $config); + //$pluginManager->setServiceLocator($serviceLocator); return $pluginManager; } diff --git a/src/Eye4web/Zf2Abac/Factory/Mvc/Controller/Plugin/HasPermissionPluginFactory.php b/src/Eye4web/Zf2Abac/Factory/Mvc/Controller/Plugin/HasPermissionPluginFactory.php index e425c26..ba69610 100644 --- a/src/Eye4web/Zf2Abac/Factory/Mvc/Controller/Plugin/HasPermissionPluginFactory.php +++ b/src/Eye4web/Zf2Abac/Factory/Mvc/Controller/Plugin/HasPermissionPluginFactory.php @@ -8,12 +8,12 @@ use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; -class HasPermissionPluginFactory implements FactoryInterface +class HasPermissionPluginFactory implements \Zend\ServiceManager\Factory\FactoryInterface { - public function createService(ServiceLocatorInterface $pluginManager) + public function __invoke(\Psr\Container\ContainerInterface $pluginManager, $requestedName, array $options = null) { /** @var ServiceLocatorInterface $serviceLocator */ - $serviceLocator = $pluginManager->getServiceLocator(); + $serviceLocator = $pluginManager; /** @var AuthorizationServiceInterface $authorizationService */ $authorizationService = $serviceLocator->get('Eye4web\Zf2Abac\Service\AuthorizationService'); diff --git a/src/Eye4web/Zf2Abac/Factory/Provider/DoctrineORMProviderFactory.php b/src/Eye4web/Zf2Abac/Factory/Provider/DoctrineORMProviderFactory.php index 396bd54..9dc593c 100644 --- a/src/Eye4web/Zf2Abac/Factory/Provider/DoctrineORMProviderFactory.php +++ b/src/Eye4web/Zf2Abac/Factory/Provider/DoctrineORMProviderFactory.php @@ -9,13 +9,13 @@ use Doctrine\ORM\EntityManagerInterface; use Zend\Validator\ValidatorPluginManager; -class DoctrineORMProviderFactory implements FactoryInterface +class DoctrineORMProviderFactory implements \Zend\ServiceManager\Factory\FactoryInterface { /** * {@inheritDoc} * @return DoctrineORMProvider */ - public function createService(ServiceLocatorInterface $serviceLocator) + public function __invoke(\Psr\Container\ContainerInterface $serviceLocator, $requestedName, array $options = null) { /** @var EntityManagerInterface $objectManager */ $objectManager = $serviceLocator->get('Doctrine\ORM\EntityManager'); diff --git a/src/Eye4web/Zf2Abac/Factory/Service/AuthorizationServiceFactory.php b/src/Eye4web/Zf2Abac/Factory/Service/AuthorizationServiceFactory.php index 5d55bf0..e54e92a 100644 --- a/src/Eye4web/Zf2Abac/Factory/Service/AuthorizationServiceFactory.php +++ b/src/Eye4web/Zf2Abac/Factory/Service/AuthorizationServiceFactory.php @@ -6,7 +6,7 @@ use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; -class AuthorizationServiceFactory implements FactoryInterface +class AuthorizationServiceFactory implements \Zend\ServiceManager\Factory\FactoryInterface { /** * Offer service @@ -14,7 +14,7 @@ class AuthorizationServiceFactory implements FactoryInterface * @param ServiceLocatorInterface $serviceLocator * @return AuthorizationService */ - public function createService(ServiceLocatorInterface $serviceLocator) + public function __invoke(\Psr\Container\ContainerInterface $serviceLocator, $requestedName, array $options = null) { /* @var \Eye4web\Zf2Abac\Assertion\AssertionPluginManager $assertionPluginManager */ $assertionPluginManager = $serviceLocator->get('Eye4web\Zf2Abac\Assertion\AssertionPluginManager'); diff --git a/src/Eye4web/Zf2Abac/Factory/View/Helper/HasPermissionHelperFactory.php b/src/Eye4web/Zf2Abac/Factory/View/Helper/HasPermissionHelperFactory.php index c5e5bfd..7a80291 100644 --- a/src/Eye4web/Zf2Abac/Factory/View/Helper/HasPermissionHelperFactory.php +++ b/src/Eye4web/Zf2Abac/Factory/View/Helper/HasPermissionHelperFactory.php @@ -8,12 +8,12 @@ use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; -class HasPermissionHelperFactory implements FactoryInterface +class HasPermissionHelperFactory implements \Zend\ServiceManager\Factory\FactoryInterface { - public function createService(ServiceLocatorInterface $pluginManager) + public function __invoke(\Psr\Container\ContainerInterface $pluginManager, $requestedName, array $options = null) { /** @var ServiceLocatorInterface $serviceLocator */ - $serviceLocator = $pluginManager->getServiceLocator(); + $serviceLocator = $pluginManager; /** @var AuthorizationServiceInterface $authorizationService */ $authorizationService = $serviceLocator->get('Eye4web\Zf2Abac\Service\AuthorizationService'); diff --git a/src/Eye4web/Zf2Abac/Provider/DoctrineORMProvider.php b/src/Eye4web/Zf2Abac/Provider/DoctrineORMProvider.php index 8b41352..760fc4d 100644 --- a/src/Eye4web/Zf2Abac/Provider/DoctrineORMProvider.php +++ b/src/Eye4web/Zf2Abac/Provider/DoctrineORMProvider.php @@ -70,7 +70,7 @@ public function getValidator(PermissionInterface $permission) if (!$validator) { throw new Exception\ValidatorNotFound(sprintf( 'The validator \"%s\" could not be found', - is_object($validator) ? get_class($validator) : gettype($validator) + is_object($validator) ? $validator::class : gettype($validator) )); } @@ -81,7 +81,7 @@ public function getValidator(PermissionInterface $permission) if (!$options) { throw new Exception\RuntimeException(sprintf( 'The options for validator \"%s\" must be in json format', - is_object($validator) ? get_class($validator) : gettype($validator) + is_object($validator) ? $validator::class : gettype($validator) )); } diff --git a/src/Eye4web/Zf2Abac/Service/AuthorizationService.php b/src/Eye4web/Zf2Abac/Service/AuthorizationService.php index da7b22b..327573e 100644 --- a/src/Eye4web/Zf2Abac/Service/AuthorizationService.php +++ b/src/Eye4web/Zf2Abac/Service/AuthorizationService.php @@ -32,7 +32,7 @@ public function hasPermission($assertionName, $value, array $attributes) if (!$assertion) { throw new Exception\AssertionNotFound(sprintf( 'The assertion \"%s\" was not found', - is_object($assertion) ? get_class($assertion) : gettype($assertion) + is_object($assertion) ? $assertion::class : gettype($assertion) )); } diff --git a/test/Eye4web/Zf2AbacTest/Factory/Assertion/AssertionPluginManagerFactoryTest.php b/test/Eye4web/Zf2AbacTest/Factory/Assertion/AssertionPluginManagerFactoryTest.php index 9992271..d92f397 100644 --- a/test/Eye4web/Zf2AbacTest/Factory/Assertion/AssertionPluginManagerFactoryTest.php +++ b/test/Eye4web/Zf2AbacTest/Factory/Assertion/AssertionPluginManagerFactoryTest.php @@ -23,6 +23,6 @@ public function testFactory() $pluginManager = $factory->createService($serviceManager); $this->assertInstanceOf('Eye4web\Zf2Abac\Assertion\AssertionPluginManager', $pluginManager); - $this->assertSame($serviceManager, $pluginManager->getServiceLocator()); + $this->assertSame($serviceManager, $pluginManager); } }