diff --git a/src/Assertion/AssertionPluginManagerFactory.php b/src/Assertion/AssertionPluginManagerFactory.php new file mode 100644 index 00000000..32189c88 --- /dev/null +++ b/src/Assertion/AssertionPluginManagerFactory.php @@ -0,0 +1,44 @@ +get('Config')['lmc_rbac']['assertion_manager']; + + return new AssertionPluginManager($container, $config); + } +} diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index b65b6f10..c2b44109 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -20,18 +20,18 @@ public function getDependencies(): array return [ 'factories' => [ /* Factories that do not map to a class */ - 'LmcRbacMvc\Guards' => \LmcRbacMvc\Factory\GuardsFactory::class, + 'LmcRbacMvc\Guards' => \LmcRbacMvc\Guard\GuardsFactory::class, /* Factories that map to a class */ - \LmcRbacMvc\Assertion\AssertionPluginManager::class => \LmcRbacMvc\Factory\AssertionPluginManagerFactory::class, - \LmcRbacMvc\Guard\GuardPluginManager::class => \LmcRbacMvc\Factory\GuardPluginManagerFactory::class, - \LmcRbacMvc\Identity\AuthenticationIdentityProvider::class => \LmcRbacMvc\Factory\AuthenticationIdentityProviderFactory::class, - \LmcRbacMvc\Options\ModuleOptions::class => \LmcRbacMvc\Factory\ModuleOptionsFactory::class, - \LmcRbacMvc\Role\RoleProviderPluginManager::class => \LmcRbacMvc\Factory\RoleProviderPluginManagerFactory::class, - \LmcRbacMvc\Service\AuthorizationService::class => \LmcRbacMvc\Factory\AuthorizationServiceFactory::class, - \LmcRbacMvc\Service\RoleService::class => \LmcRbacMvc\Factory\RoleServiceFactory::class, - \LmcRbacMvc\View\Strategy\RedirectStrategy::class => \LmcRbacMvc\Factory\RedirectStrategyFactory::class, - \LmcRbacMvc\View\Strategy\UnauthorizedStrategy::class => \LmcRbacMvc\Factory\UnauthorizedStrategyFactory::class, + \LmcRbacMvc\Assertion\AssertionPluginManager::class => \LmcRbacMvc\Assertion\AssertionPluginManagerFactory::class, + \LmcRbacMvc\Guard\GuardPluginManager::class => \LmcRbacMvc\Guard\GuardPluginManagerFactory::class, + \LmcRbacMvc\Identity\AuthenticationIdentityProvider::class => \LmcRbacMvc\Identity\AuthenticationIdentityProviderFactory::class, + \LmcRbacMvc\Options\ModuleOptions::class => \LmcRbacMvc\Options\ModuleOptionsFactory::class, + \LmcRbacMvc\Role\RoleProviderPluginManager::class => \LmcRbacMvc\Role\RoleProviderPluginManagerFactory::class, + \LmcRbacMvc\Service\AuthorizationService::class => \LmcRbacMvc\Service\AuthorizationServiceFactory::class, + \LmcRbacMvc\Service\RoleService::class => \LmcRbacMvc\Service\RoleServiceFactory::class, + \LmcRbacMvc\View\Strategy\RedirectStrategy::class => \LmcRbacMvc\View\Strategy\RedirectStrategyFactory::class, + \LmcRbacMvc\View\Strategy\UnauthorizedStrategy::class => \LmcRbacMvc\View\Strategy\UnauthorizedStrategyFactory::class, ], ]; } @@ -54,7 +54,7 @@ public function getControllerPluginConfig(): array { return [ 'factories' => [ - \LmcRbacMvc\Mvc\Controller\Plugin\IsGranted::class => \LmcRbacMvc\Factory\IsGrantedPluginFactory::class, + \LmcRbacMvc\Mvc\Controller\Plugin\IsGranted::class => \LmcRbacMvc\Mvc\Controller\Plugin\IsGrantedPluginFactory::class, ], 'aliases' => [ 'isGranted' => \LmcRbacMvc\Mvc\Controller\Plugin\IsGranted::class, @@ -66,8 +66,8 @@ public function getViewHelperConfig(): array { return [ 'factories' => [ - \LmcRbacMvc\View\Helper\IsGranted::class => \LmcRbacMvc\Factory\IsGrantedViewHelperFactory::class, - \LmcRbacMvc\View\Helper\HasRole::class => \LmcRbacMvc\Factory\HasRoleViewHelperFactory::class, + \LmcRbacMvc\View\Helper\IsGranted::class => \LmcRbacMvc\View\Helper\IsGrantedViewHelperFactory::class, + \LmcRbacMvc\View\Helper\HasRole::class => \LmcRbacMvc\View\Helper\HasRoleViewHelperFactory::class, ], 'aliases' => [ 'isGranted' => \LmcRbacMvc\View\Helper\IsGranted::class, diff --git a/src/Factory/AssertionPluginManagerFactory.php b/src/Factory/AssertionPluginManagerFactory.php index a389e97a..d591f8a2 100644 --- a/src/Factory/AssertionPluginManagerFactory.php +++ b/src/Factory/AssertionPluginManagerFactory.php @@ -18,27 +18,13 @@ namespace LmcRbacMvc\Factory; -use Psr\Container\ContainerInterface; -use Laminas\ServiceManager\Config; -use Laminas\ServiceManager\Factory\FactoryInterface; -use Laminas\ServiceManager\ServiceLocatorInterface; -use LmcRbacMvc\Assertion\AssertionPluginManager; - /** * Factory to create a assertion plugin manager * * @author Aeneas Rekkas * @license MIT + * @deprecated Replaced by \LmcRbacMvc\Assertion\AssertionPluginManagerFactory */ -class AssertionPluginManagerFactory implements FactoryInterface +class AssertionPluginManagerFactory extends \LmcRbacMvc\Assertion\AssertionPluginManagerFactory { - /** - * {@inheritDoc} - */ - public function __invoke(ContainerInterface $container, $requestedName, array $options = null): AssertionPluginManager - { - $config = $container->get('Config')['lmc_rbac']['assertion_manager']; - - return new AssertionPluginManager($container, $config); - } } diff --git a/src/Factory/AuthenticationIdentityProviderFactory.php b/src/Factory/AuthenticationIdentityProviderFactory.php index 984801b8..abc2ec87 100644 --- a/src/Factory/AuthenticationIdentityProviderFactory.php +++ b/src/Factory/AuthenticationIdentityProviderFactory.php @@ -18,28 +18,13 @@ namespace LmcRbacMvc\Factory; -use Psr\Container\ContainerInterface; -use Laminas\Authentication\AuthenticationService; -use Laminas\ServiceManager\Factory\FactoryInterface; -use Laminas\ServiceManager\ServiceLocatorInterface; -use LmcRbacMvc\Identity\AuthenticationIdentityProvider; - /** * Factory to create the authentication identity provider * * @author Michaël Gallego * @license MIT + * @deprecated Replaced by \LmcRbacMvc\Identity\AuthenticationIdentityProvider */ -class AuthenticationIdentityProviderFactory implements FactoryInterface +class AuthenticationIdentityProviderFactory extends \LmcRbacMvc\Identity\AuthenticationIdentityProvider { - /** - * {@inheritDoc} - */ - public function __invoke(ContainerInterface $container, $requestedName, array $options = null): AuthenticationIdentityProvider - { - /* @var AuthenticationService $authenticationProvider */ - $authenticationProvider = $container->get(AuthenticationService::class); - - return new AuthenticationIdentityProvider($authenticationProvider); - } } diff --git a/src/Factory/AuthorizationServiceDelegatorFactory.php b/src/Factory/AuthorizationServiceDelegatorFactory.php index 239d5d2e..09b58813 100644 --- a/src/Factory/AuthorizationServiceDelegatorFactory.php +++ b/src/Factory/AuthorizationServiceDelegatorFactory.php @@ -18,48 +18,13 @@ namespace LmcRbacMvc\Factory; -use Psr\Container\ContainerInterface; -//use Laminas\ServiceManager\AbstractPluginManager; -use Laminas\ServiceManager\Factory\DelegatorFactoryInterface; -use Laminas\ServiceManager\ServiceLocatorInterface; -use LmcRbac\Exception\RuntimeException; -use LmcRbacMvc\Service\AuthorizationService; -use LmcRbacMvc\Service\AuthorizationServiceAwareInterface; - /** * Delegator factory for classes implementing AuthorizationServiceAwareInterface * * @author Jean-Marie Leroux * @license MIT License + * @deprecated Replaced by \LmcRbacMvc\Service\AuthorizationServiceDelegatorFactory */ -class AuthorizationServiceDelegatorFactory implements DelegatorFactoryInterface +class AuthorizationServiceDelegatorFactory extends \LmcRbacMvc\Service\AuthorizationServiceDelegatorFactory { - /** - * {@inheritDoc} - */ - public function __invoke(ContainerInterface $container, $name, callable $callback, array $options = null): AuthorizationServiceAwareInterface - { - $instanceToDecorate = call_user_func($callback); - - if (!$instanceToDecorate instanceof AuthorizationServiceAwareInterface) { - throw new RuntimeException("The service $name must implement AuthorizationServiceAwareInterface."); - } -/* - if ($container instanceof AbstractPluginManager) { - $container = $container->getServiceLocator(); - } -*/ - $authorizationService = $container->get(AuthorizationService::class); - $instanceToDecorate->setAuthorizationService($authorizationService); - - return $instanceToDecorate; - } - - /** - * {@inheritDoc} - */ - public function createDelegatorWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName, $callback) - { - return $this($serviceLocator, $requestedName, $callback); - } } diff --git a/src/Factory/AuthorizationServiceFactory.php b/src/Factory/AuthorizationServiceFactory.php index 4f0978fa..fc183271 100644 --- a/src/Factory/AuthorizationServiceFactory.php +++ b/src/Factory/AuthorizationServiceFactory.php @@ -18,42 +18,13 @@ namespace LmcRbacMvc\Factory; -use Laminas\Permissions\Rbac\Rbac; -use Psr\Container\ContainerInterface; -use Laminas\ServiceManager\Factory\FactoryInterface; -use LmcRbacMvc\Assertion\AssertionPluginManager; -use LmcRbacMvc\Options\ModuleOptions; -use LmcRbacMvc\Service\AuthorizationService; -use LmcRbacMvc\Service\RoleService; - /** * Factory to create the authorization service * * @author Michaël Gallego * @license MIT + * @deprecated Replaced by \LmcRbacMvc\Service\AuthorizationServiceFactory */ -class AuthorizationServiceFactory implements FactoryInterface +class AuthorizationServiceFactory extends \LmcRbacMvc\Service\AuthorizationServiceFactory { - /** - * @param ContainerInterface $container - * @param string $requestedName - * @param array|null $options - * @return AuthorizationService - */ - public function __invoke(ContainerInterface $container, $requestedName, array $options = null): AuthorizationService - { - /* @var RoleService $roleService */ - $roleService = $container->get(RoleService::class); - - /* @var AssertionPluginManager $assertionPluginManager */ - $assertionPluginManager = $container->get(AssertionPluginManager::class); - - /* @var ModuleOptions $moduleOptions */ - $moduleOptions = $container->get(ModuleOptions::class); - - $authorizationService = new AuthorizationService($roleService, $assertionPluginManager); - $authorizationService->setAssertions($moduleOptions->getAssertionMap()); - - return $authorizationService; - } } diff --git a/src/Factory/ControllerGuardFactory.php b/src/Factory/ControllerGuardFactory.php index 3d3ea34e..136dfbf7 100644 --- a/src/Factory/ControllerGuardFactory.php +++ b/src/Factory/ControllerGuardFactory.php @@ -18,57 +18,13 @@ namespace LmcRbacMvc\Factory; -use Psr\Container\ContainerInterface; -use Laminas\ServiceManager\Factory\FactoryInterface; -use Laminas\ServiceManager\ServiceLocatorInterface; -use LmcRbacMvc\Guard\ControllerGuard; -use LmcRbacMvc\Options\ModuleOptions; -use LmcRbacMvc\Service\RoleService; - /** * Create a controller guard * * @author Michaël Gallego * @license MIT + * @deprecated Replaced by \LmcRbacMvc\Guard\ControllerGuardFactory */ -class ControllerGuardFactory implements FactoryInterface +class ControllerGuardFactory extends \LmcRbacMvc\Guard\ControllerGuardFactory { - protected array $options = []; - - /** - * @param array $options - */ - public function __construct(array $options = []) - { - $this->setCreationOptions($options); - } - - /** - * @param array $options - */ - public function setCreationOptions(array $options): void - { - $this->options = $options; - } - - /** - * {@inheritDoc} - */ - public function __invoke(ContainerInterface $container, $requestedName, array $options = null): ControllerGuard - { - if (null === $options) { - $options = []; - } - - /* @var ModuleOptions $moduleOptions */ - $moduleOptions = $container->get(\LmcRbacMvc\Options\ModuleOptions::class); - - /* @var RoleService $roleService */ - $roleService = $container->get(\LmcRbacMvc\Service\RoleService::class); - - $controllerGuard = new ControllerGuard($roleService, $options); - $controllerGuard->setProtectionPolicy($moduleOptions->getProtectionPolicy()); - - return $controllerGuard; - } } diff --git a/src/Factory/ControllerPermissionsGuardFactory.php b/src/Factory/ControllerPermissionsGuardFactory.php index cf842692..b5236fda 100644 --- a/src/Factory/ControllerPermissionsGuardFactory.php +++ b/src/Factory/ControllerPermissionsGuardFactory.php @@ -31,45 +31,8 @@ * * @author JM Lerouxw * @license MIT + * @deprecated Replaced by \LmcRbacMvc\Guard\ControllerPermissionsGuardFactory */ -class ControllerPermissionsGuardFactory implements FactoryInterface +class ControllerPermissionsGuardFactory extends \LmcRbacMvc\Guard\ControllerPermissionsGuardFactory { - protected array $options = []; - - /** - * @param array $options - */ - public function __construct(array $options = []) - { - $this->setCreationOptions($options); - } - - /** - * @param array $options - */ - public function setCreationOptions(array $options): void - { - $this->options = $options; - } - - /** - * {@inheritDoc} - */ - public function __invoke(ContainerInterface $container, $requestedName, array $options = null): ControllerPermissionsGuard - { - if (null === $options) { - $options = []; - } - - /* @var ModuleOptions $moduleOptions */ - $moduleOptions = $container->get(\LmcRbacMvc\Options\ModuleOptions::class); - - /* @var AuthorizationService $authorizationService */ - $authorizationService = $container->get(\LmcRbacMvc\Service\AuthorizationService::class); - - $guard = new ControllerPermissionsGuard($authorizationService, $options); - $guard->setProtectionPolicy($moduleOptions->getProtectionPolicy()); - - return $guard; - } } diff --git a/src/Factory/GuardPluginManagerFactory.php b/src/Factory/GuardPluginManagerFactory.php index 9a5cdea9..6fd64822 100644 --- a/src/Factory/GuardPluginManagerFactory.php +++ b/src/Factory/GuardPluginManagerFactory.php @@ -18,6 +18,7 @@ namespace LmcRbacMvc\Factory; +use Laminas\Mvc\Service\AbstractPluginManagerFactory; use Psr\Container\ContainerInterface; use Laminas\ServiceManager\Config; use Laminas\ServiceManager\Factory\FactoryInterface; @@ -29,16 +30,8 @@ * * @author Michaël Gallego * @license MIT + * @deprecated Replaced by \LmcRbacMvc\Guard\GuardPluginManagerFactory */ -class GuardPluginManagerFactory implements FactoryInterface +class GuardPluginManagerFactory extends \LmcRbacMvc\Guard\GuardPluginManagerFactory { - /** - * {@inheritDoc} - */ - public function __invoke(ContainerInterface $container, $requestedName, array $options = null): GuardPluginManager - { - $config = $container->get('Config')['lmc_rbac']['guard_manager']; - - return new GuardPluginManager($container, $config); - } } diff --git a/src/Factory/GuardsFactory.php b/src/Factory/GuardsFactory.php index 89bc1728..9b9e242b 100644 --- a/src/Factory/GuardsFactory.php +++ b/src/Factory/GuardsFactory.php @@ -18,42 +18,13 @@ namespace LmcRbacMvc\Factory; -use Psr\Container\ContainerInterface; -use Laminas\ServiceManager\Factory\FactoryInterface; -use Laminas\ServiceManager\ServiceLocatorInterface; -use LmcRbacMvc\Guard\GuardInterface; -use LmcRbacMvc\Guard\GuardPluginManager; -use LmcRbacMvc\Options\ModuleOptions; - /** * Create a list of guards * * @author Michaël Gallego * @license MIT + * @deprecated Replaced by \LmcRbacMvc\Guard\GuardsFactory */ -class GuardsFactory implements FactoryInterface +class GuardsFactory extends \LmcRbacMvc\Guard\GuardsFactory { - /** - * {@inheritDoc} - */ - public function __invoke(ContainerInterface $container, $requestedName, array $options = null): object|array - { - /* @var ModuleOptions $options */ - $options = $container->get(ModuleOptions::class); - $guardsOptions = $options->getGuards(); - - if (empty($guardsOptions)) { - return []; - } - - /* @var GuardPluginManager $pluginManager */ - $pluginManager = $container->get(GuardPluginManager::class); - $guards = []; - - foreach ($guardsOptions as $type => $options) { - $guards[] = $pluginManager->get($type, $options); - } - - return $guards; - } } diff --git a/src/Factory/HasRoleViewHelperFactory.php b/src/Factory/HasRoleViewHelperFactory.php index 64e59c57..c2825451 100644 --- a/src/Factory/HasRoleViewHelperFactory.php +++ b/src/Factory/HasRoleViewHelperFactory.php @@ -18,28 +18,13 @@ namespace LmcRbacMvc\Factory; -use Psr\Container\ContainerInterface; -use Laminas\ServiceManager\Factory\FactoryInterface; -use Laminas\ServiceManager\ServiceLocatorInterface; -use LmcRbacMvc\Service\RoleService; -use LmcRbacMvc\View\Helper\HasRole; - /** * Create the HasRole view helper * * @author JM Leroux * @license MIT + * @deprecated Replaced by \LmcRbacMvc\View\Helper\HasRoleViewHelperFactory */ -class HasRoleViewHelperFactory implements FactoryInterface +class HasRoleViewHelperFactory extends \LmcRbacMvc\View\Helper\HasRoleViewHelperFactory { - /** - * {@inheritDoc} - */ - public function __invoke(ContainerInterface $container, $requestedName, array $options = null): HasRole - { - /* @var RoleService $roleService */ - $roleService = $container->get(RoleService::class); - - return new HasRole($roleService); - } } diff --git a/src/Factory/IsGrantedPluginFactory.php b/src/Factory/IsGrantedPluginFactory.php index 15ef11cb..4e7df8ef 100644 --- a/src/Factory/IsGrantedPluginFactory.php +++ b/src/Factory/IsGrantedPluginFactory.php @@ -18,28 +18,13 @@ namespace LmcRbacMvc\Factory; -use Psr\Container\ContainerInterface; -use Laminas\ServiceManager\Factory\FactoryInterface; -use Laminas\ServiceManager\ServiceLocatorInterface; -use LmcRbacMvc\Mvc\Controller\Plugin\IsGranted; -use LmcRbacMvc\Service\AuthorizationService; - /** * Create the IsGranted controller plugin * * @author Michaël Gallego * @license MIT + * @deprecated Replaced by \LmcRbacMvc\Mvc\Controller\Plugin\IsGrantedPluginFactory */ -class IsGrantedPluginFactory implements FactoryInterface +class IsGrantedPluginFactory extends \LmcRbacMvc\Mvc\Controller\Plugin\IsGrantedPluginFactory { - /** - * {@inheritDoc} - */ - public function __invoke(ContainerInterface $container, $requestedName, array $options = null): IsGranted - { - /* @var AuthorizationService $authorizationService */ - $authorizationService = $container->get(AuthorizationService::class); - - return new IsGranted($authorizationService); - } } diff --git a/src/Factory/IsGrantedViewHelperFactory.php b/src/Factory/IsGrantedViewHelperFactory.php index 56a904b6..a36ea438 100644 --- a/src/Factory/IsGrantedViewHelperFactory.php +++ b/src/Factory/IsGrantedViewHelperFactory.php @@ -29,17 +29,8 @@ * * @author Michaël Gallego * @license MIT + * @deprecated Replaced by \LmcRbacMvc\View\Helper\IsGrantedViewHelperFactory */ -class IsGrantedViewHelperFactory implements FactoryInterface +class IsGrantedViewHelperFactory extends \LmcRbacMvc\View\Helper\IsGrantedViewHelperFactory { - /** - * {@inheritDoc} - */ - public function __invoke(ContainerInterface $container, $requestedName, array $options = null): IsGranted - { - /* @var AuthorizationService $authorizationService */ - $authorizationService = $container->get(AuthorizationService::class); - - return new IsGranted($authorizationService); - } } diff --git a/src/Factory/ModuleOptionsFactory.php b/src/Factory/ModuleOptionsFactory.php index eaf92a01..53cf4ff4 100644 --- a/src/Factory/ModuleOptionsFactory.php +++ b/src/Factory/ModuleOptionsFactory.php @@ -18,29 +18,13 @@ namespace LmcRbacMvc\Factory; -use Laminas\ServiceManager\Exception\ServiceNotCreatedException; -use Psr\Container\ContainerInterface; -use Laminas\ServiceManager\Factory\FactoryInterface; -use Laminas\ServiceManager\ServiceLocatorInterface; -use LmcRbacMvc\Options\ModuleOptions; - /** * Factory for the module options * * @author Michaël Gallego * @license MIT + * @deprecated Replaced by \LmcRbacMvc\Options\ModuleOptionsFactory */ -class ModuleOptionsFactory implements FactoryInterface +class ModuleOptionsFactory extends \LmcRbacMvc\Options\ModuleOptionsFactory { - /** - * {@inheritDoc} - */ - public function __invoke(ContainerInterface $container, $requestedName, array $options = null): ModuleOptions - { - $config = $container->get('Config'); - if (!isset($config['lmc_rbac'])) { - throw new ServiceNotCreatedException("Could not find the `lmc_rbac' configuration array "); - } - return new ModuleOptions($container->get('Config')['lmc_rbac']); - } } diff --git a/src/Factory/ObjectRepositoryRoleProviderFactory.php b/src/Factory/ObjectRepositoryRoleProviderFactory.php index 13093fb0..4e61606b 100644 --- a/src/Factory/ObjectRepositoryRoleProviderFactory.php +++ b/src/Factory/ObjectRepositoryRoleProviderFactory.php @@ -18,69 +18,13 @@ namespace LmcRbacMvc\Factory; -use Doctrine\Persistence\ObjectManager; -use Doctrine\Persistence\ObjectRepository; -use Psr\Container\ContainerInterface; -use Laminas\ServiceManager\Factory\FactoryInterface; -use Laminas\ServiceManager\ServiceLocatorInterface; -use LmcRbacMvc\Exception; -use LmcRbacMvc\Role\ObjectRepositoryRoleProvider; - /** * Factory used to create an object repository role provider * * @author Michaël Gallego * @license MIT + * @deprecated Replaced by \LmcRbacMvc\Role\ObjectRepositoryRoleProviderFactory */ -class ObjectRepositoryRoleProviderFactory implements FactoryInterface +class ObjectRepositoryRoleProviderFactory extends \LmcRbacMvc\Role\ObjectRepositoryRoleProviderFactory { - protected array $options = []; - - /** - * @param array $options - */ - public function __construct(array $options = []) - { - $this->setCreationOptions($options); - } - - /** - * @param array $options - */ - public function setCreationOptions(array $options): void - { - $this->options = $options; - } - - /** - * {@inheritDoc} - */ - public function __invoke(ContainerInterface $container, $requestedName, array $options = null): ObjectRepositoryRoleProvider - { - $objectRepository = null; - - if (!isset($options['role_name_property'])) { - throw new Exception\RuntimeException('The "role_name_property" option is missing'); - } - - if (isset($options['object_repository'])) { - /* @var ObjectRepository $objectRepository */ - $objectRepository = $container->get($options['object_repository']); - - return new ObjectRepositoryRoleProvider($objectRepository, $options['role_name_property']); - } - - if (isset($options['object_manager']) && isset($options['class_name'])) { - /* @var ObjectManager $objectManager */ - $objectManager = $container->get($options['object_manager']); - $objectRepository = $objectManager->getRepository($options['class_name']); - - return new ObjectRepositoryRoleProvider($objectRepository, $options['role_name_property']); - } - - throw new Exception\RuntimeException( - 'No object repository was found while creating the LmcRbacMvc object repository role provider. Are - you sure you specified either the "object_repository" option or "object_manager"/"class_name" options?' - ); - } } diff --git a/src/Factory/RedirectStrategyFactory.php b/src/Factory/RedirectStrategyFactory.php index 384759e9..7036c426 100644 --- a/src/Factory/RedirectStrategyFactory.php +++ b/src/Factory/RedirectStrategyFactory.php @@ -18,31 +18,13 @@ namespace LmcRbacMvc\Factory; -use Psr\Container\ContainerInterface; -use Laminas\Authentication\AuthenticationService; -use Laminas\ServiceManager\Factory\FactoryInterface; -use Laminas\ServiceManager\ServiceLocatorInterface; -use LmcRbacMvc\Options\ModuleOptions; -use LmcRbacMvc\View\Strategy\RedirectStrategy; - /** * Factory to create a redirect strategy * * @author Michaël Gallego * @license MIT + * @deprecated Replaced by \LmcRbacMvc\View\Strategy\RedirectStrategyFactory */ -class RedirectStrategyFactory implements FactoryInterface +class RedirectStrategyFactory extends \LmcRbacMvc\View\Strategy\RedirectStrategyFactory { - /** - * {@inheritDoc} - */ - public function __invoke(ContainerInterface $container, $requestedName, array $options = null): RedirectStrategy - { - /* @var ModuleOptions $moduleOptions */ - $moduleOptions = $container->get(ModuleOptions::class); - /** @var AuthenticationService $authenticationService */ - $authenticationService = $container->get(AuthenticationService::class); - - return new RedirectStrategy($moduleOptions->getRedirectStrategy(), $authenticationService); - } } diff --git a/src/Factory/RoleProviderPluginManagerFactory.php b/src/Factory/RoleProviderPluginManagerFactory.php index d62fc743..cbff74a3 100644 --- a/src/Factory/RoleProviderPluginManagerFactory.php +++ b/src/Factory/RoleProviderPluginManagerFactory.php @@ -18,26 +18,14 @@ namespace LmcRbacMvc\Factory; -use Psr\Container\ContainerInterface; -use Laminas\ServiceManager\Factory\FactoryInterface; -use Laminas\ServiceManager\ServiceLocatorInterface; -use LmcRbacMvc\Role\RoleProviderPluginManager; /** * Factory to create a role provider plugin manager * * @author Michaël Gallego * @license MIT + * @deprecated Replaced by \LmcRbacMvc\Role\RoleProviderPluginManagerFactory */ -class RoleProviderPluginManagerFactory implements FactoryInterface +class RoleProviderPluginManagerFactory extends \LmcRbacMvc\Role\RoleProviderPluginManagerFactory { - /** - * {@inheritDoc} - */ - public function __invoke(ContainerInterface $container, $requestedName, array $options = null): RoleProviderPluginManager - { - $config = $container->get('Config')['lmc_rbac']['role_provider_manager']; - - return new RoleProviderPluginManager($container, $config); - } } diff --git a/src/Factory/RoleServiceFactory.php b/src/Factory/RoleServiceFactory.php index 4fdb742d..b8708a53 100644 --- a/src/Factory/RoleServiceFactory.php +++ b/src/Factory/RoleServiceFactory.php @@ -18,55 +18,13 @@ namespace LmcRbacMvc\Factory; -use Laminas\ServiceManager\Exception\ServiceNotCreatedException; -use Psr\Container\ContainerInterface; -use Laminas\ServiceManager\Factory\FactoryInterface; -use Laminas\ServiceManager\ServiceLocatorInterface; -use LmcRbacMvc\Identity\IdentityProviderInterface; -use LmcRbacMvc\Options\ModuleOptions; -use LmcRbacMvc\Role\RoleProviderInterface; -use LmcRbacMvc\Role\RoleProviderPluginManager; -use LmcRbacMvc\Service\RoleService; -use LmcRbacMvc\Role\RecursiveRoleIteratorStrategy; -use LmcRbacMvc\Role\TraversalStrategyInterface; - /** * Factory to create the role service * * @author Michaël Gallego * @license MIT + * @deprecated Replaced by \LmcRbacMvc\Service\RoleServiceFactory */ -class RoleServiceFactory implements FactoryInterface +class RoleServiceFactory extends \LmcRbacMvc\Service\RoleServiceFactory { - /** - * {@inheritDoc} - */ - public function __invoke(ContainerInterface $container, $requestedName, array $options = null): RoleService - { - /* @var ModuleOptions $moduleOptions */ - $moduleOptions = $container->get(ModuleOptions::class); - - /* @var IdentityProviderInterface $identityProvider */ - $identityProvider = $container->get($moduleOptions->getIdentityProvider()); - - $roleProviderConfig = $moduleOptions->getRoleProvider(); - - if (empty($roleProviderConfig)) { - throw new ServiceNotCreatedException('No role provider has been set for LmcRbacMvc'); - } - - /* @var RoleProviderPluginManager $pluginManager */ - $pluginManager = $container->get(RoleProviderPluginManager::class); - - reset($roleProviderConfig); - $roleProvider = $pluginManager->get(key($roleProviderConfig), current($roleProviderConfig)); - - /* @var TraversalStrategyInterface $traversalStrategy */ - $traversalStrategy = new RecursiveRoleIteratorStrategy();//$container->get(Rbac::class)->getTraversalStrategy(); - - $roleService = new RoleService($identityProvider, $roleProvider, $traversalStrategy); - $roleService->setGuestRole($moduleOptions->getGuestRole()); - - return $roleService; - } } diff --git a/src/Factory/RouteGuardFactory.php b/src/Factory/RouteGuardFactory.php index 64474cfb..2ca8dc1a 100644 --- a/src/Factory/RouteGuardFactory.php +++ b/src/Factory/RouteGuardFactory.php @@ -18,60 +18,13 @@ namespace LmcRbacMvc\Factory; -use Psr\Container\ContainerInterface; -use Laminas\ServiceManager\Factory\FactoryInterface; -use Laminas\ServiceManager\ServiceLocatorInterface; -use LmcRbacMvc\Guard\RouteGuard; -use LmcRbacMvc\Options\ModuleOptions; -use LmcRbacMvc\Service\RoleService; - /** * Create a route guard * * @author Michaël Gallego * @license MIT + * @deprecated Replaced by \LmcRbacMvc\Guard\RouteGuardFactory */ -class RouteGuardFactory implements FactoryInterface +class RouteGuardFactory extends \LmcRbacMvc\Guard\RouteGuardFactory { - /** - * @var array - */ - protected array $options = []; - - /** - * @param array $options - */ - public function __construct(array $options = []) - { - $this->setCreationOptions($options); - } - - /** - * @param array $options - */ - public function setCreationOptions(array $options): void - { - $this->options = $options; - } - - /** - * {@inheritDoc} - */ - public function __invoke(ContainerInterface $container, $requestedName, array $options = null): RouteGuard - { - if (null === $options) { - $options = []; - } - - /* @var ModuleOptions $moduleOptions */ - $moduleOptions = $container->get(ModuleOptions::class); - - /* @var RoleService $roleService */ - $roleService = $container->get(RoleService::class); - - $routeGuard = new RouteGuard($roleService, $options); - $routeGuard->setProtectionPolicy($moduleOptions->getProtectionPolicy()); - - return $routeGuard; - } } diff --git a/src/Factory/RoutePermissionsGuardFactory.php b/src/Factory/RoutePermissionsGuardFactory.php index 9701d150..9df3da23 100644 --- a/src/Factory/RoutePermissionsGuardFactory.php +++ b/src/Factory/RoutePermissionsGuardFactory.php @@ -18,59 +18,14 @@ namespace LmcRbacMvc\Factory; -use Psr\Container\ContainerInterface; -use Laminas\ServiceManager\Factory\FactoryInterface; -use Laminas\ServiceManager\ServiceLocatorInterface; -use LmcRbacMvc\Guard\RouteGuard; -use LmcRbacMvc\Guard\RoutePermissionsGuard; -use LmcRbacMvc\Options\ModuleOptions; -use LmcRbacMvc\Service\AuthorizationService; - /** * Create a route guard for checking permissions * * @author Michaël Gallego * @author JM Lerouxw * @license MIT + * @deprecated Replaced by \LmcRbacMvc\Guard\RoutePermissionsGuardFactory */ -class RoutePermissionsGuardFactory implements FactoryInterface +class RoutePermissionsGuardFactory extends \LmcRbacMvc\Guard\RoutePermissionsGuardFactory { - protected array $options = []; - - /** - * @param array $options - */ - public function __construct(array $options = []) - { - $this->setCreationOptions($options); - } - - /** - * @param array $options - */ - public function setCreationOptions(array $options): void - { - $this->options = $options; - } - - /** - * {@inheritDoc} - */ - public function __invoke(ContainerInterface $container, $requestedName, array $options = null): RoutePermissionsGuard - { - if (null === $options) { - $options = []; - } - - /* @var ModuleOptions $moduleOptions */ - $moduleOptions = $container->get(ModuleOptions::class); - - /* @var AuthorizationService $authorizationService */ - $authorizationService = $container->get(AuthorizationService::class); - - $routeGuard = new RoutePermissionsGuard($authorizationService, $options); - $routeGuard->setProtectionPolicy($moduleOptions->getProtectionPolicy()); - - return $routeGuard; - } } diff --git a/src/Factory/UnauthorizedStrategyFactory.php b/src/Factory/UnauthorizedStrategyFactory.php index a8b2a4c1..12d53715 100644 --- a/src/Factory/UnauthorizedStrategyFactory.php +++ b/src/Factory/UnauthorizedStrategyFactory.php @@ -18,28 +18,13 @@ namespace LmcRbacMvc\Factory; -use Psr\Container\ContainerInterface; -use Laminas\ServiceManager\Factory\FactoryInterface; -use Laminas\ServiceManager\ServiceLocatorInterface; -use LmcRbacMvc\Options\ModuleOptions; -use LmcRbacMvc\View\Strategy\UnauthorizedStrategy; - /** * Factory to create an unauthorized strategy * * @author Michaël Gallego * @license MIT + * @deprecated Replaced by \LmcRbacMvc\View\Strategy\UnauthorizedStrategyFactory */ -class UnauthorizedStrategyFactory implements FactoryInterface +class UnauthorizedStrategyFactory extends \LmcRbacMvc\View\Strategy\UnauthorizedStrategyFactory { - /** - * {@inheritDoc} - */ - public function __invoke(ContainerInterface $container, $requestedName, array $options = null): UnauthorizedStrategy - { - /* @var ModuleOptions $moduleOptions */ - $moduleOptions = $container->get(ModuleOptions::class); - - return new UnauthorizedStrategy($moduleOptions->getUnauthorizedStrategy()); - } } diff --git a/src/Guard/ControllerGuardFactory.php b/src/Guard/ControllerGuardFactory.php new file mode 100644 index 00000000..0af1afd8 --- /dev/null +++ b/src/Guard/ControllerGuardFactory.php @@ -0,0 +1,72 @@ + + * @license MIT + */ +class ControllerGuardFactory implements FactoryInterface +{ + protected array $options = []; + + /** + * @param array $options + */ + public function __construct(array $options = []) + { + $this->setCreationOptions($options); + } + + /** + * @param array $options + */ + public function setCreationOptions(array $options): void + { + $this->options = $options; + } + + /** + * {@inheritDoc} + */ + public function __invoke(ContainerInterface $container, $requestedName, array $options = null): ControllerGuard + { + if (null === $options) { + $options = []; + } + + /* @var ModuleOptions $moduleOptions */ + $moduleOptions = $container->get(ModuleOptions::class); + + /* @var RoleService $roleService */ + $roleService = $container->get(RoleService::class); + + $controllerGuard = new ControllerGuard($roleService, $options); + $controllerGuard->setProtectionPolicy($moduleOptions->getProtectionPolicy()); + + return $controllerGuard; + } +} diff --git a/src/Guard/ControllerPermissionsGuardFactory.php b/src/Guard/ControllerPermissionsGuardFactory.php new file mode 100644 index 00000000..3777afd3 --- /dev/null +++ b/src/Guard/ControllerPermissionsGuardFactory.php @@ -0,0 +1,72 @@ + + * @license MIT + */ +class ControllerPermissionsGuardFactory implements FactoryInterface +{ + protected array $options = []; + + /** + * @param array $options + */ + public function __construct(array $options = []) + { + $this->setCreationOptions($options); + } + + /** + * @param array $options + */ + public function setCreationOptions(array $options): void + { + $this->options = $options; + } + + /** + * {@inheritDoc} + */ + public function __invoke(ContainerInterface $container, $requestedName, array $options = null): ControllerPermissionsGuard + { + if (null === $options) { + $options = []; + } + + /* @var ModuleOptions $moduleOptions */ + $moduleOptions = $container->get(ModuleOptions::class); + + /* @var AuthorizationService $authorizationService */ + $authorizationService = $container->get(AuthorizationService::class); + + $guard = new ControllerPermissionsGuard($authorizationService, $options); + $guard->setProtectionPolicy($moduleOptions->getProtectionPolicy()); + + return $guard; + } +} diff --git a/src/Guard/GuardPluginManagerFactory.php b/src/Guard/GuardPluginManagerFactory.php new file mode 100644 index 00000000..05c333e4 --- /dev/null +++ b/src/Guard/GuardPluginManagerFactory.php @@ -0,0 +1,41 @@ + + * @license MIT + */ +class GuardPluginManagerFactory implements FactoryInterface +{ + /** + * {@inheritDoc} + */ + public function __invoke(ContainerInterface $container, $requestedName, array $options = null): GuardPluginManager + { + $config = $container->get('Config')['lmc_rbac']['guard_manager']; + + return new GuardPluginManager($container, $config); + } +} diff --git a/src/Guard/GuardsFactory.php b/src/Guard/GuardsFactory.php new file mode 100644 index 00000000..f041aba3 --- /dev/null +++ b/src/Guard/GuardsFactory.php @@ -0,0 +1,56 @@ + + * @license MIT + */ +class GuardsFactory implements FactoryInterface +{ + /** + * {@inheritDoc} + */ + public function __invoke(ContainerInterface $container, $requestedName, array $options = null): object|array + { + /* @var ModuleOptions $options */ + $options = $container->get(ModuleOptions::class); + $guardsOptions = $options->getGuards(); + + if (empty($guardsOptions)) { + return []; + } + + /* @var GuardPluginManager $pluginManager */ + $pluginManager = $container->get(GuardPluginManager::class); + $guards = []; + + foreach ($guardsOptions as $type => $options) { + $guards[] = $pluginManager->get($type, $options); + } + + return $guards; + } +} diff --git a/src/Guard/RouteGuardFactory.php b/src/Guard/RouteGuardFactory.php new file mode 100644 index 00000000..02026c94 --- /dev/null +++ b/src/Guard/RouteGuardFactory.php @@ -0,0 +1,75 @@ + + * @license MIT + */ +class RouteGuardFactory implements FactoryInterface +{ + /** + * @var array + */ + protected array $options = []; + + /** + * @param array $options + */ + public function __construct(array $options = []) + { + $this->setCreationOptions($options); + } + + /** + * @param array $options + */ + public function setCreationOptions(array $options): void + { + $this->options = $options; + } + + /** + * {@inheritDoc} + */ + public function __invoke(ContainerInterface $container, $requestedName, array $options = null): RouteGuard + { + if (null === $options) { + $options = []; + } + + /* @var ModuleOptions $moduleOptions */ + $moduleOptions = $container->get(ModuleOptions::class); + + /* @var RoleService $roleService */ + $roleService = $container->get(RoleService::class); + + $routeGuard = new RouteGuard($roleService, $options); + $routeGuard->setProtectionPolicy($moduleOptions->getProtectionPolicy()); + + return $routeGuard; + } +} diff --git a/src/Guard/RoutePermissionsGuardFactory.php b/src/Guard/RoutePermissionsGuardFactory.php new file mode 100644 index 00000000..c61f4dc2 --- /dev/null +++ b/src/Guard/RoutePermissionsGuardFactory.php @@ -0,0 +1,73 @@ + + * @author JM Lerouxw + * @license MIT + */ +class RoutePermissionsGuardFactory implements FactoryInterface +{ + protected array $options = []; + + /** + * @param array $options + */ + public function __construct(array $options = []) + { + $this->setCreationOptions($options); + } + + /** + * @param array $options + */ + public function setCreationOptions(array $options): void + { + $this->options = $options; + } + + /** + * {@inheritDoc} + */ + public function __invoke(ContainerInterface $container, $requestedName, array $options = null): RoutePermissionsGuard + { + if (null === $options) { + $options = []; + } + + /* @var ModuleOptions $moduleOptions */ + $moduleOptions = $container->get(ModuleOptions::class); + + /* @var AuthorizationService $authorizationService */ + $authorizationService = $container->get(AuthorizationService::class); + + $routeGuard = new RoutePermissionsGuard($authorizationService, $options); + $routeGuard->setProtectionPolicy($moduleOptions->getProtectionPolicy()); + + return $routeGuard; + } +} diff --git a/src/Identity/AuthenticationIdentityProviderFactory.php b/src/Identity/AuthenticationIdentityProviderFactory.php new file mode 100644 index 00000000..04ca9a57 --- /dev/null +++ b/src/Identity/AuthenticationIdentityProviderFactory.php @@ -0,0 +1,45 @@ + + * @license MIT + */ +class AuthenticationIdentityProviderFactory implements FactoryInterface +{ + /** + * {@inheritDoc} + */ + public function __invoke(ContainerInterface $container, $requestedName, array $options = null): AuthenticationIdentityProvider + { + /* @var AuthenticationService $authenticationProvider */ + $authenticationProvider = $container->get(AuthenticationService::class); + + return new AuthenticationIdentityProvider($authenticationProvider); + } +} diff --git a/src/Mvc/Controller/Plugin/IsGrantedPluginFactory.php b/src/Mvc/Controller/Plugin/IsGrantedPluginFactory.php new file mode 100644 index 00000000..c7f1fec0 --- /dev/null +++ b/src/Mvc/Controller/Plugin/IsGrantedPluginFactory.php @@ -0,0 +1,43 @@ + + * @license MIT + */ +class IsGrantedPluginFactory implements FactoryInterface +{ + /** + * {@inheritDoc} + */ + public function __invoke(ContainerInterface $container, $requestedName, array $options = null): IsGranted + { + /* @var AuthorizationService $authorizationService */ + $authorizationService = $container->get(AuthorizationService::class); + + return new IsGranted($authorizationService); + } +} diff --git a/src/Options/ModuleOptionsFactory.php b/src/Options/ModuleOptionsFactory.php new file mode 100644 index 00000000..1056b4c2 --- /dev/null +++ b/src/Options/ModuleOptionsFactory.php @@ -0,0 +1,44 @@ + + * @license MIT + */ +class ModuleOptionsFactory implements FactoryInterface +{ + /** + * {@inheritDoc} + */ + public function __invoke(ContainerInterface $container, $requestedName, array $options = null): ModuleOptions + { + $config = $container->get('Config'); + if (!isset($config['lmc_rbac'])) { + throw new ServiceNotCreatedException("Could not find the `lmc_rbac' configuration array "); + } + return new ModuleOptions($container->get('Config')['lmc_rbac']); + } +} diff --git a/src/Role/ObjectRepositoryRoleProviderFactory.php b/src/Role/ObjectRepositoryRoleProviderFactory.php new file mode 100644 index 00000000..3d25fa62 --- /dev/null +++ b/src/Role/ObjectRepositoryRoleProviderFactory.php @@ -0,0 +1,84 @@ + + * @license MIT + */ +class ObjectRepositoryRoleProviderFactory implements FactoryInterface +{ + protected array $options = []; + + /** + * @param array $options + */ + public function __construct(array $options = []) + { + $this->setCreationOptions($options); + } + + /** + * @param array $options + */ + public function setCreationOptions(array $options): void + { + $this->options = $options; + } + + /** + * {@inheritDoc} + */ + public function __invoke(ContainerInterface $container, $requestedName, array $options = null): ObjectRepositoryRoleProvider + { + $objectRepository = null; + + if (!isset($options['role_name_property'])) { + throw new Exception\RuntimeException('The "role_name_property" option is missing'); + } + + if (isset($options['object_repository'])) { + /* @var ObjectRepository $objectRepository */ + $objectRepository = $container->get($options['object_repository']); + + return new ObjectRepositoryRoleProvider($objectRepository, $options['role_name_property']); + } + + if (isset($options['object_manager']) && isset($options['class_name'])) { + /* @var ObjectManager $objectManager */ + $objectManager = $container->get($options['object_manager']); + $objectRepository = $objectManager->getRepository($options['class_name']); + + return new ObjectRepositoryRoleProvider($objectRepository, $options['role_name_property']); + } + + throw new Exception\RuntimeException( + 'No object repository was found while creating the LmcRbacMvc object repository role provider. Are + you sure you specified either the "object_repository" option or "object_manager"/"class_name" options?' + ); + } +} diff --git a/src/Role/RoleProviderPluginManagerFactory.php b/src/Role/RoleProviderPluginManagerFactory.php new file mode 100644 index 00000000..2aa9526e --- /dev/null +++ b/src/Role/RoleProviderPluginManagerFactory.php @@ -0,0 +1,41 @@ + + * @license MIT + */ +class RoleProviderPluginManagerFactory implements FactoryInterface +{ + /** + * {@inheritDoc} + */ + public function __invoke(ContainerInterface $container, $requestedName, array $options = null): RoleProviderPluginManager + { + $config = $container->get('Config')['lmc_rbac']['role_provider_manager']; + + return new RoleProviderPluginManager($container, $config); + } +} diff --git a/src/Service/AuthorizationServiceDelegatorFactory.php b/src/Service/AuthorizationServiceDelegatorFactory.php new file mode 100644 index 00000000..205752a0 --- /dev/null +++ b/src/Service/AuthorizationServiceDelegatorFactory.php @@ -0,0 +1,58 @@ + + * @license MIT License + */ +class AuthorizationServiceDelegatorFactory implements DelegatorFactoryInterface +{ + /** + * {@inheritDoc} + */ + public function __invoke(ContainerInterface $container, $name, callable $callback, array $options = null): AuthorizationServiceAwareInterface + { + $instanceToDecorate = call_user_func($callback); + + if (!$instanceToDecorate instanceof AuthorizationServiceAwareInterface) { + throw new RuntimeException("The service $name must implement AuthorizationServiceAwareInterface."); + } + $authorizationService = $container->get(AuthorizationService::class); + $instanceToDecorate->setAuthorizationService($authorizationService); + + return $instanceToDecorate; + } + + /** TODO remove */ + public function createDelegatorWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName, $callback) + { + return $this($serviceLocator, $requestedName, $callback); + } +} diff --git a/src/Service/AuthorizationServiceFactory.php b/src/Service/AuthorizationServiceFactory.php new file mode 100644 index 00000000..6d8c68a9 --- /dev/null +++ b/src/Service/AuthorizationServiceFactory.php @@ -0,0 +1,59 @@ + + * @license MIT + */ +class AuthorizationServiceFactory implements FactoryInterface +{ + /** + * @param ContainerInterface $container + * @param string $requestedName + * @param array|null $options + * @return AuthorizationService + */ + public function __invoke(ContainerInterface $container, $requestedName, array $options = null): AuthorizationService + { + /* @var RoleService $roleService */ + $roleService = $container->get(RoleService::class); + + /* @var AssertionPluginManager $assertionPluginManager */ + $assertionPluginManager = $container->get(AssertionPluginManager::class); + + /* @var ModuleOptions $moduleOptions */ + $moduleOptions = $container->get(ModuleOptions::class); + + $authorizationService = new AuthorizationService($roleService, $assertionPluginManager); + $authorizationService->setAssertions($moduleOptions->getAssertionMap()); + + return $authorizationService; + } +} diff --git a/src/Service/RoleServiceFactory.php b/src/Service/RoleServiceFactory.php new file mode 100644 index 00000000..0575a8c9 --- /dev/null +++ b/src/Service/RoleServiceFactory.php @@ -0,0 +1,69 @@ + + * @license MIT + */ +class RoleServiceFactory implements FactoryInterface +{ + /** + * {@inheritDoc} + */ + public function __invoke(ContainerInterface $container, $requestedName, array $options = null): RoleService + { + /* @var ModuleOptions $moduleOptions */ + $moduleOptions = $container->get(ModuleOptions::class); + + /* @var IdentityProviderInterface $identityProvider */ + $identityProvider = $container->get($moduleOptions->getIdentityProvider()); + + $roleProviderConfig = $moduleOptions->getRoleProvider(); + + if (empty($roleProviderConfig)) { + throw new ServiceNotCreatedException('No role provider has been set for LmcRbacMvc'); + } + + /* @var RoleProviderPluginManager $pluginManager */ + $pluginManager = $container->get(RoleProviderPluginManager::class); + + reset($roleProviderConfig); + $roleProvider = $pluginManager->get(key($roleProviderConfig), current($roleProviderConfig)); + + /* @var TraversalStrategyInterface $traversalStrategy */ + $traversalStrategy = new RecursiveRoleIteratorStrategy();//$container->get(Rbac::class)->getTraversalStrategy(); + + $roleService = new RoleService($identityProvider, $roleProvider, $traversalStrategy); + $roleService->setGuestRole($moduleOptions->getGuestRole()); + + return $roleService; + } +} diff --git a/src/View/Helper/HasRoleViewHelperFactory.php b/src/View/Helper/HasRoleViewHelperFactory.php new file mode 100644 index 00000000..3203b2db --- /dev/null +++ b/src/View/Helper/HasRoleViewHelperFactory.php @@ -0,0 +1,43 @@ + + * @license MIT + */ +class HasRoleViewHelperFactory implements FactoryInterface +{ + /** + * {@inheritDoc} + */ + public function __invoke(ContainerInterface $container, $requestedName, array $options = null): HasRole + { + /* @var RoleService $roleService */ + $roleService = $container->get(RoleService::class); + + return new HasRole($roleService); + } +} diff --git a/src/View/Helper/IsGrantedViewHelperFactory.php b/src/View/Helper/IsGrantedViewHelperFactory.php new file mode 100644 index 00000000..f8db2824 --- /dev/null +++ b/src/View/Helper/IsGrantedViewHelperFactory.php @@ -0,0 +1,43 @@ + + * @license MIT + */ +class IsGrantedViewHelperFactory implements FactoryInterface +{ + /** + * {@inheritDoc} + */ + public function __invoke(ContainerInterface $container, $requestedName, array $options = null): IsGranted + { + /* @var AuthorizationService $authorizationService */ + $authorizationService = $container->get(AuthorizationService::class); + + return new IsGranted($authorizationService); + } +} diff --git a/src/View/Strategy/RedirectStrategyFactory.php b/src/View/Strategy/RedirectStrategyFactory.php new file mode 100644 index 00000000..c3397ba6 --- /dev/null +++ b/src/View/Strategy/RedirectStrategyFactory.php @@ -0,0 +1,46 @@ + + * @license MIT + */ +class RedirectStrategyFactory implements FactoryInterface +{ + /** + * {@inheritDoc} + */ + public function __invoke(ContainerInterface $container, $requestedName, array $options = null): RedirectStrategy + { + /* @var ModuleOptions $moduleOptions */ + $moduleOptions = $container->get(ModuleOptions::class); + /** @var AuthenticationService $authenticationService */ + $authenticationService = $container->get(AuthenticationService::class); + + return new RedirectStrategy($moduleOptions->getRedirectStrategy(), $authenticationService); + } +} diff --git a/src/View/Strategy/UnauthorizedStrategyFactory.php b/src/View/Strategy/UnauthorizedStrategyFactory.php new file mode 100644 index 00000000..3191880a --- /dev/null +++ b/src/View/Strategy/UnauthorizedStrategyFactory.php @@ -0,0 +1,43 @@ + + * @license MIT + */ +class UnauthorizedStrategyFactory implements FactoryInterface +{ + /** + * {@inheritDoc} + */ + public function __invoke(ContainerInterface $container, $requestedName, array $options = null): UnauthorizedStrategy + { + /* @var ModuleOptions $moduleOptions */ + $moduleOptions = $container->get(ModuleOptions::class); + + return new UnauthorizedStrategy($moduleOptions->getUnauthorizedStrategy()); + } +} diff --git a/tests/Factory/AssertionPluginManagerFactoryTest.php b/tests/Assertion/AssertionPluginManagerFactoryTest.php similarity index 92% rename from tests/Factory/AssertionPluginManagerFactoryTest.php rename to tests/Assertion/AssertionPluginManagerFactoryTest.php index f61e47b8..a24c774b 100644 --- a/tests/Factory/AssertionPluginManagerFactoryTest.php +++ b/tests/Assertion/AssertionPluginManagerFactoryTest.php @@ -16,13 +16,13 @@ * and is licensed under the MIT license. */ -namespace LmcRbacMvcTest\Factory; +namespace LmcRbacMvcTest\Assertion; use Laminas\ServiceManager\ServiceManager; -use LmcRbacMvc\Factory\AssertionPluginManagerFactory; +use LmcRbacMvc\Assertion\AssertionPluginManagerFactory; /** - * @covers \LmcRbacMvc\Factory\AssertionPluginManagerFactory + * @covers \LmcRbacMvc\Assertion\AssertionPluginManagerFactory */ class AssertionPluginManagerFactoryTest extends \PHPUnit\Framework\TestCase { diff --git a/tests/Assertion/AssertionPluginManagerTest.php b/tests/Assertion/AssertionPluginManagerTest.php new file mode 100644 index 00000000..9352f7c8 --- /dev/null +++ b/tests/Assertion/AssertionPluginManagerTest.php @@ -0,0 +1,24 @@ +expectException(InvalidServiceException::class); + $pluginManager->validate($assertion); + } +} diff --git a/tests/ConfigProviderTest.php b/tests/ConfigProviderTest.php new file mode 100644 index 00000000..00073341 --- /dev/null +++ b/tests/ConfigProviderTest.php @@ -0,0 +1,24 @@ +assertIsArray($provider()); + $this->assertArrayHasKey('dependencies', $provider()); + $this->assertArrayHasKey('factories', $provider->getDependencies()); + $this->assertArrayHasKey('controller_plugins', $provider()); + $this->assertArrayHasKey('view_manager', $provider()); + $this->assertArrayHasKey('lmc_rbac', $provider()); + $this->assertArrayHasKey('view_helpers', $provider()); + } +} diff --git a/tests/Factory/ControllerGuardFactoryTest.php b/tests/Guard/ControllerGuardFactoryTest.php similarity index 94% rename from tests/Factory/ControllerGuardFactoryTest.php rename to tests/Guard/ControllerGuardFactoryTest.php index 13d0b0ed..089705fc 100644 --- a/tests/Factory/ControllerGuardFactoryTest.php +++ b/tests/Guard/ControllerGuardFactoryTest.php @@ -16,16 +16,16 @@ * and is licensed under the MIT license. */ -namespace LmcRbacMvcTest\Factory; +namespace LmcRbacMvcTest\Guard; use Laminas\ServiceManager\ServiceManager; -use LmcRbacMvc\Factory\ControllerGuardFactory; +use LmcRbacMvc\Guard\ControllerGuardFactory; use LmcRbacMvc\Guard\GuardInterface; use LmcRbacMvc\Guard\GuardPluginManager; use LmcRbacMvc\Options\ModuleOptions; /** - * @covers \LmcRbacMvc\Factory\ControllerGuardFactory + * @covers \LmcRbacMvc\Guard\ControllerGuardFactory */ class ControllerGuardFactoryTest extends \PHPUnit\Framework\TestCase { diff --git a/tests/Factory/ControllerPermissionsGuardFactoryTest.php b/tests/Guard/ControllerPermissionsGuardFactoryTest.php similarity index 88% rename from tests/Factory/ControllerPermissionsGuardFactoryTest.php rename to tests/Guard/ControllerPermissionsGuardFactoryTest.php index 5a18be63..48cc6d8d 100644 --- a/tests/Factory/ControllerPermissionsGuardFactoryTest.php +++ b/tests/Guard/ControllerPermissionsGuardFactoryTest.php @@ -16,16 +16,16 @@ * and is licensed under the MIT license. */ -namespace LmcRbacMvcTest\Factory; +namespace LmcRbacMvcTest\Guard; use Laminas\ServiceManager\ServiceManager; -use LmcRbacMvc\Factory\ControllerPermissionsGuardFactory; +use LmcRbacMvc\Guard\ControllerPermissionsGuardFactory; use LmcRbacMvc\Guard\GuardInterface; use LmcRbacMvc\Guard\GuardPluginManager; use LmcRbacMvc\Options\ModuleOptions; /** - * @covers \LmcRbacMvc\Factory\ControllerPermissionsGuardFactory + * @covers \LmcRbacMvc\Guard\ControllerPermissionsGuardFactory */ class ControllerPermissionsGuardFactoryTest extends \PHPUnit\Framework\TestCase { @@ -34,10 +34,6 @@ public function testFactory() { $serviceManager = new ServiceManager(); - if (!method_exists($serviceManager, 'build')) { - $this->markTestSkipped('this test is only vor zend-servicemanager v3'); - } - $creationOptions = [ 'route' => 'permission' ]; diff --git a/tests/Factory/GuardPluginManagerFactoryTest.php b/tests/Guard/GuardPluginManagerFactoryTest.php similarity index 91% rename from tests/Factory/GuardPluginManagerFactoryTest.php rename to tests/Guard/GuardPluginManagerFactoryTest.php index 45d96081..d230e3fc 100644 --- a/tests/Factory/GuardPluginManagerFactoryTest.php +++ b/tests/Guard/GuardPluginManagerFactoryTest.php @@ -16,14 +16,14 @@ * and is licensed under the MIT license. */ -namespace LmcRbacMvcTest\Factory; +namespace LmcRbacMvcTest\Guard; use Laminas\ServiceManager\ServiceManager; -use LmcRbacMvc\Factory\GuardPluginManagerFactory; +use LmcRbacMvc\Guard\GuardPluginManagerFactory; use LmcRbacMvc\Guard\GuardPluginManager; /** - * @covers \LmcRbacMvc\Factory\GuardPluginManagerFactory + * @covers \LmcRbacMvc\Guard\GuardPluginManagerFactory */ class GuardPluginManagerFactoryTest extends \PHPUnit\Framework\TestCase { diff --git a/tests/Factory/GuardsFactoryTest.php b/tests/Guard/GuardsFactoryTest.php similarity index 96% rename from tests/Factory/GuardsFactoryTest.php rename to tests/Guard/GuardsFactoryTest.php index 944a228d..fb387f59 100644 --- a/tests/Factory/GuardsFactoryTest.php +++ b/tests/Guard/GuardsFactoryTest.php @@ -16,15 +16,15 @@ * and is licensed under the MIT license. */ -namespace LmcRbacMvcTest\Factory; +namespace LmcRbacMvcTest\Guard; use Laminas\ServiceManager\ServiceManager; -use LmcRbacMvc\Factory\GuardsFactory; +use LmcRbacMvc\Guard\GuardsFactory; use LmcRbacMvc\Guard\GuardPluginManager; use LmcRbacMvc\Options\ModuleOptions; /** - * @covers \LmcRbacMvc\Factory\GuardsFactory + * @covers \LmcRbacMvc\Guard\GuardsFactory */ class GuardsFactoryTest extends \PHPUnit\Framework\TestCase { diff --git a/tests/Factory/RouteGuardFactoryTest.php b/tests/Guard/RouteGuardFactoryTest.php similarity index 87% rename from tests/Factory/RouteGuardFactoryTest.php rename to tests/Guard/RouteGuardFactoryTest.php index d0b598e7..c2850da9 100644 --- a/tests/Factory/RouteGuardFactoryTest.php +++ b/tests/Guard/RouteGuardFactoryTest.php @@ -16,16 +16,15 @@ * and is licensed under the MIT license. */ -namespace LmcRbacMvcTest\Factory; +namespace LmcRbacMvcTest\Guard; use Laminas\ServiceManager\ServiceManager; -use LmcRbacMvc\Factory\RouteGuardFactory; +use LmcRbacMvc\Guard\RouteGuardFactory; use LmcRbacMvc\Guard\GuardInterface; -use LmcRbacMvc\Guard\GuardPluginManager; use LmcRbacMvc\Options\ModuleOptions; /** - * @covers \LmcRbacMvc\Factory\RouteGuardFactory + * @covers \LmcRbacMvc\Guard\RouteGuardFactory */ class RouteGuardFactoryTest extends \PHPUnit\Framework\TestCase { @@ -33,10 +32,6 @@ public function testFactory() { $serviceManager = new ServiceManager(); - if (!method_exists($serviceManager, 'build')) { - $this->markTestSkipped('this test is only vor zend-servicemanager v3'); - } - $creationOptions = [ 'route' => 'role' ]; diff --git a/tests/Factory/RoutePermissionsGuardFactoryTest.php b/tests/Guard/RoutePermissionsGuardFactoryTest.php similarity index 86% rename from tests/Factory/RoutePermissionsGuardFactoryTest.php rename to tests/Guard/RoutePermissionsGuardFactoryTest.php index 0d032321..09302fb4 100644 --- a/tests/Factory/RoutePermissionsGuardFactoryTest.php +++ b/tests/Guard/RoutePermissionsGuardFactoryTest.php @@ -16,16 +16,15 @@ * and is licensed under the MIT license. */ -namespace LmcRbacMvcTest\Factory; +namespace LmcRbacMvcTest\Guard; use Laminas\ServiceManager\ServiceManager; -use LmcRbacMvc\Factory\RoutePermissionsGuardFactory; +use LmcRbacMvc\Guard\RoutePermissionsGuardFactory; use LmcRbacMvc\Guard\GuardInterface; -use LmcRbacMvc\Guard\GuardPluginManager; use LmcRbacMvc\Options\ModuleOptions; /** - * @covers \LmcRbacMvc\Factory\RoutePermissionsGuardFactory + * @covers \LmcRbacMvc\Guard\RoutePermissionsGuardFactory */ class RoutePermissionsGuardFactoryTest extends \PHPUnit\Framework\TestCase { @@ -33,10 +32,6 @@ public function testFactory() { $serviceManager = new ServiceManager(); - if (! method_exists($serviceManager, 'build')) { - $this->markTestSkipped('this test is only vor zend-servicemanager v3'); - } - $creationOptions = [ 'route' => 'role' ]; diff --git a/tests/Factory/AuthenticationIdentityProviderFactoryTest.php b/tests/Identity/AuthenticationIdentityProviderFactoryTest.php similarity index 90% rename from tests/Factory/AuthenticationIdentityProviderFactoryTest.php rename to tests/Identity/AuthenticationIdentityProviderFactoryTest.php index a9820be1..d7f7f5f3 100644 --- a/tests/Factory/AuthenticationIdentityProviderFactoryTest.php +++ b/tests/Identity/AuthenticationIdentityProviderFactoryTest.php @@ -16,13 +16,13 @@ * and is licensed under the MIT license. */ -namespace LmcRbacMvcTest\Factory; +namespace LmcRbacMvcTest\Identity; use Laminas\ServiceManager\ServiceManager; -use LmcRbacMvc\Factory\AuthenticationIdentityProviderFactory; +use LmcRbacMvc\Identity\AuthenticationIdentityProviderFactory; /** - * @covers \LmcRbacMvc\Factory\AuthenticationIdentityProviderFactory + * @covers \LmcRbacMvc\Identity\AuthenticationIdentityProviderFactory */ class AuthenticationIdentityProviderFactoryTest extends \PHPUnit\Framework\TestCase { diff --git a/tests/Factory/IsGrantedPluginFactoryTest.php b/tests/Mvc/Controller/Plugin/IsGrantedPluginFactoryTest.php similarity index 90% rename from tests/Factory/IsGrantedPluginFactoryTest.php rename to tests/Mvc/Controller/Plugin/IsGrantedPluginFactoryTest.php index 49f3445d..bb5aa39f 100644 --- a/tests/Factory/IsGrantedPluginFactoryTest.php +++ b/tests/Mvc/Controller/Plugin/IsGrantedPluginFactoryTest.php @@ -16,14 +16,13 @@ * and is licensed under the MIT license. */ -namespace LmcRbacMvcTest\Factory; +namespace LmcRbacMvcTest\Mvc\Controller\Plugin; -use Laminas\Mvc\Controller\PluginManager; use Laminas\ServiceManager\ServiceManager; -use LmcRbacMvc\Factory\IsGrantedPluginFactory; +use LmcRbacMvc\Mvc\Controller\Plugin\IsGrantedPluginFactory; /** - * @covers \LmcRbacMvc\Factory\IsGrantedPluginFactory + * @covers \LmcRbacMvc\Mvc\Controller\Plugin\IsGrantedPluginFactory */ class IsGrantedPluginFactoryTest extends \PHPUnit\Framework\TestCase { diff --git a/tests/Factory/ModuleOptionsFactoryTest.php b/tests/Options/ModuleOptionsFactoryTest.php similarity index 93% rename from tests/Factory/ModuleOptionsFactoryTest.php rename to tests/Options/ModuleOptionsFactoryTest.php index 21421f30..9a95a3c3 100644 --- a/tests/Factory/ModuleOptionsFactoryTest.php +++ b/tests/Options/ModuleOptionsFactoryTest.php @@ -16,14 +16,14 @@ * and is licensed under the MIT license. */ -namespace LmcRbacMvcTest\Factory; +namespace LmcRbacMvcTest\Options; use Laminas\ServiceManager\Exception\ServiceNotCreatedException; use Laminas\ServiceManager\ServiceManager; -use LmcRbacMvc\Factory\ModuleOptionsFactory; +use LmcRbacMvc\Options\ModuleOptionsFactory; /** - * @covers \LmcRbacMvc\Factory\ModuleOptionsFactory + * @covers \LmcRbacMvc\Options\ModuleOptionsFactory */ class ModuleOptionsFactoryTest extends \PHPUnit\Framework\TestCase { diff --git a/tests/Factory/ObjectRepositoryRoleProviderFactoryTest.php b/tests/Role/ObjectRepositoryRoleProviderFactoryTest.php similarity index 94% rename from tests/Factory/ObjectRepositoryRoleProviderFactoryTest.php rename to tests/Role/ObjectRepositoryRoleProviderFactoryTest.php index f6e473e4..e50ab3ac 100644 --- a/tests/Factory/ObjectRepositoryRoleProviderFactoryTest.php +++ b/tests/Role/ObjectRepositoryRoleProviderFactoryTest.php @@ -16,7 +16,7 @@ * and is licensed under the MIT license. */ -namespace LmcRbacMvcTest\Factory; +namespace LmcRbacMvcTest\Role; use Laminas\ServiceManager\Exception\ServiceNotCreatedException; use Laminas\ServiceManager\ServiceManager; @@ -24,7 +24,7 @@ use LmcRbacMvc\Role\RoleProviderPluginManager; /** - * @covers \LmcRbacMvc\Factory\ObjectRepositoryRoleProviderFactory + * @covers \LmcRbacMvc\Role\ObjectRepositoryRoleProviderFactory */ class ObjectRepositoryRoleProviderFactoryTest extends \PHPUnit\Framework\TestCase { @@ -87,7 +87,7 @@ public function testThrowExceptionIfNoRoleNamePropertyIsSet() } $this->fail( - 'LmcRbacMvc\Factory\ObjectRepositoryRoleProviderFactory::createService() :: ' + 'LmcRbacMvc\Role\ObjectRepositoryRoleProviderFactory::createService() :: ' .'LmcRbac\Exception\RuntimeException was not found in the previous Exceptions' ); } @@ -114,7 +114,7 @@ public function testThrowExceptionIfNoObjectManagerNorObjectRepositoryIsSet() } $this->fail( - 'LmcRbacMvc\Factory\ObjectRepositoryRoleProviderFactory::createService() :: ' + 'LmcRbacMvc\Role\ObjectRepositoryRoleProviderFactory::createService() :: ' .'LmcRbac\Exception\RuntimeException was not found in the previous Exceptions' ); } diff --git a/tests/Factory/RoleProviderPluginManagerFactoryTest.php b/tests/Role/RoleProviderPluginManagerFactoryTest.php similarity index 91% rename from tests/Factory/RoleProviderPluginManagerFactoryTest.php rename to tests/Role/RoleProviderPluginManagerFactoryTest.php index c0078c8f..8c68dc88 100644 --- a/tests/Factory/RoleProviderPluginManagerFactoryTest.php +++ b/tests/Role/RoleProviderPluginManagerFactoryTest.php @@ -16,14 +16,14 @@ * and is licensed under the MIT license. */ -namespace LmcRbacMvcTest\Factory; +namespace LmcRbacMvcTest\Role; use Laminas\ServiceManager\ServiceManager; -use LmcRbacMvc\Factory\RoleProviderPluginManagerFactory; +use LmcRbacMvc\Role\RoleProviderPluginManagerFactory; use LmcRbacMvc\Role\RoleProviderPluginManager; /** - * @covers \LmcRbacMvc\Factory\RoleProviderPluginManagerFactory + * @covers \LmcRbacMvc\Role\RoleProviderPluginManagerFactory */ class RoleProviderPluginManagerFactoryTest extends \PHPUnit\Framework\TestCase { diff --git a/tests/Factory/AuthorizationServiceDelegatorTest.php b/tests/Service/AuthorizationServiceDelegatorTest.php similarity index 93% rename from tests/Factory/AuthorizationServiceDelegatorTest.php rename to tests/Service/AuthorizationServiceDelegatorTest.php index 3daa2c4a..8a9ab71d 100644 --- a/tests/Factory/AuthorizationServiceDelegatorTest.php +++ b/tests/Service/AuthorizationServiceDelegatorTest.php @@ -15,17 +15,19 @@ * This software consists of voluntary contributions made by many individuals * and is licensed under the MIT license. */ -namespace LmcRbacMvcTest\Factory; +namespace LmcRbacMvcTest\Service; +use Laminas\ServiceManager\Exception\ServiceNotCreatedException; use Psr\Container\ContainerInterface; use Laminas\ServiceManager\ServiceLocatorInterface; -use LmcRbacMvc\Factory\AuthorizationServiceDelegatorFactory; +use LmcRbacMvc\Service\AuthorizationServiceDelegatorFactory; use LmcRbacMvcTest\Initializer\AuthorizationAwareFake; use LmcRbacMvcTest\Util\ServiceManagerFactory; use Prophecy\PhpUnit\ProphecyTrait; +use stdClass; /** - * @covers \LmcRbacMvc\Factory\AuthorizationServiceDelegatorFactory + * @covers \LmcRbacMvc\Service\AuthorizationServiceDelegatorFactory * @author Jean-Marie Leroux * @license MIT License */ @@ -51,6 +53,7 @@ public function testDelegatorFactory() $serviceLocator->get($authServiceClassName)->willReturn($authorizationService)->shouldBeCalled(); + /** TODO replace this test */ $decoratedInstance = $delegator->createDelegatorWithName($serviceLocator->reveal(), 'name', 'requestedName', $callback); $this->assertEquals($authorizationService, $decoratedInstance->getAuthorizationService()); @@ -104,7 +107,7 @@ public function testAuthorizationServiceIsInjectedWithDelegatorV3() $serviceManager->addDelegator( 'LmcRbacMvcTest\Initializer\AuthorizationAwareFake', - 'LmcRbacMvc\Factory\AuthorizationServiceDelegatorFactory' + 'LmcRbacMvc\Service\AuthorizationServiceDelegatorFactory' ); $decoratedInstance = $serviceManager->get('LmcRbacMvcTest\AuthorizationAware'); @@ -116,7 +119,6 @@ public function testDelegatorThrowExceptionWhenBadInterface() $serviceManager = ServiceManagerFactory::getServiceManager(); $serviceManager->setAllowOverride(true); -// $authorizationService = $this->getMock('LmcRbacMvc\Service\AuthorizationService', [], [], '', false); $authorizationService = $this->getMockBuilder('LmcRbacMvc\Service\AuthorizationService') ->disableOriginalConstructor() ->getMock(); @@ -135,7 +137,7 @@ function () { $serviceManager->addDelegator( 'LmcRbacTest\AuthorizationAware', - 'LmcRbacMvc\Factory\AuthorizationServiceDelegatorFactory' + 'LmcRbacMvc\Service\AuthorizationServiceDelegatorFactory' ); $thrown = false; diff --git a/tests/Factory/AuthorizationServiceFactoryTest.php b/tests/Service/AuthorizationServiceFactoryTest.php similarity index 93% rename from tests/Factory/AuthorizationServiceFactoryTest.php rename to tests/Service/AuthorizationServiceFactoryTest.php index 6fa7d02b..ae1252a9 100644 --- a/tests/Factory/AuthorizationServiceFactoryTest.php +++ b/tests/Service/AuthorizationServiceFactoryTest.php @@ -16,16 +16,16 @@ * and is licensed under the MIT license. */ -namespace LmcRbacMvcTest\Factory; +namespace LmcRbacMvcTest\Service; use Laminas\Permissions\Rbac\Rbac; use Laminas\ServiceManager\ServiceManager; -use LmcRbacMvc\Factory\AuthorizationServiceFactory; +use LmcRbacMvc\Service\AuthorizationServiceFactory; use LmcRbacMvc\Options\ModuleOptions; use PHPUnit\Framework\TestCase; /** - * @covers \LmcRbacMvc\Factory\AuthorizationServiceFactory + * @covers \LmcRbacMvc\Service\AuthorizationServiceFactory */ class AuthorizationServiceFactoryTest extends TestCase { diff --git a/tests/Factory/RoleServiceFactoryTest.php b/tests/Service/RoleServiceFactoryTest.php similarity index 97% rename from tests/Factory/RoleServiceFactoryTest.php rename to tests/Service/RoleServiceFactoryTest.php index af414eaa..6ffaaf83 100644 --- a/tests/Factory/RoleServiceFactoryTest.php +++ b/tests/Service/RoleServiceFactoryTest.php @@ -16,15 +16,14 @@ * and is licensed under the MIT license. */ -namespace LmcRbacMvcTest\Factory; +namespace LmcRbacMvcTest\Service; use Laminas\ServiceManager\ServiceManager; -use LmcRbacMvc\Factory\RoleServiceFactory; +use LmcRbacMvc\Service\RoleServiceFactory; use LmcRbacMvc\Options\ModuleOptions; -use LmcRbacMvc\Role\RoleProviderPluginManager; /** - * @covers \LmcRbacMvc\Factory\RoleServiceFactory + * @covers \LmcRbacMvc\Service\RoleServiceFactory */ class RoleServiceFactoryTest extends \PHPUnit\Framework\TestCase { diff --git a/tests/View/Helper/HasRoleTest.php b/tests/View/Helper/HasRoleTest.php index 011f44c9..01478ffa 100644 --- a/tests/View/Helper/HasRoleTest.php +++ b/tests/View/Helper/HasRoleTest.php @@ -34,7 +34,7 @@ public function testHelperIsRegistered() $viewHelpersConfig = $config['view_helpers']; $this->assertEquals('LmcRbacMvc\View\Helper\HasRole', $viewHelpersConfig['aliases']['hasRole']); $this->assertEquals( - 'LmcRbacMvc\Factory\HasRoleViewHelperFactory', + 'LmcRbacMvc\View\Helper\HasRoleViewHelperFactory', $viewHelpersConfig['factories']['LmcRbacMvc\View\Helper\HasRole'] ); } diff --git a/tests/Factory/HasRoleViewHelperFactoryTest.php b/tests/View/Helper/HasRoleViewHelperFactoryTest.php similarity index 84% rename from tests/Factory/HasRoleViewHelperFactoryTest.php rename to tests/View/Helper/HasRoleViewHelperFactoryTest.php index 9b4ca3ff..d12a9bde 100644 --- a/tests/Factory/HasRoleViewHelperFactoryTest.php +++ b/tests/View/Helper/HasRoleViewHelperFactoryTest.php @@ -16,14 +16,14 @@ * and is licensed under the MIT license. */ -namespace LmcRbacMvcTest\Factory; +namespace LmcRbacMvcTest\View\Helper; use Laminas\ServiceManager\ServiceManager; use Laminas\View\HelperPluginManager; -use LmcRbacMvc\Factory\HasRoleViewHelperFactory; +use LmcRbacMvc\View\Helper\HasRoleViewHelperFactory; /** - * @covers \LmcRbacMvc\Factory\HasRoleViewHelperFactory + * @covers \LmcRbacMvc\View\Helper\HasRoleViewHelperFactory */ class HasRoleViewHelperFactoryTest extends \PHPUnit\Framework\TestCase { @@ -31,10 +31,6 @@ public function testFactory() { $serviceManager = new ServiceManager(); - if (!method_exists($serviceManager, 'build')) { - $this->markTestSkipped('this test is only vor zend-servicemanager v3'); - } - $serviceManager->setService( 'LmcRbacMvc\Service\RoleService', $this->getMockBuilder('LmcRbacMvc\Service\RoleService')->disableOriginalConstructor()->getMock() diff --git a/tests/View/Helper/IsGrantedTest.php b/tests/View/Helper/IsGrantedTest.php index 6450247f..986d691b 100644 --- a/tests/View/Helper/IsGrantedTest.php +++ b/tests/View/Helper/IsGrantedTest.php @@ -34,7 +34,7 @@ public function testHelperIsRegistered() $viewHelpersConfig = $config['view_helpers']; $this->assertEquals('LmcRbacMvc\View\Helper\IsGranted', $viewHelpersConfig['aliases']['isGranted']); $this->assertEquals( - 'LmcRbacMvc\Factory\IsGrantedViewHelperFactory', + 'LmcRbacMvc\View\Helper\IsGrantedViewHelperFactory', $viewHelpersConfig['factories']['LmcRbacMvc\View\Helper\IsGranted'] ); } diff --git a/tests/Factory/IsGrantedViewHelperFactoryTest.php b/tests/View/Helper/IsGrantedViewHelperFactoryTest.php similarity index 82% rename from tests/Factory/IsGrantedViewHelperFactoryTest.php rename to tests/View/Helper/IsGrantedViewHelperFactoryTest.php index d11f6da8..0992f1a3 100644 --- a/tests/Factory/IsGrantedViewHelperFactoryTest.php +++ b/tests/View/Helper/IsGrantedViewHelperFactoryTest.php @@ -16,14 +16,13 @@ * and is licensed under the MIT license. */ -namespace LmcRbacMvcTest\Factory; +namespace LmcRbacMvcTest\View\Helper; use Laminas\ServiceManager\ServiceManager; -use Laminas\View\HelperPluginManager; -use LmcRbacMvc\Factory\IsGrantedViewHelperFactory; +use LmcRbacMvc\View\Helper\IsGrantedViewHelperFactory; /** - * @covers \LmcRbacMvc\Factory\IsGrantedViewHelperFactory + * @covers \LmcRbacMvc\View\Helper\IsGrantedViewHelperFactory */ class IsGrantedViewHelperFactoryTest extends \PHPUnit\Framework\TestCase { @@ -31,9 +30,6 @@ public function testFactory() { $serviceManager = new ServiceManager(); - if (! method_exists($serviceManager, 'build')) { - $this->markTestSkipped('this test is only vor zend-servicemanager v3'); - } $serviceManager->setService( 'LmcRbacMvc\Service\AuthorizationService', $this->createMock('LmcRbacMvc\Service\AuthorizationServiceInterface') diff --git a/tests/Factory/RedirectStrategyFactoryTest.php b/tests/View/Strategy/RedirectStrategyFactoryTest.php similarity index 94% rename from tests/Factory/RedirectStrategyFactoryTest.php rename to tests/View/Strategy/RedirectStrategyFactoryTest.php index 5e0d679b..4e3c777b 100644 --- a/tests/Factory/RedirectStrategyFactoryTest.php +++ b/tests/View/Strategy/RedirectStrategyFactoryTest.php @@ -16,15 +16,15 @@ * and is licensed under the MIT license. */ -namespace LmcRbacMvcTest\Factory; +namespace LmcRbacMvcTest\View\Strategy; -use Psr\Container\ContainerInterface; use Laminas\ServiceManager\ServiceLocatorInterface; -use LmcRbacMvc\Factory\RedirectStrategyFactory; +use LmcRbacMvc\View\Strategy\RedirectStrategyFactory; use Prophecy\PhpUnit\ProphecyTrait; +use Psr\Container\ContainerInterface; /** - * @covers \LmcRbacMvc\Factory\RedirectStrategyFactory + * @covers \LmcRbacMvc\View\Strategy\RedirectStrategyFactory */ class RedirectStrategyFactoryTest extends \PHPUnit\Framework\TestCase { diff --git a/tests/Factory/UnauthorizedStrategyFactoryTest.php b/tests/View/Strategy/UnauthorizedStrategyFactoryTest.php similarity index 92% rename from tests/Factory/UnauthorizedStrategyFactoryTest.php rename to tests/View/Strategy/UnauthorizedStrategyFactoryTest.php index 96a7167d..e2a0df65 100644 --- a/tests/Factory/UnauthorizedStrategyFactoryTest.php +++ b/tests/View/Strategy/UnauthorizedStrategyFactoryTest.php @@ -16,14 +16,14 @@ * and is licensed under the MIT license. */ -namespace LmcRbacMvcTest\Factory; +namespace LmcRbacMvcTest\View\Strategy; -use Psr\Container\ContainerInterface; -use LmcRbacMvc\Factory\UnauthorizedStrategyFactory; +use LmcRbacMvc\View\Strategy\UnauthorizedStrategyFactory; use Prophecy\PhpUnit\ProphecyTrait; +use Psr\Container\ContainerInterface; /** - * @covers \LmcRbacMvc\Factory\UnauthorizedStrategyFactory + * @covers \LmcRbacMvc\View\Strategy\UnauthorizedStrategyFactory */ class UnauthorizedStrategyFactoryTest extends \PHPUnit\Framework\TestCase {