{"id":20876068,"url":"https://github.com/php-casbin/hyperf-permission","last_synced_at":"2025-05-12T15:32:03.339Z","repository":{"id":96365670,"uuid":"283381184","full_name":"php-casbin/hyperf-permission","owner":"php-casbin","description":"An authorization library that supports access control models like ACL, RBAC, ABAC in Hyperf.","archived":false,"fork":false,"pushed_at":"2023-08-28T11:01:59.000Z","size":17,"stargazers_count":13,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-01T07:39:04.174Z","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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-07-29T02:47:02.000Z","updated_at":"2025-02-17T15:36:25.000Z","dependencies_parsed_at":"2024-01-26T03:12:09.056Z","dependency_job_id":null,"html_url":"https://github.com/php-casbin/hyperf-permission","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/php-casbin%2Fhyperf-permission","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-casbin%2Fhyperf-permission/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-casbin%2Fhyperf-permission/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-casbin%2Fhyperf-permission/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/php-casbin","download_url":"https://codeload.github.com/php-casbin/hyperf-permission/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253765946,"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.199Z","updated_at":"2025-05-12T15:32:02.608Z","avatar_url":"https://github.com/php-casbin.png","language":"PHP","readme":"\u003ch1 align=\"center\"\u003e hyperf-permission \u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e An authorization library that supports access control models like ACL, RBAC, ABAC in Hyperf..\u003c/p\u003e\n\n\n## Installing\n\nRequire this package in the `composer.json` of your Hyperf project. This will download the package.\n\n```shell\n$ composer require casbin/hyperf-permission -vvv\n```\n\nTo publish the config, run the vendor publish command:\n\n```shell\n$ php bin/hyperf.php vendor:publish casbin/hyperf-permission\n```\n\nThis will create a new model config file named `config/autoload/casbin-rbac-model.conf`,  a new permission config file named `config/autoload/permission.php` and new migrate file named `2020_07_22_213202_create_rules_table.php`.\n\nTo migrate the migrations, run the migrate command:\n\n```shell\n$ php bin/hyperf.php migrate\n```\n\nThis will create a new table named `rules` .\n\n## Usage\n\n### Quick start\n\nOnce installed you can do stuff like this:\n\n```php\nuse Hyperf\\Permission\\Casbin;\n\n$casbin = new Casbin();\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\nEnforcer::getAllRoles(); // ['writer', 'reader']\n```\n\nGets all the authorization rules in the policy.:\n\n```php\nEnforcer::getPolicy();\n```\n\nGets the roles that a user has.\n\n```php\nEnforcer::getRolesForUser('eve'); // ['writer']\n```\n\nGets the users that has a role.\n\n```php\nEnforcer::getUsersForRole('writer'); // ['eve']\n```\n\nDetermines whether a user has a role.\n\n```php\nEnforcer::hasRoleForUser('eve', 'writer'); // true or false\n```\n\nAdds a role for a user.\n\n```php\nEnforcer::addRoleForUser('eve', 'writer');\n```\n\nAdds a permission for a user or role.\n\n```php\n// to user\nEnforcer::addPermissionForUser('eve', 'articles', 'read');\n// to role\nEnforcer::addPermissionForUser('writer', 'articles','edit');\n```\n\nDeletes a role for a user.\n\n```php\nEnforcer::deleteRoleForUser('eve', 'writer');\n```\n\nDeletes all roles for a user.\n\n```php\nEnforcer::deleteRolesForUser('eve');\n```\n\nDeletes a role.\n\n```php\nEnforcer::deleteRole('writer');\n```\n\nDeletes a permission.\n\n```php\nEnforcer::deletePermission('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\nEnforcer::deletePermissionForUser('eve', 'articles', 'read');\n```\n\nDeletes permissions for a user or role.\n\n```php\n// to user\nEnforcer::deletePermissionsForUser('eve');\n// to role\nEnforcer::deletePermissionsForUser('writer');\n```\n\nGets permissions for a user or role.\n\n```php\nEnforcer::getPermissionsForUser('eve'); // return array\n```\n\nDetermines whether a user has a permission.\n\n```php\nEnforcer::hasPermissionForUser('eve', 'articles', 'read');  // true or false\n```\n\nSee [Casbin API](https://casbin.org/docs/en/management-api) for more APIs.\n\n## Contributing\n\nYou can contribute in one of three ways:\n\n1. File bug reports using the [[issue tracker](https://github.com/yi17310320725/hyperf-authz/issues)](https://github.com/php-casbin/hyperf-permission/issues).\n2. Answer questions or fix bugs on the [[issue tracker](https://github.com/yi17310320725/hyperf-authz/issues)](https://github.com/php-casbin/hyperf-permission/issues).\n3. Contribute new features or update the wiki.\n\n_The code contribution process is not very formal. You just need to make sure that you follow the PSR-0, PSR-1, and PSR-2 coding guidelines. Any new code contributions must be accompanied by unit tests where applicable._\n\n## License\n\nApache-2.0\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-casbin%2Fhyperf-permission","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphp-casbin%2Fhyperf-permission","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-casbin%2Fhyperf-permission/lists"}