Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
visto9259 committed Feb 29, 2024
1 parent 960c07f commit d5580f4
Show file tree
Hide file tree
Showing 96 changed files with 1,112 additions and 1,005 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"laminas/laminas-i18n": "^2.7",
"laminas/laminas-serializer": "^2.2",
"laminas/laminas-view": "^2.12",
"phpunit/phpunit": "9.5.21",
"phpunit/phpunit": "10.5.11",
"squizlabs/php_codesniffer": "^3.5.5",
"php-coveralls/php-coveralls": "^2.2",
"phpspec/prophecy-phpunit": "^2.0",
Expand Down
10 changes: 9 additions & 1 deletion config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@

return [
'service_manager' => [
'aliases' => [
'Rbac' => 'rbac',
],
'factories' => [
/* Factories that do not map to a class */
'LmcRbacMvc\Guards' => \LmcRbacMvc\Factory\GuardsFactory::class,
'rbac' => \LmcRbacMvc\Factory\RbacFactory::class,

/* Factories that map to a class */
\Rbac\Rbac::class => \LmcRbacMvc\Factory\RbacFactory::class,
\LmcRbacMvc\Assertion\AssertionPluginManager::class => \LmcRbacMvc\Factory\AssertionPluginManagerFactory::class,
\LmcRbacMvc\Collector\RbacCollector::class => \Laminas\ServiceManager\Factory\InvokableFactory::class,
\LmcRbacMvc\Guard\GuardPluginManager::class => \LmcRbacMvc\Factory\GuardPluginManagerFactory::class,
Expand Down Expand Up @@ -64,6 +67,10 @@
]
],

/*
* Developer tools are now provided by the companion module LmcRbacMvcDevTools
* You can still use the config below but you are encouraged to use the new module
*
'laminas-developer-tools' => [
'profiler' => [
'collectors' => [
Expand All @@ -76,6 +83,7 @@
],
],
],
*/

'lmc_rbac' => [
// Guard plugin manager
Expand Down
85 changes: 45 additions & 40 deletions data/FlatRole.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,21 @@
* and is licensed under the MIT license.
*/


use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Laminas\Permissions\Rbac\RoleInterface;
use Doctrine\ORM\Mapping as ORM;
use Rbac\Role\RoleInterface;
use LmcRbac\Permission\PermissionInterface;

/**
* There is no specific implementation of a flot role.
* A flot role is a simple utilization of the Laminas\Permission\Rbac\Role without children
*/


/**
* @ORM\Entity
* @ORM\Table(name="roles")
* @ORM\Table(name="flat_roles")
*/
class FlatRole implements RoleInterface
{
Expand All @@ -32,83 +39,81 @@ class FlatRole implements RoleInterface
*
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\GeneratedValue
*/
protected $id;
private ?int $id;

/**
* @var string|null
*
* @ORM\Column(type="string", length=48, unique=true)
* @ORM\Column(type="string", length=32, unique=true)
*/
protected $name;
protected ?string $name;

/**
* @var PermissionInterface[]|\Doctrine\Common\Collections\Collection
*
* @ORM\ManyToMany(targetEntity="Permission", indexBy="name", fetch="EAGER", cascade={"persist"})
* @var Collection
* @ORM\ManyToMany(targetEntity="Permission", indexBy="name", cascade={"persist"}, fetch="EAGER")
*/
protected $permissions;
protected Collection $permissions;

/**
* Init the Doctrine collection
*/
public function __construct()
public function __construct($name)
{
$this->name = (string) $name;
$this->permissions = new ArrayCollection();
}

/**
* Get the role identifier
*
* @return int
* @return int|null
*/
public function getId()
public function getId(): ?int
{
return $this->id;
}

/**
* Set the role name
* Add a permission
*
* @param string $name
* @param string $name
* @return void
*/
public function setName($name)
public function addPermission(string $name):void
{
$this->name = (string) $name;
$permission = new \LmcRbacMvcTest\Asset\Permission($name);

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

/**
* Get the role name
*
* @return string
*/
public function getName()
public function getName(): string
{
return $this->name;
}

/**
* {@inheritDoc}
*/
public function addPermission($permission)
public function hasPermission(string $name): bool
{
if (is_string($permission)) {
$permission = new Permission($permission);
}
return isset($this->permissions[$name]);
}

$this->permissions[(string) $permission] = $permission;
public function addChild(RoleInterface $child): void
{
// Do nothing
}

/**
* {@inheritDoc}
*/
public function hasPermission($permission)
public function getChildren(): iterable
{
// 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 [];
}

return isset($this->permissions[(string) $permission]);
public function addParent(RoleInterface $parent): void
{
// Do nothing
}

public function getParents(): iterable
{
return [];
}
}
33 changes: 20 additions & 13 deletions data/Permission.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,27 @@
* and is licensed under the MIT license.
*/


use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use LmcRbac\Permission\PermissionInterface;

/**
* @ORM\Entity
* @ORM\Table(name="permissions")
*/
class Permission implements PermissionInterface
class Permission
{
/**
* @var int|null
*
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
private ?int $id;

/**
* @var string|null
*
* @ORM\Column(type="string", length=128, unique=true)
* @ORM\Column(type="string", length=32, unique=true)
*/
protected $name;
private ?string $name;

/**
* Constructor
Expand All @@ -52,18 +49,28 @@ class Permission implements PermissionInterface
/**
* Get the permission identifier
*
* @return int
* @return int|null
*/
public function getId()
public function getId(): ?int
{
return $this->id;
}

/**
* {@inheritDoc}
* Get the permission name
*
* @return string|null
*/
public function __toString()
public function getName(): ?string
{
return $this->name;
}

/**
*
*/
public function __toString(): string
{
return $this->getName();
}
}
2 changes: 1 addition & 1 deletion data/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
These files are only provided as-in, and are not part of LmcRbac. They provide you some basic Doctrine ORM
These files are only provided as-in, and are not part of LmcRbacMvc. They provide you some basic Doctrine ORM
entities that you can use as a starting point.

## Flat role or hierarchical role?
Expand Down
Loading

0 comments on commit d5580f4

Please sign in to comment.