Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced Exception classes by LmcRbac's #97

Merged
merged 2 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"laminas/laminas-mvc": "^3.0",
"laminas/laminas-servicemanager": "^3.0",
"laminas/laminas-permissions-rbac": "^3.0",
"doctrine/persistence": "^2.1"
"doctrine/persistence": "^2.1",
"lm-commons/lmc-rbac": "2.x-dev"
},
"require-dev": {
"laminas/laminas-authentication": "^2.2",
Expand All @@ -58,9 +59,6 @@
"laminas/laminas-developer-tools": "if you want to show information about the roles",
"doctrine/doctrine-module": "if you want to use Doctrine role provider"
},
"replace": {
"laminas-commons/lmc-rbac-mvc": "3.0.1"
},
"autoload": {
"psr-4": {
"LmcRbacMvc\\": "src"
Expand Down
95 changes: 0 additions & 95 deletions config/module.config.php

This file was deleted.

4 changes: 2 additions & 2 deletions docs/docs/cookbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ check for the `deletePost` permission. We don't want others to delete our previo
called `assertion_map`. In this map we glue `assertions` and `permissions` together.

```php
// module.config.php or wherever you configure your RBAC stuff
// config/autoload/lmc_rbac.global.php or wherever your LmcRbac configuration file is
return [
'lmc_rbac' => [
'assertion_map' => [
Expand All @@ -376,7 +376,7 @@ However, some assertions may need dependencies. You can manually configure the a
shown below:

```php
// module.config.php or wherever you configure your RBAC stuff
// config/autoload/lmc_rbac.global.php or wherever your LmcRbac configuration file is
return [
'lmc_rbac' => [
// ... other rbac stuff
Expand Down
2 changes: 1 addition & 1 deletion src/Collector/RbacCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
use Laminas\DeveloperTools\Collector\CollectorInterface;
use LmcRbacMvc\Options\ModuleOptions;
use LmcRbacMvc\Service\RoleService;
use LmcRbacMvc\Exception\InvalidArgumentException;
use LmcRbac\Exception\InvalidArgumentException;

/**
* RbacCollector
Expand Down
90 changes: 90 additions & 0 deletions src/ConfigProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php

namespace LmcRbacMvc;

class ConfigProvider
{
public function __invoke(): array
{
return [
'dependencies' => $this->getDependencies(),
'view_helpers' => $this->getViewHelperConfig(),
'controller_plugins' => $this->getControllerPluginConfig(),
'view_manager' => $this->getViewManagerConfig(),
'lmc_rbac' => $this->getModuleConfig(),
];
}

public function getDependencies(): array
{
return [
'factories' => [
/* Factories that do not map to a class */
'LmcRbacMvc\Guards' => \LmcRbacMvc\Factory\GuardsFactory::class,

/* Factories that map to a class */
\LmcRbacMvc\Assertion\AssertionPluginManager::class => \LmcRbacMvc\Factory\AssertionPluginManagerFactory::class,
// TODO Remove RbacCollector once it is moved to a separate library
\LmcRbacMvc\Collector\RbacCollector::class => \Laminas\ServiceManager\Factory\InvokableFactory::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,
],
];
}

public function getModuleConfig(): array
{
return [
// Guard plugin manager
'guard_manager' => [],

// Role provider plugin manager
'role_provider_manager' => [],

// Assertion plugin manager
'assertion_manager' => []
];
}

public function getControllerPluginConfig(): array
{
return [
'factories' => [
\LmcRbacMvc\Mvc\Controller\Plugin\IsGranted::class => \LmcRbacMvc\Factory\IsGrantedPluginFactory::class,
],
'aliases' => [
'isGranted' => \LmcRbacMvc\Mvc\Controller\Plugin\IsGranted::class,
],
];
}

public function getViewHelperConfig(): array
{
return [
'factories' => [
\LmcRbacMvc\View\Helper\IsGranted::class => \LmcRbacMvc\Factory\IsGrantedViewHelperFactory::class,
\LmcRbacMvc\View\Helper\HasRole::class => \LmcRbacMvc\Factory\HasRoleViewHelperFactory::class,
],
'aliases' => [
'isGranted' => \LmcRbacMvc\View\Helper\IsGranted::class,
'hasRole' => \LmcRbacMvc\View\Helper\HasRole::class,
],
];
}

public function getViewManagerConfig(): array
{
return [
'template_map' => [
'error/403' => __DIR__ . '/../view/error/403.phtml',
'laminas-developer-tools/toolbar/lmc-rbac' => __DIR__ . '/../view/laminas-developer-tools/toolbar/lmc-rbac.phtml'
],
];
}
}
1 change: 1 addition & 0 deletions src/Exception/ExceptionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*
* @author Michaël Gallego <[email protected]>
* @license MIT
* @deprecated Use LmcRbac\Exception\ExceptionInterface instead
*/
interface ExceptionInterface
{
Expand Down
5 changes: 2 additions & 3 deletions src/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@

namespace LmcRbacMvc\Exception;

use InvalidArgumentException as BaseInvalidArgumentException;

/**
* InvalidArgumentException
*
* @author Michaël Gallego <[email protected]>
* @license MIT
* @deprecated Use LmcRbac\Exception\InvalidArgumentException instead
*/
class InvalidArgumentException extends BaseInvalidArgumentException implements ExceptionInterface
class InvalidArgumentException extends \LmcRbac\Exception\InvalidArgumentException
{
}
3 changes: 2 additions & 1 deletion src/Exception/RoleNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
*
* @author Michaël Gallego <[email protected]>
* @license MIT
* @deprecated Use LmcRbac\Exception\RoleNotFoundException instead
*/
class RoleNotFoundException extends BaseRuntimeException implements ExceptionInterface
class RoleNotFoundException extends \LmcRbac\Exception\RoleNotFoundException
{
/**
* @var string
Expand Down
5 changes: 2 additions & 3 deletions src/Exception/RuntimeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@

namespace LmcRbacMvc\Exception;

use RuntimeException as BaseRuntimeException;

/**
* RuntimeException
*
* @author Michaël Gallego <[email protected]>
* @license MIT
* @deprecated Use LmcRbac\Exception\RuntimeException instead
*/
class RuntimeException extends BaseRuntimeException implements ExceptionInterface
class RuntimeException extends \LmcRbac\Exception\RuntimeException
{
}
8 changes: 2 additions & 6 deletions src/Exception/UnauthorizedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,14 @@

namespace LmcRbacMvc\Exception;

use RuntimeException as BaseRuntimeException;

/**
* Unauthorized exception
*
* @author Michaël Gallego <[email protected]>
* @license MIT
* @deprecated Use LmcRbac\Exception\UnauthorizedException instead
*/
class UnauthorizedException extends BaseRuntimeException implements UnauthorizedExceptionInterface
class UnauthorizedException extends \LmcRbac\Exception\UnauthorizedException
{
/**
* @var string
*/
protected $message = 'You are not authorized to access this resource';
}
1 change: 1 addition & 0 deletions src/Exception/UnauthorizedExceptionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*
* @author Michaël Gallego <[email protected]>
* @license MIT
* @deprecated Use LmcRbac\Exception\UnauthorizedExceptionInterface instead
*/
interface UnauthorizedExceptionInterface extends ExceptionInterface
{
Expand Down
2 changes: 1 addition & 1 deletion src/Factory/AuthorizationServiceDelegatorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
//use Laminas\ServiceManager\AbstractPluginManager;
use Laminas\ServiceManager\Factory\DelegatorFactoryInterface;
use Laminas\ServiceManager\ServiceLocatorInterface;
use LmcRbacMvc\Exception\RuntimeException;
use LmcRbac\Exception\RuntimeException;
use LmcRbacMvc\Service\AuthorizationService;
use LmcRbacMvc\Service\AuthorizationServiceAwareInterface;

Expand Down
1 change: 0 additions & 1 deletion src/Factory/RoleServiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use Psr\Container\ContainerInterface;
use Laminas\ServiceManager\Factory\FactoryInterface;
use Laminas\ServiceManager\ServiceLocatorInterface;
use LmcRbacMvc\Exception\RuntimeException;
use LmcRbacMvc\Identity\IdentityProviderInterface;
use LmcRbacMvc\Options\ModuleOptions;
use LmcRbacMvc\Role\RoleProviderInterface;
Expand Down
2 changes: 1 addition & 1 deletion src/Guard/RoutePermissionsGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
namespace LmcRbacMvc\Guard;

use Laminas\Mvc\MvcEvent;
use LmcRbacMvc\Exception\InvalidArgumentException;
use LmcRbac\Exception\InvalidArgumentException;
use LmcRbacMvc\Service\AuthorizationServiceInterface;

/**
Expand Down
15 changes: 11 additions & 4 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ class Module implements BootstrapListenerInterface, ConfigProviderInterface
/**
* {@inheritDoc}
*/
public function onBootstrap(EventInterface $event): void
public function onBootstrap(EventInterface $e): void
{
/* @var Application $application */
$application = $event->getTarget();
$application = $e->getTarget();
$serviceManager = $application->getServiceManager();
$eventManager = $application->getEventManager();

Expand All @@ -54,8 +54,15 @@ public function onBootstrap(EventInterface $event): void
/**
* {@inheritDoc}
*/
public function getConfig()
public function getConfig(): array
{
return include __DIR__ . '/../config/module.config.php';
$configProvider = new ConfigProvider();
return [
'service_manager' => $configProvider->getDependencies(),
'view_helpers' => $configProvider->getViewHelperConfig(),
'controller_plugins' => $configProvider->getControllerPluginConfig(),
'view_manager' => $configProvider->getViewManagerConfig(),
'lmc_rbac' => $configProvider->getModuleConfig(),
];
}
}
2 changes: 1 addition & 1 deletion src/Role/ObjectRepositoryRoleProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
namespace LmcRbacMvc\Role;

use Doctrine\Persistence\ObjectRepository;
use LmcRbacMvc\Exception\RoleNotFoundException;
use LmcRbac\Exception\RoleNotFoundException;

/**
* Role provider that uses Doctrine object repository to fetch roles
Expand Down
2 changes: 1 addition & 1 deletion src/View/Strategy/RedirectStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use Laminas\Authentication\AuthenticationServiceInterface;
use Laminas\Http\Response as HttpResponse;
use Laminas\Mvc\MvcEvent;
use LmcRbacMvc\Exception\UnauthorizedExceptionInterface;
use LmcRbac\Exception\UnauthorizedExceptionInterface;
use LmcRbacMvc\Options\RedirectStrategyOptions;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/View/Strategy/UnauthorizedStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use Laminas\Http\Response as HttpResponse;
use Laminas\Mvc\MvcEvent;
use Laminas\View\Model\ViewModel;
use LmcRbacMvc\Exception\UnauthorizedExceptionInterface;
use LmcRbac\Exception\UnauthorizedExceptionInterface;
use LmcRbacMvc\Guard\GuardInterface;
use LmcRbacMvc\Options\UnauthorizedStrategyOptions;

Expand Down
Loading
Loading