eziat / permission-bundle
Provides a simple layer to store permissions.
Installs: 4 710
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^7.1.3
- symfony/config: ^3.4|^4.0
- symfony/dependency-injection: ^3.4|^4.0
- symfony/security-bundle: ^3.4|^4.0
Requires (Dev)
- doctrine/doctrine-bundle: ^1.8
- doctrine/orm: ^2.5
- friendsofphp/php-cs-fixer: ^2.8
- phpunit/phpunit: ^6.5
- symfony/cache: ^3.4|^4.0
- symfony/framework-bundle: ^3.4|^4.0
- symfony/phpunit-bridge: ^3.4|^4.0
- symfony/yaml: ^3.4|^4.0
This package is auto-updated.
Last update: 2024-11-09 02:58:48 UTC
README
Eziat Permission bundle
Permission bundle provides a flexible way to control access decisions. Basically it make sense to use it if you need to have something more flexible than roles but less complex than acl definitions.
Installation
Step 1 Download the bundle using composer.
composer require eziat/permission-bundle
Step 2 Enable the bundle
Add the bundle to the config/bundles.php
file.
<?php // config/bundles.php return [ //... new Eziat\PermissionBundle\EziatPermissionBundle(), //... ];
This is done automatically if you use flex.
Step 3 Create your permission class (optional)
- Required if you want to store permissions in the database as an additional table.
<?php // src/Entity/Permission.php namespace App\Entity; use Eziat\PermissionBundle\Entity\Permission as BasePermission; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity * @ORM\Table(name="permission") */ class Permission extends BasePermission { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; public function getId() { return $this->id; } // Your other logic. }
Step 4 Implement UserPermissionInterface
To use the UserManager
your User
class should implement UserPermissionInterface
.
There are two methods to implement:
getId()
getPermissions()
<?php // src/Entity/User.php namespace App\Entity; use Doctrine\ORM\Mapping as ORM; use Eziat\PermissionBundle\Model\UserPermissionInterface; /** * @ORM\Entity */ class User implements UserPermissionInterface { /** * @ORM\ManyToMany(targetEntity="Permission") * @ORM\JoinTable(name="users_permissions", * joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")}, * inverseJoinColumns={@ORM\JoinColumn(name="permission_id", referencedColumnName="id")} * ) */ protected $permissions; public function getId() { return $this->id; } public function getPermissions() : array { return $this->permissions; } // Your other logic. }
Step 5 Configure the bundle
eziat_permission: database: db_driver: orm permission_class: App\Entity\Permission cache: ~