Skip to content
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
23 changes: 3 additions & 20 deletions data/FlatRole.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -23,38 +23,21 @@ use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Laminas\Permissions\Rbac\RoleInterface;

/**
* @ORM\Entity
* @ORM\Table(name="roles")
*/
#[ORM\Entity]
#[ORM\Table(name: 'roles')]
/**
* @deprecated
*/
class FlatRole implements RoleInterface
{
/**
* @var int|null
*
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
#[ORM\Id]
#[ORM\Column(name: 'id', type: 'integer')]
#[ORM\GeneratedValue(strategy: 'AUTO')]
protected ?int $id;

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

/**
* @var Permission[]|Collection
* @ORM\ManyToMany(targetEntity="Permission", indexBy="name", fetch="EAGER", cascade={"persist"})
*/
#[ORM\ManyToMany(targetEntity: "Persmission", cascade: ["persist"], fetch: "EAGER", indexBy: "name")]
protected array|Collection|ArrayCollection $permissions;

Expand Down
23 changes: 3 additions & 20 deletions data/HierarchicalRole.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -23,46 +23,29 @@ use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Laminas\Permissions\Rbac\RoleInterface;

/**
* @ORM\Entity
* @ORM\Table(name="roles")
*/
#[ORM\Entity]
#[ORM\Table(name: 'roles')]
/**
* @deprecated
*/
class HierarchicalRole implements RoleInterface
{
/**
* @var int|null
*
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
#[ORM\Id]
#[ORM\Column(name: 'id', type: 'integer')]
#[ORM\GeneratedValue(strategy: 'AUTO')]
protected ?int $id = null;

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

/**
* @var RoleInterface[]|Collection
*
* @ORM\ManyToMany(targetEntity="HierarchicalRole")
*/
#[ORM\ManyToMany(targetEntity: RoleInterface::class)]
protected array|Collection|ArrayCollection $children = [];

/**
* @var Permission[]|Collection
*
* @ORM\ManyToMany(targetEntity="Permission", indexBy="name", fetch="EAGER")
*/
#[ORM\ManyToMany(targetEntity: Permission::class, fetch: 'EAGER', indexBy: 'name')]
protected array|Collection|ArrayCollection $permissions;
Expand Down
19 changes: 3 additions & 16 deletions data/Permission.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,18 @@ declare(strict_types=1);

use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
* @ORM\Table(name="permissions")
*/
#[ORM\Entity]
#[ORM\Table(name: 'permissions')]
/**
* @deprecated
*/
class Permission
{
/**
* @var int|null
*
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
#[ORM\Id]
#[ORM\Column(type: 'integer')]
#[ORM\GeneratedValue(strategy: 'AUTO')]
protected ?int $id;

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

Expand Down
28 changes: 1 addition & 27 deletions data/Role.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -24,52 +24,26 @@ use Doctrine\ORM\Mapping as ORM;
use Laminas\Permissions\Rbac\RoleInterface;

/**
* @ORM\Entity
* @ORM\Table(name="roles")
* @deprecated
*/
#[ORM\Entity]
#[ORM\Table(name: 'roles')]
class Role implements RoleInterface
{
/**
* @var int|null
*
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
#[ORM\Id]
#[ORM\Column(type: 'integer')]
#[ORM\GeneratedValue]
private ?int $id;

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

/**
* @var Collection
*
* @ORM\JoinTable(name="role_children")
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
* @ORM\InverseJoinColumn(name="child_id", referencedColumnName="id")
* @ORM\ManyToMany(targetEntity="role", cascade={"persist"})
*/
#[ORM\JoinTable(name: 'role_children')]
#[ORM\JoinColumn(name: 'parent_id', referencedColumnName: 'id')]
#[ORM\InverseJoinColumn(name: 'child_id', referencedColumnName: 'id')]
#[ORM\ManyToMany(targetEntity: 'Role', cascade: ['persist'])]
private Collection $children;

/**
* @var Collection
*
* @ORM\ManyToMany(targetEntity="Permission", indexBy="name", fetch="EAGER", cascade={"persist"})
*/
#[ORM\ManyToMany(targetEntity: 'Permission', cascade: ['persist'], fetch: 'EAGER', indexBy: 'name')]
private Collection $permissions;

Expand Down
64 changes: 51 additions & 13 deletions psalm.baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
<code><![CDATA[AssertionPluginManager]]></code>
</MissingTemplateParam>
</file>
<file src="src/ConfigProvider.php">
<DeprecatedClass>
<code><![CDATA[ObjectRepositoryRoleProvider::class]]></code>
<code><![CDATA[ObjectRepositoryRoleProviderFactory::class]]></code>
</DeprecatedClass>
</file>
<file src="src/Exception/UnauthorizedException.php">
<UnusedClass>
<code><![CDATA[UnauthorizedException]]></code>
Expand Down Expand Up @@ -64,27 +70,20 @@
</MixedMethodCall>
</file>
<file src="src/Role/ObjectRepositoryRoleProvider.php">
<InvalidReturnStatement>
<code><![CDATA[$roles]]></code>
</InvalidReturnStatement>
<MissingOverrideAttribute>
<code><![CDATA[public function getRoles(iterable $roleNames): iterable]]></code>
</MissingOverrideAttribute>
<MixedAssignment>
<code><![CDATA[$role]]></code>
</MixedAssignment>
<MixedReturnStatement>
<code><![CDATA[$this->roleCache[$key]]]></code>
</MixedReturnStatement>
<UndefinedDocblockClass>
<code><![CDATA[$role]]></code>
<code><![CDATA[$roles]]></code>
</UndefinedDocblockClass>
</file>
<file src="src/Role/ObjectRepositoryRoleProviderFactory.php">
<ClassMustBeFinal>
<code><![CDATA[ObjectRepositoryRoleProviderFactory]]></code>
</ClassMustBeFinal>
<DeprecatedClass>
<code><![CDATA[ObjectRepositoryRoleProvider]]></code>
<code><![CDATA[ObjectRepositoryRoleProvider::class]]></code>
<code><![CDATA[new ObjectRepositoryRoleProvider($objectRepository, $options['role_name_property'])]]></code>
<code><![CDATA[new ObjectRepositoryRoleProvider($objectRepository, $options['role_name_property'])]]></code>
</DeprecatedClass>
<MixedArgument>
<code><![CDATA[$objectRepository]]></code>
<code><![CDATA[$objectRepository]]></code>
Expand Down Expand Up @@ -219,6 +218,10 @@
<ClassMustBeFinal>
<code><![CDATA[ConfigProviderTest]]></code>
</ClassMustBeFinal>
<DeprecatedClass>
<code><![CDATA[ObjectRepositoryRoleProvider::class]]></code>
<code><![CDATA[ObjectRepositoryRoleProviderFactory::class]]></code>
</DeprecatedClass>
<MissingReturnType>
<code><![CDATA[testInvocationProvidesDependencyConfiguration]]></code>
<code><![CDATA[testProvidesExpectedConfiguration]]></code>
Expand Down Expand Up @@ -257,11 +260,46 @@
<ClassMustBeFinal>
<code><![CDATA[ObjectRepositoryRoleProviderFactoryTest]]></code>
</ClassMustBeFinal>
<DeprecatedClass>
<code><![CDATA[ObjectRepositoryRoleProvider::class]]></code>
<code><![CDATA[ObjectRepositoryRoleProvider::class]]></code>
<code><![CDATA[ObjectRepositoryRoleProvider::class]]></code>
<code><![CDATA[ObjectRepositoryRoleProvider::class]]></code>
<code><![CDATA[ObjectRepositoryRoleProvider::class]]></code>
<code><![CDATA[ObjectRepositoryRoleProvider::class]]></code>
<code><![CDATA[ObjectRepositoryRoleProviderFactory::class]]></code>
<code><![CDATA[new ObjectRepositoryRoleProviderFactory()]]></code>
<code><![CDATA[new ObjectRepositoryRoleProviderFactory()]]></code>
<code><![CDATA[new ObjectRepositoryRoleProviderFactory()]]></code>
<code><![CDATA[new ObjectRepositoryRoleProviderFactory()]]></code>
</DeprecatedClass>
</file>
<file src="test/Role/ObjectRepositoryRoleProviderTest.php">
<ClassMustBeFinal>
<code><![CDATA[ObjectRepositoryRoleProviderTest]]></code>
</ClassMustBeFinal>
<DeprecatedClass>
<code><![CDATA[$objectManager->getRepository(\LmcTest\Rbac\Asset\Role::class)]]></code>
<code><![CDATA[$objectManager->getRepository(\LmcTest\Rbac\Asset\Role::class)]]></code>
<code><![CDATA[$objectManager->getRepository(\LmcTest\Rbac\Asset\Role::class)]]></code>
<code><![CDATA[ObjectRepositoryRoleProvider::class]]></code>
<code><![CDATA[\LmcTest\Rbac\Asset\Role::class]]></code>
<code><![CDATA[\LmcTest\Rbac\Asset\Role::class]]></code>
<code><![CDATA[\LmcTest\Rbac\Asset\Role::class]]></code>
<code><![CDATA[new ObjectRepositoryRoleProvider($objectRepository, 'name')]]></code>
<code><![CDATA[new ObjectRepositoryRoleProvider($objectRepository, 'name')]]></code>
<code><![CDATA[new ObjectRepositoryRoleProvider($objectRepository, 'name')]]></code>
<code><![CDATA[new ObjectRepositoryRoleProvider($objectRepository, 'name')]]></code>
<code><![CDATA[new ObjectRepositoryRoleProvider($objectRepository, 'name')]]></code>
<code><![CDATA[new ObjectRepositoryRoleProvider($objectRepository, 'name')]]></code>
<code><![CDATA[new ObjectRepositoryRoleProvider($objectRepository, 'name')]]></code>
<code><![CDATA[new \LmcTest\Rbac\Asset\Role($name)]]></code>
<code><![CDATA[new \LmcTest\Rbac\Asset\Role($roleConfig)]]></code>
<code><![CDATA[new \LmcTest\Rbac\Asset\Role('admin')]]></code>
<code><![CDATA[new \LmcTest\Rbac\Asset\Role('admin')]]></code>
<code><![CDATA[new \LmcTest\Rbac\Asset\Role('guest')]]></code>
<code><![CDATA[new \LmcTest\Rbac\Asset\Role('member')]]></code>
</DeprecatedClass>
<InvalidArgument>
<code><![CDATA[[
'driverClass' => Driver::class,
Expand Down
13 changes: 7 additions & 6 deletions src/Role/ObjectRepositoryRoleProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
namespace Lmc\Rbac\Role;

use Doctrine\Persistence\ObjectRepository;
use Laminas\Permissions\Rbac\RoleInterface;
use Lmc\Rbac\Exception\RoleNotFoundException;

use function array_diff;
Expand All @@ -31,17 +32,17 @@

/**
* Role provider that uses Doctrine object repository to fetch roles
*
* @deprecated Use Lmc\Rbac\Role\Doctrine\ObjectRepositoryRoleProvider instead
*/
final class ObjectRepositoryRoleProvider implements RoleProviderInterface
{
/** @var ObjectRepository */
private $objectRepository;
private ObjectRepository $objectRepository;

/** @var string */
private $roleNameProperty;
private string $roleNameProperty;

/** @var array */
private $roleCache = [];
/** @var array<array-key, RoleInterface[]> */
private array $roleCache = [];

public function __construct(ObjectRepository $objectRepository, string $roleNameProperty)
{
Expand Down
2 changes: 2 additions & 0 deletions src/Role/ObjectRepositoryRoleProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

/**
* Factory used to create an object repository role provider
*
* @deprecated
*/
class ObjectRepositoryRoleProviderFactory
{
Expand Down
9 changes: 1 addition & 8 deletions test/Asset/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,17 @@
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
* @ORM\Table(name="permissions")
* @deprecated
*/
#[ORM\Entity]
#[ORM\Table(name: 'permissions')]
class Permission
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
#[ORM\Id]
#[ORM\Column(type: 'integer')]
#[ORM\GeneratedValue(strategy: 'AUTO')]
protected ?int $id;

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

Expand Down
16 changes: 1 addition & 15 deletions test/Asset/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,40 +27,26 @@
use Laminas\Permissions\Rbac\RoleInterface;

/**
* @ORM\Entity
* @ORM\Table(name="roles")
* @deprecated
*/
#[ORM\Entity]
#[ORM\Table(name: 'roles')]
class Role implements RoleInterface
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
#[ORM\Id]
#[ORM\Column(type: 'integer')]
#[ORM\GeneratedValue]
private ?int $id;

/** @ORM\Column(type="string", length=32, unique=true) */
#[ORM\Column(type: 'string', length: 32, unique: true)]
private ?string $name;

/**
* @ORM\JoinTable(name="role_children")
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
* @ORM\InverseJoinColumn(name="child_id", referencedColumnName="id")
* @ORM\ManyToMany(targetEntity="role", cascade={"persist"})
*/
#[ORM\JoinTable(name: 'role_children')]
#[ORM\JoinColumn(name: 'parent_id', referencedColumnName: 'id')]
#[ORM\InverseJoinColumn(name: 'child_id', referencedColumnName: 'id')]
#[ORM\ManyToMany(targetEntity: self::class, cascade: ['persist'])]
private Collection $children;

/** @ORM\ManyToMany(targetEntity="Permission", indexBy="name", fetch="EAGER", cascade={"persist"}) */
#[ORM\ManyToMany(targetEntity: 'Permission', cascade: ['persist'], fetch: 'EAGER', indexBy: 'name')]
private Collection $permissions;

Expand Down
Loading