Skip to content

Commit

Permalink
Move factories to the same folder as the class they are creating (LM-…
Browse files Browse the repository at this point in the history
  • Loading branch information
visto9259 committed Jul 11, 2024
1 parent 8c136e6 commit 3354dc1
Show file tree
Hide file tree
Showing 62 changed files with 1,218 additions and 641 deletions.
44 changes: 44 additions & 0 deletions src/Assertion/AssertionPluginManagerFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/

namespace LmcRbacMvc\Assertion;

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
*/
class AssertionPluginManagerFactory implements FactoryInterface
{
/**
* {@inheritDoc}
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null): AssertionPluginManager
{
$config = $container->get('Config')['lmc_rbac']['assertion_manager'];

return new AssertionPluginManager($container, $config);
}
}
26 changes: 13 additions & 13 deletions src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
];
}
Expand All @@ -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,
Expand All @@ -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,
Expand Down
18 changes: 2 additions & 16 deletions src/Factory/AssertionPluginManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
19 changes: 2 additions & 17 deletions src/Factory/AuthenticationIdentityProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
* @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);
}
}
39 changes: 2 additions & 37 deletions src/Factory/AuthorizationServiceDelegatorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
* @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);
}
}
33 changes: 2 additions & 31 deletions src/Factory/AuthorizationServiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
* @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;
}
}
48 changes: 2 additions & 46 deletions src/Factory/ControllerGuardFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
* @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;
}
}
41 changes: 2 additions & 39 deletions src/Factory/ControllerPermissionsGuardFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,45 +31,8 @@
*
* @author JM Lerouxw <[email protected]>
* @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;
}
}
13 changes: 3 additions & 10 deletions src/Factory/GuardPluginManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,16 +30,8 @@
*
* @author Michaël Gallego <[email protected]>
* @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);
}
}
Loading

0 comments on commit 3354dc1

Please sign in to comment.