{"id":20876071,"url":"https://github.com/php-casbin/easyswoole-permission","last_synced_at":"2025-05-12T15:32:04.854Z","repository":{"id":45990398,"uuid":"283381591","full_name":"php-casbin/easyswoole-permission","owner":"php-casbin","description":"An authorization library that supports access control models like ACL, RBAC, ABAC in EasySwoole.","archived":false,"fork":false,"pushed_at":"2021-11-22T14:23:10.000Z","size":57,"stargazers_count":9,"open_issues_count":0,"forks_count":6,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-24T22:58:44.550Z","etag":null,"topics":[],"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}},"created_at":"2020-07-29T02:49:35.000Z","updated_at":"2023-10-07T14:12:38.000Z","dependencies_parsed_at":"2022-07-20T05:00:21.944Z","dependency_job_id":null,"html_url":"https://github.com/php-casbin/easyswoole-permission","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-casbin%2Feasyswoole-permission","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-casbin%2Feasyswoole-permission/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-casbin%2Feasyswoole-permission/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-casbin%2Feasyswoole-permission/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/php-casbin","download_url":"https://codeload.github.com/php-casbin/easyswoole-permission/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253765954,"owners_count":21960821,"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":[],"created_at":"2024-11-18T06:49:56.911Z","updated_at":"2025-05-12T15:32:04.585Z","avatar_url":"https://github.com/php-casbin.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003eeasyswoole-permission\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003cstrong\u003eeasyswoole-permission is an authorization library for the easyswoole framework.\u003c/strong\u003e    \n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/php-casbin/easyswoole-permission/actions\"\u003e\n        \u003cimg src=\"https://github.com/php-casbin/easyswoole-permission/workflows/build/badge.svg?branch=master\" alt=\"Build Status\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://coveralls.io/github/php-casbin/easyswoole-permission\"\u003e\n        \u003cimg src=\"https://coveralls.io/repos/github/php-casbin/easyswoole-permission/badge.svg\" alt=\"Coverage Status\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://packagist.org/packages/casbin/easyswoole-permission\"\u003e\n        \u003cimg src=\"https://poser.pugx.org/casbin/easyswoole-permission/v/stable\" alt=\"Latest Stable Version\"\u003e\n    \u003c/a\u003e\n     \u003ca href=\"https://packagist.org/packages/casbin/easyswoole-permission\"\u003e\n        \u003cimg src=\"https://poser.pugx.org/casbin/easyswoole-permission/downloads\" alt=\"Total Downloads\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://packagist.org/packages/casbin/easyswoole-permissionz\"\u003e\n        \u003cimg src=\"https://poser.pugx.org/casbin/easyswoole-permission/license\" alt=\"License\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n[Chinese Version](https://github.com/php-casbin/easyswoole-permission/blob/master/README_CN.md)\n\nIt's based on [Casbin](https://github.com/php-casbin/php-casbin), an authorization library that supports access control models like `ACL`, `RBAC`, `ABAC`.\n\nAll you need to learn to use `Casbin` first.\n\n* [Installation](#installation)\n\n* [Usage](#usage)\n\n  - [Database settings](#database-settings)\n  - [Create corresponding data table](#create-corresponding-data-table)\n\n  * [Quick start](#quick-start)\n  * [Using Enforcer Api](#using-enforcer-api)\n\n* [Thinks](#thinks)\n\n* [License](#license)\n\n## Installation\n\nRequire this package in the `composer.json` of your easyswoole project. This will download the package.\n\n```shell\n$ composer install\n```\n\nOr in the root directory of your easyswoole application, you can use the following composer command to install this package directly .\n\n```shell\n$ composer require casbin/easyswoole-permission\n```\n\n## Usage\n\n### Database settings\n\nadd mysql configuration to `dev.php`:\n```php\n/*################ MYSQL CONFIG ##################*/\n\n'MYSQL'  =\u003e [\n    'host'          =\u003e '127.0.0.1',\n    'port'          =\u003e 3306,\n    'user'          =\u003e 'root',\n    'password'      =\u003e 'root',\n    'database'      =\u003e 'easyswoole',\n    'timeout'       =\u003e 5,\n    'charset'       =\u003e 'utf8mb4',\n]\n```\n\nadd mysql configuration to `EasySwooleEvent.php`:\n\n```php\nuse EasySwoole\\ORM\\Db\\Connection;\nuse EasySwoole\\ORM\\DbManager;\n\npublic static function initialize()\n{\n  ...\n  $config = new \\EasySwoole\\ORM\\Db\\Config(Config::getInstance()-\u003egetConf('MYSQL'));\n  DbManager::getInstance()-\u003eaddConnection(new Connection($config));\n}\n```\n\n### Create corresponding data table\n\nBefore using it, you need to create a table named `casbin_rules` for Casbin to store the policy.\n\nTake mysql as an example:\n\n```sql\nCREATE TABLE  if not exists  `casbin_rules` (\n  `id` BigInt(20) unsigned NOT NULL AUTO_INCREMENT,\n  `ptype` varchar(255) DEFAULT NULL,\n  `v0` varchar(255) DEFAULT NULL,\n  `v1` varchar(255) DEFAULT NULL,\n  `v2` varchar(255) DEFAULT NULL,\n  `v3` varchar(255) DEFAULT NULL,\n  `v4` varchar(255) DEFAULT NULL,\n  `v5` varchar(255) DEFAULT NULL,\n  `create_time` timestamp NULL DEFAULT NULL,\n  `update_time` timestamp NULL DEFAULT NULL,\n  PRIMARY KEY (`id`)\n) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4;\n```\n\n### Quick start\n\nThen you can start like this:\n\n```php\nuse EasySwoole\\Permission\\Casbin;\nuse EasySwoole\\Permission\\Config;\n\n$config = new Config();\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\nFirst create an instance of the enforcer class, and the following operations are based on this instance:\n\n```php\n$config = new Config();\n$casbin = new Casbin($config);\n$enforcer = $casbin-\u003eenforcer();\n```\n\nGets all roles:\n\n```php\n$enforcer-\u003egetAllRoles(); // ['writer', 'reader']\n```\n\nGets all the authorization rules in the policy.:\n\n```php\n$enforcer-\u003egetPolicy();\n```\n\nGets the roles that a user has.\n\n```php\n$enforcer-\u003egetRolesForUser('eve'); // ['writer']\n```\n\nGets the users that has a role.\n\n```php\n$enforcer-\u003egetUsersForRole('writer'); // ['eve']\n```\n\nDetermines whether a user has a role.\n\n```php\n$enforcer-\u003ehasRoleForUser('eve', 'writer'); // true or false\n```\n\nAdds a role for a user.\n\n```php\n$enforcer-\u003eaddRoleForUser('eve', 'writer');\n```\n\nAdds a permission for a user or role.\n\n```php\n// to user\n$enforcer-\u003eaddPermissionForUser('eve', 'articles', 'read');\n// to role\n$enforcer-\u003eaddPermissionForUser('writer', 'articles','edit');\n```\n\nDeletes a role for a user.\n\n```php\n$enforcer-\u003edeleteRoleForUser('eve', 'writer');\n```\n\nDeletes all roles for a user.\n\n```php\n$enforcer-\u003edeleteRolesForUser('eve');\n```\n\nDeletes a role.\n\n```php\n$enforcer-\u003edeleteRole('writer');\n```\n\nDeletes a permission.\n\n```php\n$enforcer-\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$enforcer-\u003edeletePermissionForUser('eve', 'articles', 'read');\n```\n\nDeletes permissions for a user or role.\n\n```php\n// to user\n$enforcer-\u003edeletePermissionsForUser('eve');\n// to role\n$enforcer-\u003edeletePermissionsForUser('writer');\n```\n\nGets permissions for a user or role.\n\n```php\n$enforcer-\u003egetPermissionsForUser('eve'); // return array\n```\n\nDetermines whether a user has a permission.\n\n```php\n$enforcer-\u003ehasPermissionForUser('eve', 'articles', 'read');  // true or false\n```\n\nSee [Casbin API](https://casbin.org/docs/en/management-api) for more APIs.\n\n## Thinks\n\n[Casbin](https://github.com/php-casbin/php-casbin) in Easyswoole. You can find the full documentation of Casbin [on the website](https://casbin.org/).\n\n## License\n\nThis project is licensed under the [Apache 2.0 license](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-casbin%2Feasyswoole-permission","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphp-casbin%2Feasyswoole-permission","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-casbin%2Feasyswoole-permission/lists"}