ggbb / symfony-user-permission
The permissions system for users in symfony
v0.1.3
2023-10-17 21:44 UTC
Requires
- php: >=8.1
- doctrine/doctrine-bundle: ^2.10
- doctrine/doctrine-migrations-bundle: ^3.2
- doctrine/orm: ^2.15
- symfony/framework-bundle: 6.3.*
- symfony/security-bundle: 6.3.*
- symfony/yaml: 6.3.*
README
composer require ggbb/symfony-user-permission
php bin/console role:create-default-user-role
// ggbb_user_permission.yaml
ggbb_user_permission:
entity:
user: App\Entity\User
user_role: App\Entity\UserRole
mapping:
permissions_dir: '%kernel.project_dir%/src/Permission'
namespace: App\Permission
// security.yaml
security:
providers:
users:
id: ggbb.user_permission.user_provider
access_decision_manager:
strategy: unanimous
...
// UserRepository.php
class UserRepository extends ServiceEntityRepository implements PasswordUpgraderInterface, UserLoaderInterface
{
use UserRoleUserLoaderTrait;
...
}
// User.php
class User implements UserInterface, UserRoleFieldInterface
{
use GetRolesMethodTrait;
...
}
// UserRole.php
namespace App\Entity;
#[ORM\Entity(repositoryClass: UserRoleRepository::class)]
class UserRole implements UserRoleInterface
{
use RoleFieldTrait;
use RolePermissionFieldTrait;
...
}
// src/Permission/MyPermission.php