forked from LM-Commons/LmcRbacMvc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move factories to the same folder as the class they are creating (LM-…
- Loading branch information
Showing
62 changed files
with
1,218 additions
and
641 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 <[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); | ||
} | ||
} |
Oops, something went wrong.