jonston / symfony-permission
Basic permission management bundle for Symfony
Installs: 4
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 0
Type:symfony-bundle
Requires
- php: >=8.1
- doctrine/doctrine-bundle: ^2.5
- doctrine/orm: ^2.10
- symfony/framework-bundle: ^6.0|^7.0
- symfony/security-bundle: ^6.0|^7.0
Requires (Dev)
- doctrine/doctrine-fixtures-bundle: ^3.4
- phpunit/phpunit: ^10.0
- symfony/phpunit-bridge: ^6.0|^7.0
This package is auto-updated.
Last update: 2025-09-09 18:04:23 UTC
README
A basic bundle for managing permissions and roles in Symfony, similar to spatie-permission, but with simplified functionality.
Installation
Via Composer
composer require jonston/symfony-permission
- Add the bundle to
config/bundles.php
:
<?php return [ // ... Jonston\SymfonyPermission\SymfonyPermissionBundle::class => ['all' => true], ];
- Import Doctrine configuration in
config/packages/doctrine.yaml
:
imports: - { resource: '../../vendor/jonston/symfony-permission/src/Resources/config/doctrine.yaml' }
- Create and run migrations:
php bin/console make:migration php bin/console doctrine:migrations:migrate
Usage
Creating permissions
use Jonston\SymfonyPermission\Service\PermissionServiceInterface; class SomeController { public function __construct( private PermissionServiceInterface $permissionService ) {} public function createPermission() { // Create a permission $permission = $this->permissionService->createPermission( 'edit-posts', 'Permission to edit posts' ); // Find a permission $permission = $this->permissionService->findPermissionByName('edit-posts'); // Get all permissions $permissions = $this->permissionService->getAllPermissions(); } }
Managing roles
use Jonston\SymfonyPermission\Service\RoleServiceInterface; class RoleController { public function __construct( private RoleServiceInterface $roleService ) {} public function createRole() { // Create a role $role = $this->roleService->createRole( 'editor', 'Content editor' ); // Assign permissions to the role $this->roleService->assignPermissionsByNamesToRole( $role, ['edit-posts', 'create-posts'] ); // Check permission $hasPermission = $role->hasPermissionByName('edit-posts'); } }
Database structure
The bundle will create the following tables:
permissions
- permissions tableroles
- roles tablerole_permissions
- many-to-many pivot table
Features
- ✅ Create, update, delete permissions
- ✅ Create, update, delete roles
- ✅ Assign permissions to roles
- ✅ Revoke permissions from roles
- ✅ Check if a role has a permission
- ✅ Follows SOLID principles
- ✅ Uses repositories for data access