{"id":20876075,"url":"https://github.com/php-casbin/symfony-permission","last_synced_at":"2026-02-04T05:03:46.082Z","repository":{"id":96365843,"uuid":"157995614","full_name":"php-casbin/symfony-permission","owner":"php-casbin","description":"Use Casbin in Symfony Framework, Casbin is a powerful and efficient open-source access control library.","archived":false,"fork":false,"pushed_at":"2020-09-27T16:13:27.000Z","size":10,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"develop","last_synced_at":"2025-07-03T02:03:37.292Z","etag":null,"topics":["abac","access-control","acl","auth","authz","casbin","permission","rbac","symfony-casbin"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/php-casbin.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":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-11-17T15:06:19.000Z","updated_at":"2024-12-09T16:23:28.000Z","dependencies_parsed_at":"2023-03-30T09:06:13.249Z","dependency_job_id":null,"html_url":"https://github.com/php-casbin/symfony-permission","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/php-casbin/symfony-permission","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-casbin%2Fsymfony-permission","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-casbin%2Fsymfony-permission/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-casbin%2Fsymfony-permission/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-casbin%2Fsymfony-permission/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/php-casbin","download_url":"https://codeload.github.com/php-casbin/symfony-permission/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-casbin%2Fsymfony-permission/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263245294,"owners_count":23436511,"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":["abac","access-control","acl","auth","authz","casbin","permission","rbac","symfony-casbin"],"created_at":"2024-11-18T06:49:58.042Z","updated_at":"2026-02-04T05:03:46.003Z","avatar_url":"https://github.com/php-casbin.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003esymfony-permission\u003c/h1\u003e\n\u003cp align=\"center\"\u003eAn authorization library that supports access control models like ACL, RBAC, ABAC in Symfony.\u003c/p\u003e\n\n## Installing\n\nRequire this package in the `composer.json` of your easyswoole project. This will download the package.\n\n```shell\n$ composer require\n```\n\n## Usage\n\nFirst, you can install Doctrine.\n\n```bash\n$ composer require symfony/orm-pack\n```\n\nConfiguring the Database, you can find and customize this inside `.env`:\n```env\n# customize this line!\nDATABASE_URL=\"mysql://db_user:db_password@127.0.0.1:3306/db_name?serverVersion=5.7\"\n\n# to use sqlite:\n# DATABASE_URL=\"sqlite:///%kernel.project_dir%/var/app.db\"\n\n# to use postgresql:\n# DATABASE_URL=\"postgresql://db_user:db_password@127.0.0.1:5432/db_name?serverVersion=11\u0026charset=utf8\"\n```\n\nAnd you can create migration file to generate database table, :\n\n*migrations/Version20200823135629.php*\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nnamespace DoctrineMigrations;\n\nuse Doctrine\\DBAL\\Schema\\Schema;\nuse Doctrine\\Migrations\\AbstractMigration;\n\n/**\n * Auto-generated Migration: Please modify to your needs!\n */\nfinal class Version20200823135629 extends AbstractMigration\n{\n    public function getDescription() : string\n    {\n        return '';\n    }\n\n    public function up(Schema $schema) : void\n    {\n        // this up() migration is auto-generated, please modify it to your needs\n        $this-\u003eaddSql('CREATE TABLE casbin_rules (id INT AUTO_INCREMENT NOT NULL, ptype VARCHAR(255) DEFAULT NULL, v0 VARCHAR(255) DEFAULT NULL, v1 VARCHAR(255) DEFAULT NULL, v2 VARCHAR(255) DEFAULT NULL, v3 VARCHAR(255) DEFAULT NULL, v4 VARCHAR(255) DEFAULT NULL, v5 VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');\n    }\n\n    public function down(Schema $schema) : void\n    {\n        // this down() migration is auto-generated, please modify it to your needs\n        $this-\u003eaddSql('DROP TABLE casbin_rules');\n    }\n}\n```\n\nexecute your migrations:\n```shell\n$ php bin/console doctrine:migrations:migrate\n```\n\nThen you can start like this:\n\n```php\nuse Easyswolle\\Permission\\Casbin;\nuse Easyswolle\\Permission\\Config;\n\n$config = new Config();\n$config-\u003esetUrl($_ENV['DATABASE_URL']);\n$casbin = new Casbin($config);\n\n// adds permissions to a user\n$casbin-\u003eaddPermissionForUser('eve', 'articles', 'read');\n// adds a role for a user.\n$casbin-\u003eaddRoleForUser('eve', 'writer');\n// adds permissions to a rule\n$casbin-\u003eaddPolicy('writer', 'articles', 'edit');\n```\n\nYou can check if a user has a permission like this:\n\n```php\n// to check if a user has permission\nif ($casbin-\u003eenforce('eve', 'articles', 'edit')) {\n  // permit eve to edit articles\n} else {\n  // deny the request, show an error\n}\n```\n\n### Using Enforcer Api\n\nIt provides a very rich api to facilitate various operations on the Policy:\n\nGets all roles:\n\n```php\n$casbin-\u003egetAllRoles(); // ['writer', 'reader']\n```\n\nGets all the authorization rules in the policy.:\n\n```php\n$casbin-\u003egetPolicy();\n```\n\nGets the roles that a user has.\n\n```php\n$casbin-\u003egetRolesForUser('eve'); // ['writer']\n```\n\nGets the users that has a role.\n\n```php\n$casbin-\u003egetUsersForRole('writer'); // ['eve']\n```\n\nDetermines whether a user has a role.\n\n```php\n$casbin-\u003ehasRoleForUser('eve', 'writer'); // true or false\n```\n\nAdds a role for a user.\n\n```php\n$casbin-\u003eaddRoleForUser('eve', 'writer');\n```\n\nAdds a permission for a user or role.\n\n```php\n// to user\n$casbin-\u003eaddPermissionForUser('eve', 'articles', 'read');\n// to role\n$casbin-\u003eaddPermissionForUser('writer', 'articles','edit');\n```\n\nDeletes a role for a user.\n\n```php\n$casbin-\u003edeleteRoleForUser('eve', 'writer');\n```\n\nDeletes all roles for a user.\n\n```php\n$casbin-\u003edeleteRolesForUser('eve');\n```\n\nDeletes a role.\n\n```php\n$casbin-\u003edeleteRole('writer');\n```\n\nDeletes a permission.\n\n```php\n$casbin-\u003edeletePermission('articles', 'read'); // returns false if the permission does not exist (aka not affected).\n```\n\nDeletes a permission for a user or role.\n\n```php\n$casbin-\u003edeletePermissionForUser('eve', 'articles', 'read');\n```\n\nDeletes permissions for a user or role.\n\n```php\n// to user\n$casbin-\u003edeletePermissionsForUser('eve');\n// to role\n$casbin-\u003edeletePermissionsForUser('writer');\n```\n\nGets permissions for a user or role.\n\n```php\n$casbin-\u003egetPermissionsForUser('eve'); // return array\n```\n\nDetermines whether a user has a permission.\n\n```php\n$casbin-\u003ehasPermissionForUser('eve', 'articles', 'read');  // true or false\n```\n\nSee [Casbin API](https://casbin.org/docs/en/management-api) for more APIs.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-casbin%2Fsymfony-permission","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphp-casbin%2Fsymfony-permission","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-casbin%2Fsymfony-permission/lists"}