-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from visto9259/2.x
Refactored factories
- Loading branch information
Showing
22 changed files
with
324 additions
and
29 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
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,41 @@ | ||
<?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. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LmcRbac\Assertion; | ||
|
||
use LmcRbac\Assertion\AssertionContainer; | ||
use Psr\Container\ContainerInterface; | ||
|
||
/** | ||
* Factory to create a assertion plugin manager | ||
* | ||
* @author Aeneas Rekkas | ||
* @licence MIT | ||
*/ | ||
final class AssertionContainerFactory | ||
{ | ||
public function __invoke(ContainerInterface $container): AssertionContainer | ||
{ | ||
$config = $container->get('config')['lmc_rbac']['assertion_manager']; | ||
|
||
return new AssertionContainer($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 |
---|---|---|
|
@@ -33,6 +33,7 @@ | |
* | ||
* @author Michaël Gallego <[email protected]> | ||
* @licence MIT | ||
* @deprecated Replaced by LmcRbac\Service\AuthorizationServiceFactory | ||
*/ | ||
final class AuthorizationServiceFactory | ||
{ | ||
|
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 |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
* | ||
* @author Michaël Gallego <[email protected]> | ||
* @licence MIT | ||
* @deprecated Replaced by LmcRbac\Options\ModuleOptionsFactory | ||
*/ | ||
final class ModuleOptionsFactory | ||
{ | ||
|
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,6 +31,7 @@ | |
* | ||
* @author Michaël Gallego <[email protected]> | ||
* @licence MIT | ||
* @deprecated Replaced by LmcRbac\Role\ObjectRepositoryRoleProviderFactory | ||
*/ | ||
final class ObjectRepositoryRoleProviderFactory | ||
{ | ||
|
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,6 +31,7 @@ | |
* | ||
* @author Michaël Gallego <[email protected]> | ||
* @licence MIT | ||
* @deprecated Replaced by LmcRbac\Service\RoleServiceFactory | ||
*/ | ||
final class RoleServiceFactory | ||
{ | ||
|
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 |
---|---|---|
|
@@ -29,29 +29,29 @@ | |
* @author Michaël Gallego <[email protected]> | ||
* @licence MIT | ||
*/ | ||
final class ModuleOptions extends AbstractOptions | ||
class ModuleOptions extends AbstractOptions | ||
{ | ||
/** | ||
* Guest role (used when no identity is found) | ||
* | ||
* @var string | ||
*/ | ||
protected $guestRole = 'guest'; | ||
protected string $guestRole = 'guest'; | ||
|
||
/** | ||
* Assertion map | ||
* | ||
* @var array | ||
*/ | ||
protected $assertionMap = []; | ||
protected array $assertionMap = []; | ||
|
||
/** | ||
* A configuration for role provider | ||
* Defaults to InMemoryRoleProvider | ||
* | ||
* @var array | ||
*/ | ||
protected $roleProvider = [ | ||
protected array $roleProvider = [ | ||
'LmcRbac\Role\InMemoryRoleProvider' => [], | ||
]; | ||
|
||
|
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,39 @@ | ||
<?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. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LmcRbac\Options; | ||
|
||
use LmcRbac\Options\ModuleOptions; | ||
use Psr\Container\ContainerInterface; | ||
|
||
/** | ||
* Factory for the module options | ||
* | ||
* @author Michaël Gallego <[email protected]> | ||
* @licence MIT | ||
*/ | ||
final class ModuleOptionsFactory | ||
{ | ||
public function __invoke(ContainerInterface $container): ModuleOptions | ||
{ | ||
return new ModuleOptions($container->get('config')['lmc_rbac']); | ||
} | ||
} |
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. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LmcRbac\Role; | ||
|
||
use LmcRbac\Options\ModuleOptions; | ||
use LmcRbac\Role\InMemoryRoleProvider; | ||
use Psr\Container\ContainerInterface; | ||
|
||
/** | ||
* Factory used to create an in memory role provider | ||
* | ||
* @author Vytautas Stankus | ||
* @licence MIT | ||
*/ | ||
final class InMemoryRoleProviderFactory | ||
{ | ||
public function __invoke(ContainerInterface $container): InMemoryRoleProvider | ||
{ | ||
$moduleOptions = $container->get(ModuleOptions::class); | ||
|
||
return new InMemoryRoleProvider( | ||
$moduleOptions->getRoleProvider()[InMemoryRoleProvider::class] ?? [] | ||
); | ||
} | ||
} |
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,64 @@ | ||
<?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. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LmcRbac\Role; | ||
|
||
use LmcRbac\Exception; | ||
use LmcRbac\Options\ModuleOptions; | ||
use LmcRbac\Role\ObjectRepositoryRoleProvider; | ||
use Psr\Container\ContainerInterface; | ||
|
||
/** | ||
* Factory used to create an object repository role provider | ||
* | ||
* @author Michaël Gallego <[email protected]> | ||
* @licence MIT | ||
*/ | ||
final class ObjectRepositoryRoleProviderFactory | ||
{ | ||
public function __invoke(ContainerInterface $container): ObjectRepositoryRoleProvider | ||
{ | ||
$moduleOptions = $container->get(ModuleOptions::class); | ||
$options = $moduleOptions->getRoleProvider()[ObjectRepositoryRoleProvider::class] ?? []; | ||
|
||
if (! isset($options['role_name_property'])) { | ||
throw new Exception\RuntimeException('The "role_name_property" option is missing'); | ||
} | ||
|
||
if (isset($options['object_repository'])) { | ||
$objectRepository = $container->get($options['object_repository']); | ||
|
||
return new ObjectRepositoryRoleProvider($objectRepository, $options['role_name_property']); | ||
} | ||
|
||
if (isset($options['object_manager'], $options['class_name'])) { | ||
$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 LmcRbac object repository role provider. Are | ||
you sure you specified either the "object_repository" option or "object_manager"/"class_name" options?' | ||
); | ||
} | ||
} |
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,50 @@ | ||
<?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. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LmcRbac\Service; | ||
|
||
use LmcRbac\Assertion\AssertionContainerInterface; | ||
use LmcRbac\Options\ModuleOptions; | ||
use LmcRbac\Rbac; | ||
use LmcRbac\Service\AuthorizationService; | ||
use LmcRbac\Service\RoleServiceInterface; | ||
use Psr\Container\ContainerInterface; | ||
|
||
/** | ||
* Factory to create the authorization service | ||
* | ||
* @author Michaël Gallego <[email protected]> | ||
* @licence MIT | ||
*/ | ||
final class AuthorizationServiceFactory | ||
{ | ||
public function __invoke(ContainerInterface $container): AuthorizationService | ||
{ | ||
$moduleOptions = $container->get(ModuleOptions::class); | ||
|
||
return new AuthorizationService( | ||
$container->get(Rbac::class), | ||
$container->get(RoleServiceInterface::class), | ||
$container->get(AssertionContainerInterface::class), | ||
$moduleOptions->getAssertionMap() | ||
); | ||
} | ||
} |
Oops, something went wrong.