{"id":17953363,"url":"https://github.com/eloyekunle/permissionsbundle","last_synced_at":"2025-08-03T00:08:11.716Z","repository":{"id":128581933,"uuid":"137677897","full_name":"eloyekunle/PermissionsBundle","owner":"eloyekunle","description":"A Flexible Permission Management module for Symfony","archived":false,"fork":false,"pushed_at":"2019-02-17T16:33:29.000Z","size":129,"stargazers_count":21,"open_issues_count":6,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-19T05:43:21.020Z","etag":null,"topics":["bundle","php","roles-management","symfony","symfony-bundle","user-management"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eloyekunle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"Security/PermissionsVoter.php","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-06-17T18:44:06.000Z","updated_at":"2025-03-18T16:21:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"4f7088db-e6d3-4350-80f3-814753380ff3","html_url":"https://github.com/eloyekunle/PermissionsBundle","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eloyekunle%2FPermissionsBundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eloyekunle%2FPermissionsBundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eloyekunle%2FPermissionsBundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eloyekunle%2FPermissionsBundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eloyekunle","download_url":"https://codeload.github.com/eloyekunle/PermissionsBundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245377920,"owners_count":20605374,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bundle","php","roles-management","symfony","symfony-bundle","user-management"],"created_at":"2024-10-29T10:04:55.393Z","updated_at":"2025-03-25T00:31:48.109Z","avatar_url":"https://github.com/eloyekunle.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"EloyekunlePermissionsBundle\n===========================\n\n[![Build Status](https://travis-ci.org/eloyekunle/PermissionsBundle.svg?branch=master)](https://travis-ci.org/eloyekunle/PermissionsBundle)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/eloyekunle/PermissionsBundle/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/eloyekunle/PermissionsBundle/?branch=master)\n[![Code Coverage](https://scrutinizer-ci.com/g/eloyekunle/PermissionsBundle/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/eloyekunle/PermissionsBundle/?branch=master)\n\nThe EloyekunlePermissionsBundle provides support for a database-backed permissions system in Symfony2.\nIt provides a flexible framework for permissions management that aims to handle common tasks such as flexible\nPermissions Definitions, Roles Creation and Authorization Checking (using Symfony Voters).\n\nFeatures include:\n\n- Roles can be stored via Doctrine ORM.\n- Flexible \u0026 Modular permissions definitions in YAML files. From few permissions to hundreds, this bundle has your back.\n- Symfony Voter for Authorization Checking.\n- Unit tested.\n\nCONTENTS\n--------\n\n* [Installation](#installation)\n* [Usage](#usage)\n* [Contributions](#contributions)\n* [Support](#support)\n* [Credits](#credits)\n\n## INSTALLATION\nInstallation is a quick (I promise!) 5 step process:\n\n1. [Download EloyekunlePermissionsBundle using composer](#step-1-download-the-bundle)\n2. [Enable the Bundle](#step-2-enable-the-bundle)\n3. [Create your Role class](#step-3-create-role-class)\n4. [Configure your User class](#step-4-configure-your-user-class)\n5. [Configure the bundle](#step-5-configure-the-bundle)\n6. [Update your database schema](#step-5-update-your-database-schema)\n\n### Step 1: Download the bundle\n\nOpen a command console, enter your project directory and execute the\nfollowing command to download the latest stable version of this bundle:\n\n```bash\n$ composer require \"eloyekunle/permissions-bundle\"\n```\n\nThis command requires you to have Composer installed globally, as explained\nin the [installation chapter](https://getcomposer.org/doc/00-intro.md) of the Composer documentation.\n\n### Step 2: Enable the bundle\n\nThen, enable the bundle by adding the following line in the ``config/bundles.php``\nfile of your project, e.g. (Symfony \u003e=4):\n\n```php\n    // config/bundles.php\n    return [\n        // ...\n        Eloyekunle\\PermissionsBundle\\EloyekunlePermissionsBundle::class =\u003e ['all' =\u003e true],\n    ];\n```\n\n### Step 3: Create Role class\n\nThe goal of this bundle is to persist some ``Role`` class to a database. \nYour first job, then, is to create the ``Role`` class\nfor your application. This class can look and act however you want: add any\nproperties or methods you find useful. This is *your* ``Role`` class.\n\nThe bundle provides base classes which are already mapped for most fields\nto make it easier to create your entity. Here is how you use it:\n\n1. Extend the base ``Role`` class (from the ``Model`` folder if you are using\n   any of the doctrine variants)\n2. Map the ``id`` field. It must be protected as it is inherited from the parent class.\n3. When you extend from the mapped superclass provided by the bundle, don't \n   redefine the mapping for the other fields as it is provided by the bundle.\n4. If you override the __construct() method in your Role class, be sure \n   to call parent::__construct(), as the base Role class depends on this to initialize some fields.\n\n#### Doctrine ORM Role class\n\nIf you're persisting your roles via the Doctrine ORM, then your ``Role`` class\nshould live in the ``Entity`` namespace of your bundle and look like this to\nstart:\n\n##### PHP\n\n```php\n\u003c?php\n// src/App/Entity/Role.php\n\nnamespace App\\Entity;\n\nuse Eloyekunle\\PermissionsBundle\\Model\\Role as BaseRole;\nuse Doctrine\\ORM\\Mapping as ORM;\n\n/**\n * @ORM\\Entity\n * @ORM\\Table(name=\"role\")\n */\nclass Role extends BaseRole\n{\n    /**\n     * @ORM\\Id\n     * @ORM\\Column(type=\"integer\")\n     * @ORM\\GeneratedValue(strategy=\"AUTO\")\n     */\n    protected $id;\n\n    public function __construct()\n    {\n        parent::__construct();\n        // your own logic\n    }\n}\n```\n\n### Step 4: Configure your User class\n\nThe bundle currently ships with a [`User`](https://github.com/eloyekunle/PermissionsBundle/blob/master/Model/User.php)\nclass which you can extend from your own `User` entity.\n\n##### PHP\n\n```php\n\u003c?php\n// src/App/Entity/User.php\n\nnamespace App\\Entity;\n\nuse Eloyekunle\\PermissionsBundle\\Model\\User as BaseUser;\n\nclass User extends BaseUser\n{\n    \n    public function __construct()\n    {\n        parent::__construct();\n        // your own logic\n    }\n}\n```\n\nIf you already extend another base user class in your `User` entity (e.g. from the excellent [FOSUserBundle](https://github.com/FriendsOfSymfony/FOSUserBundle)),\nyou will need to implement [`Eloyekunle\\PermissionsBundle\\Model\\UserInterface`](https://github.com/eloyekunle/PermissionsBundle/blob/master/Model/UserInterface.php)\nin your entity and implement the methods (especially `UserInterface::hasPermission`). You can view the [`User`](https://github.com/eloyekunle/PermissionsBundle/blob/master/Model/User.php)\nEntity for sample implementation details.\n\n### Step 5: Configure the Bundle\n\nTo configure the bundle, add your custom `Role` class that was created above, and also a path where your permissions\nwill be defined. E.g.\n\n```yaml\n# config/packages/eloyekunle_permissions.yaml\neloyekunle_permissions:\n  role_class: App\\Entity\\Role\n  module:\n    definitions_path: '%kernel.project_dir%/config/modules'\n```\n\n### Step 6: Update your database schema\n\nNow that the bundle is configured, the last thing you need to do is update your\ndatabase schema because you have added a new entity, the ``Role`` class which you\ncreated in Step 3.\n\nRun the following command.\n\n```bash\n$ php bin/console doctrine:schema:update --force\n```\n\n**Or** to create and execute a migration:\n\n```bash\n$ php bin/console doctrine:migrations:diff\n$ php bin/console doctrine:migrations:migrate\n```\n\n## USAGE\n\nTo start using the bundle:\n1. [Set up a few permissions](#2-set-up-a-few-permissions)\n2. [Set up a Role](#1-set-up-a-role)\n3. [Check Permissions in your Controllers](#4-check-permissions-in-your-controllers)\n\n### 1. Set up a few permissions\n\nThis bundle currently supports a modular form of defining permissions, since a lot of projects usually have various\ncomponents e.g. Content Management, User Management, Comments, Files etc. You can easily separate your permissions\ninto various YAML files in your `config/modules` directory (or any directory as long as you specify it in the\nconfig as [described above](#step-5-configure-the-bundle)).\nFor example:\n```yaml\n# config/modules/content.yaml\n# This shows the basic expected structure of the permissions definitions.\n\nname: 'Content'\n\npermissions:\n    # The key is the important stuff here. You can add your own fields too...\n    edit content:\n      # E.g. Add a human-readable name for the permission.\n      title: 'Edit Content'\n      description: 'Grants permission to edit content.'\n      dependencies:\n        - view content\n    view content:\n      title: 'View Content'\n      description: 'Grants permission to view content.'\n```\n\nThe bundle ships with a [`PermissionsHandler`](https://github.com/eloyekunle/PermissionsBundle/blob/master/Util/PermissionsHandlerInterface.php)\nthat is available as a service and can be injected into your Controllers/Services. You can use it to get all available\npermissions.\n\n```php\n\u003c?php\n// src/Controller/PermissionsController.php\nnamespace App\\Controller;\n\nuse Eloyekunle\\PermissionsBundle\\Util\\PermissionsHandler;\n\nclass PermissionsController {\n    public function getPermissions(PermissionsHandler $permissionsHandler)\n    {\n        /*\n         * @var array\n         * \n         * array (\n         *    'edit content' =\u003e \n         *        array (\n         *          'title' =\u003e 'Edit Content',\n         *          'description' =\u003e 'Grants permission to edit content.',\n         *          'dependencies' =\u003e \n         *              array (\n         *                0 =\u003e 'view content',\n         *              ),\n         *          'provider' =\u003e 'content',\n         *        ),\n         *    'view content' =\u003e \n         *        array (\n         *          'title' =\u003e 'View Content',\n         *          'description' =\u003e 'Grants permission to view content.',\n         *          'provider' =\u003e 'content',\n         *        ),\n         *  )\n         */\n        $permissions = $permissionsHandler-\u003egetPermissions();\n        // ........................\n    }\n}\n```\n\n### 2. Set up a Role\n\nThe bundle ships with a [`RoleManager`](https://github.com/eloyekunle/PermissionsBundle/blob/master/Model/RoleManagerInterface.php)\nwhich is available as a service and can be injected into your Controllers/Services. It contains useful utility methods\nto manager roles. You can also `get` it from the container as `eloyekunle_permissions.role_manager`.\n\n```php\n\u003c?php\n// src/App/Controller/RoleController.php\nnamespace App\\Controller;\n\nuse Eloyekunle\\PermissionsBundle\\Doctrine\\RoleManager;\nuse Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller;\n\nclass RoleController extends Controller \n{\n    public function create(RoleManager $roleManager) {\n        $role = $roleManager-\u003ecreateRole();\n        $role-\u003esetRole('Content Admin');\n        \n        $roleManager-\u003eupdateRole($role);\n        // ......\n    }\n}\n```\n\nThis creates and persists a `Role` entity to your database.\n\n### 3. Check Permissions in your Controllers\n\nThe bundle ships with a [voter](https://symfony.com/doc/current/security/voters.html), [`PermissionsVoter`](https://github.com/eloyekunle/PermissionsBundle/blob/master/Security/PermissionsVoter.php).\nYou can check for user permissions by using the `isGranted()` method on Symfony's authorization checker or call \n`denyAccessUnlessGranted()` in a controller.\n\n```php\n\u003c?php\n// src/App/Controller/ContentController.php\nnamespace App\\Controller;\n\nuse Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller;\nuse Symfony\\Component\\Routing\\Annotation\\Route;\n\nclass ContentController extends Controller \n{\n    \n    /**\n     * @Route(\"/content/{id}/edit\", name=\"content_edit\")\n     * \n     * \n     */\n    public function edit($id)\n    {\n        $this-\u003edenyAccessUnlessGranted('edit content');\n        // Get a Content object - e.g. query for it.\n        // $content = ......;\n    }\n    \n    /**\n     * @Route(\"/content/{id}\", name=\"content_show\")\n     */\n    public function show($id)\n    {\n        $this-\u003edenyAccessUnlessGranted('view content');\n        // Get a Content object - e.g. query for it.\n        // $content = ......;\n    }\n}\n```\n\n## CONTRIBUTIONS\n\nContributions of any kind are welcome: code, documentation, ideas etc.\nIssues and feature requests are tracked in the [Github issue tracker](https://github.com/eloyekunle/PermissionsBundle/issues).\n\n## SUPPORT\nIf you need any support related to this bundle, you can contact me on the [Symfony Slack group](http://symfony-devs.slack.com) \n(eloyekunle), or send me an email (eloyekunle@gmail.com).\n\n## CREDITS\n- Bundle inspired by the [Drupal Permissions System](https://api.drupal.org/api/drupal/core!core.api.php/group/user_api/8.5.x)!\n- Implementation inspired by some excellent Symfony bundles, especially [FOSUserBundle](https://github.com/FriendsOfSymfony/FOSUserBundle).\n- [Elijah Oyekunle](https://elijahoyekunle.com) - [LinkedIn](https://www.linkedin.com/in/elijahoyekunle) - [Twitter](https://twitter.com/elijahoyekunle) - [Github](https://github.com/eloyekunle)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feloyekunle%2Fpermissionsbundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feloyekunle%2Fpermissionsbundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feloyekunle%2Fpermissionsbundle/lists"}