{"id":20876087,"url":"https://github.com/php-casbin/casbin-client","last_synced_at":"2025-05-12T15:32:13.856Z","repository":{"id":62499940,"uuid":"157482843","full_name":"php-casbin/casbin-client","owner":"php-casbin","description":"PHP's client for Casbin-Server. Casbin-Server is the Access Control as a Service (ACaaS) solution based on Casbin.","archived":false,"fork":false,"pushed_at":"2024-05-18T12:10:04.000Z","size":21078,"stargazers_count":6,"open_issues_count":0,"forks_count":2,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-07T15:52:13.159Z","etag":null,"topics":["access-control","acl","authorization","client","rbac","server"],"latest_commit_sha":null,"homepage":"","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":"2018-11-14T03:08:45.000Z","updated_at":"2024-05-18T12:10:09.000Z","dependencies_parsed_at":"2022-11-02T10:00:54.951Z","dependency_job_id":null,"html_url":"https://github.com/php-casbin/casbin-client","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%2Fcasbin-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-casbin%2Fcasbin-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-casbin%2Fcasbin-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-casbin%2Fcasbin-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/php-casbin","download_url":"https://codeload.github.com/php-casbin/casbin-client/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225141154,"owners_count":17427235,"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":["access-control","acl","authorization","client","rbac","server"],"created_at":"2024-11-18T06:49:59.733Z","updated_at":"2024-11-18T06:50:00.379Z","avatar_url":"https://github.com/php-casbin.png","language":"PHP","readme":"PHP client for Casbin Server\n====\n\n[![Latest Stable Version](https://poser.pugx.org/casbin/casbin-client/v/stable)](https://packagist.org/packages/casbin/casbin-client)\n[![Total Downloads](https://poser.pugx.org/casbin/casbin-client/downloads)](https://packagist.org/packages/casbin/casbin-client)\n[![License](https://poser.pugx.org/casbin/casbin-client/license)](https://packagist.org/packages/casbin/casbin-client)\n[![Discord](https://img.shields.io/discord/1022748306096537660?logo=discord\u0026label=discord\u0026color=5865F2)](https://discord.gg/S5UjpzGZjN)\n\n``Casbin-client`` is PHP's client for [Casbin-Server](https://github.com/casbin/casbin-server). ``Casbin-Server`` is the ``Access Control as a Service (ACaaS)`` solution based on [Casbin](https://github.com/casbin/casbin).\n\n## Prerequisites\n\n* `php` 5.5 or above, 7.0 or above\n* `gRPC` PHP extension\n\nThis guide gets you started with gRPC in PHP with a simple working example：[gRPC in PHP](https://grpc.io/docs/quickstart/php.html).\n\n## Installation\n\n```\ncomposer require casbin/casbin-client\n```\n\n## Examples\n\n### Client\n\n```php\nrequire_once './vendor/autoload.php';\n\nuse Proto\\CasbinClient;\nuse Proto\\NewEnforcerRequest;\nuse Proto\\NewAdapterRequest;\nuse Proto\\EnforceRequest;\n\n$client = new CasbinClient('localhost:50051', [\n    'credentials' =\u003e Grpc\\ChannelCredentials::createInsecure(),\n]);\n```\n\n### AdapterRequest\n\n```php\n$newAdapterRequest = new NewAdapterRequest();\n$newAdapterRequest-\u003esetDriverName('file');\n$newAdapterRequest-\u003esetConnectString('path/to/rbac_policy.csv');\n\nlist($newAdapterReply, $status) = $client-\u003eNewAdapter($newAdapterRequest)-\u003ewait();\n\nif (0 !== $status-\u003ecode) {\n    throw new \\Exception($status-\u003edetails, $status-\u003ecode);\n}\n\t\n$adapterHandle = $newAdapterReply-\u003egetHandler();\n```\n\n### EnforcerRequest\n\n```php\n$newEnforcerRequest = new NewEnforcerRequest();\n$newEnforcerRequest-\u003esetModelText(\u003c\u003c\u003cEOT\n[request_definition]\nr = sub, obj, act\n\n[policy_definition]\np = sub, obj, act\n\n[role_definition]\ng = _, _\n\n[policy_effect]\ne = some(where (p.eft == allow))\n\n[matchers]\nm = g(r.sub, p.sub) \u0026\u0026 r.obj == p.obj \u0026\u0026 r.act == p.act\nEOT\n        );\n$newEnforcerRequest-\u003esetAdapterHandle($adapterHandle);\n\nlist($newEnforcerReply, $status) = $client-\u003eNewEnforcer($newEnforcerRequest)-\u003ewait();\n\nif (0 !== $status-\u003ecode) {\n    throw new \\Exception($status-\u003edetails, $status-\u003ecode);\n}\n```\n\n### EnforceRequest\n\n```php\n$enforceRequest = new EnforceRequest();\n$enforceRequest-\u003esetEnforcerHandler($newEnforcerReply-\u003egetHandler());\n$enforceRequest-\u003esetParams(['alice', 'data1', 'read']);\n\nlist($enforceReply, $status) = $client-\u003eEnforce($enforceRequest)-\u003ewait();\n\nif (0 !== $status-\u003ecode) {\n    throw new \\Exception($status-\u003edetails, $status-\u003ecode);\n}\n\nif ($enforceReply-\u003egetRes()) {\n    // permit alice to read data1\n} else {\n    // deny the request, show an error\n}\n\n```\n\n## License\n\nThis project is under Apache 2.0 License. See the [LICENSE](LICENSE) file for the full license text.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-casbin%2Fcasbin-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphp-casbin%2Fcasbin-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-casbin%2Fcasbin-client/lists"}