Skip to content

Commit

Permalink
Merge pull request #85 from visto9259/2.0.x
Browse files Browse the repository at this point in the history
Updated docs. Moved to laminas rbac
  • Loading branch information
visto9259 authored Aug 27, 2024
2 parents 12d00b8 + c6986b9 commit ae7b1c6
Show file tree
Hide file tree
Showing 73 changed files with 1,401 additions and 973 deletions.
16 changes: 11 additions & 5 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,26 @@

## From LmcRbac v1 to LmcRbac v2

LmcRbac v2 is a major version upgrade with many breaking changes that prevent
LmcRbac v2 is a major version upgrade with many major breaking changes that prevent
straightforward upgrading.

### Major changes

- LmcRbac v2 is now based on Role and Rbac classes from `laminas-permissions-rbac`. All services have
been updated to use these classes and interfaces.


### Namespace change

The namespace has been changed from LmcRbac to Lmc\Rbac. Please review your code to replace `LmcRbac` namespace
by `Lmc\Rbac` namespace.

### Deprecations
### Deprecations and removals

- `Lmc\Rbac\HierarchicalRole` has been deprecated since `Lmc\Rbac\Role` now supports hierarchical roles. Flat roles
are just a simplified version of a hierarchical roles. Use `Lmc\Rbac\Role` instead.
- `LmcRbac\HierarchicalRole`, `LmcRbac\Role` and `LmcRbac\RoleInterface` has been deleted.
Use the equivalent classes from `laminas-permissions-rbac` instead.
- The factories for services have been refactored from the `src/Container` folder
to be colocated with the service that a factory is creating. All factories in the `src/Container` has been deprecated.
to be colocated with the service that a factory is creating. All factories in the `src/Container` has been deleted.
- The `AssertionContainer` class, interface and factory have been deprecated and replaced by `AssertionPluginManager` class, interface and factory.

## From ZfcRbac v3 to LmcRbac v1
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
],
"require": {
"php": "^8.1 || ^8.2 || ^8.3",
"laminas/laminas-permissions-rbac": "^3.0",
"laminas/laminas-servicemanager": "^3.3",
"laminas/laminas-stdlib": "^3.1",
"doctrine/persistence": "^2.0 || ^3.0"
Expand Down
122 changes: 91 additions & 31 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 1 addition & 9 deletions config/lmcrbac.global.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@ declare(strict_types=1);
return [
'lmc_rbac' => [

/**
* Key that is used to fetch the identity provider
*
* Please note that when an identity is found, it MUST implement the LmcRbac\Identity\IdentityProviderInterface
* interface, otherwise it will throw an exception.
*/
// 'identity_provider' => 'LmcRbac\Identity\AuthenticationIdentityProvider',

/**
* Set the guest role
*
Expand All @@ -50,7 +42,7 @@ return [
*
* The provider config for InMemoryRoleProvider must follow the following format:
*
* 'LmcRbac\Role\InMemoryRoleProvider' => [
* Lmc\Rbac\Role\InMemoryRoleProvider::class => [
* 'role1' => [
* 'children' => ['children1', 'children2'], // OPTIONAL
* 'permissions' => ['edit', 'read'] // OPTIONAL
Expand Down
36 changes: 19 additions & 17 deletions data/FlatRole.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ declare(strict_types=1);
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Lmc\Rbac\Permission\PermissionInterface;
use Lmc\Rbac\Role\RoleInterface;
use Laminas\Permissions\Rbac\RoleInterface;

/**
* @ORM\Entity
Expand All @@ -45,12 +44,12 @@ class FlatRole implements RoleInterface
protected ?int $id;

/**
* @var string|null
* @var string
*
* @ORM\Column(type="string", length=255, unique=true)
*/
#[ORM\Column(name: 'name', type: 'string', length: 255, unique: true)]
protected ?string $name;
protected string $name = '';

/**
* @var Permission[]|Collection
Expand Down Expand Up @@ -101,28 +100,21 @@ class FlatRole implements RoleInterface
/**
* @inheritDoc
*/
public function addPermission(PermissionInterface|string $permission): void
public function addPermission(string $name): void
{
if (is_string($permission)) {
$permission = new Permission($permission);
}
$permission = new Permission($name);

$this->permissions[(string) $permission] = $permission;
$this->permissions[$name] = $permission;
}

/**
* @inheritDoc
*/
public function hasPermission(PermissionInterface|string $permission): bool
public function hasPermission(string $name): bool
{
// This can be a performance problem if your role has a lot of permissions. Please refer
// to the cookbook to an elegant way to solve this issue

return isset($this->permissions[(string) $permission]);
return isset($this->permissions[$name]);
}



public function getChildren(): iterable
{
return [];
Expand All @@ -133,8 +125,18 @@ class FlatRole implements RoleInterface
return false;
}

public function addChild(RoleInterface $role): void
public function addChild(RoleInterface $child): void
{
// Do nothing
}

public function addParent(RoleInterface $parent): void
{
// Do nothing
}

public function getParents(): iterable
{
return [];
}
}
Loading

0 comments on commit ae7b1c6

Please sign in to comment.