Skip to content
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
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
17 changes: 9 additions & 8 deletions src/Eye4web/Zf2Abac/Assertion/AssertionPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class AuthorizationServiceFactory implements FactoryInterface
class AuthorizationServiceFactory implements \Zend\ServiceManager\Factory\FactoryInterface
{
/**
* Offer service
*
* @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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions src/Eye4web/Zf2Abac/Provider/DoctrineORMProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
));
}

Expand All @@ -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)
));
}

Expand Down
2 changes: 1 addition & 1 deletion src/Eye4web/Zf2Abac/Service/AuthorizationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}