{"id":20876081,"url":"https://github.com/php-casbin/casbin","last_synced_at":"2026-02-03T04:02:47.251Z","repository":{"id":96365613,"uuid":"299067175","full_name":"php-casbin/casbin","owner":"php-casbin","description":"A PHP extension for Casbin, implemented by C++","archived":false,"fork":false,"pushed_at":"2020-10-09T04:46:27.000Z","size":998,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"develop","last_synced_at":"2025-06-20T17:50:05.045Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":null,"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-09-27T16:00:10.000Z","updated_at":"2020-12-20T14:04:46.000Z","dependencies_parsed_at":"2023-03-30T09:04:08.270Z","dependency_job_id":null,"html_url":"https://github.com/php-casbin/casbin","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/php-casbin/casbin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-casbin%2Fcasbin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-casbin%2Fcasbin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-casbin%2Fcasbin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-casbin%2Fcasbin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/php-casbin","download_url":"https://codeload.github.com/php-casbin/casbin/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-casbin%2Fcasbin/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29032006,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-03T02:28:16.591Z","status":"ssl_error","status_checked_at":"2026-02-03T02:27:48.904Z","response_time":96,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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:58.872Z","updated_at":"2026-02-03T04:02:47.236Z","avatar_url":"https://github.com/php-casbin.png","language":null,"readme":"\u003ch1 align=\"center\"\u003e\n    Casbin\n\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003cstrong\u003eCasbin is used to build Casbin-cpp into a PHP dynamic library via PHP-CPP.\u003c/strong\u003e\n\u003c/p\u003e\n\n## Installation\n\nThis application needs to be compiled, and also relies on the PHP-CPP library, so you will need requirements:\n* [PHP-CPP](https://github.com/CopernicaMarketingSoftware/PHP-CPP)\n* PHP \u003e= 7.0\n* GCC\n* make\n\n### Install extension\n\n```shell\n$ git clone https://github.com/php-casbin/casbin.git\n$ cd casbin\n$ make\n$ make library\n$ sudo make install\n```\n\nTo get rid of intermediate files generated during building of library:\n```shell\n$ make clean\n```\n\n## Usage\n\n### Get started\n\nNew a Casbin enforcer with a model file and a policy file:\n\n```php\nuse Casbin\\Enforcer;\n\n$e = new Enforcer(\"path/to/model.conf\", \"path/to/policy.csv\");\n```\n\nAdd an enforcement hook into your code right before the access happens:\n\n```php\n$params = [\n    \"alice\", // the user that wants to access a resource.\n    \"data1\", // the resource that is going to be accessed.\n    \"read\" // the operation that the user performs on the resource.\n]\n\nif ($e-\u003eenforce($params) === true) {\n    // permit alice to read data1\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$e-\u003egetAllRoles();\n```\n\nGets all the authorization rules in the policy.:\n\n```php\n$e-\u003egetPolicy();\n```\n\nGets the roles that a user has.\n\n```php\n$e-\u003egetRolesForUser('eve');\n```\n\nGets the users that has a role.\n\n```php\n$e-\u003egetUsersForRole('writer');\n```\n\nDetermines whether a user has a role.\n\n```php\n$e-\u003ehasRoleForUser('eve', 'writer');\n```\n\nAdds a role for a user.\n\n```php\n$e-\u003eaddRoleForUser('eve', 'writer');\n```\n\nAdds a permission for a user or role.\n\n```php\n// to user\n$e-\u003eaddPermissionForUser('eve', ['articles', 'read']);\n// to role\n$e-\u003eaddPermissionForUser('writer', ['articles','edit']);\n```\n\nDeletes a role for a user.\n\n```php\n$e-\u003edeleteRoleForUser('eve', 'writer');\n```\n\nDeletes all roles for a user.\n\n```php\n$e-\u003edeleteRolesForUser('eve');\n```\n\nDeletes a role.\n\n```php\n$e-\u003edeleteRole('writer');\n```\n\nDeletes a permission.\n\n```php\n$e-\u003edeletePermission(['articles', 'read']);\n```\n\nDeletes a permission for a user or role.\n\n```php\n$e-\u003edeletePermissionForUser('eve', ['articles', 'read']);\n```\n\nDeletes permissions for a user or role.\n\n```php\n// to user\n$e-\u003edeletePermissionsForUser('eve');\n// to role\n$e-\u003edeletePermissionsForUser('writer');\n```\n\nGets permissions for a user or role.\n\n```php\n$e-\u003egetPermissionsForUser('eve');\n```\n\nDetermines whether a user has a permission.\n\n```php\n$e-\u003ehasPermissionForUser('eve', ['articles', 'read']);\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 Laravel. 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).","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-casbin%2Fcasbin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphp-casbin%2Fcasbin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-casbin%2Fcasbin/lists"}