{"id":29419365,"url":"https://github.com/perer876/guard","last_synced_at":"2026-01-20T16:30:35.769Z","repository":{"id":302761752,"uuid":"1012915197","full_name":"Perer876/guard","owner":"Perer876","description":"Lightweight, enum-based definition, querying and mapping of permissions in PHP applications.","archived":false,"fork":false,"pushed_at":"2025-08-13T05:23:47.000Z","size":38,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-10T13:32:00.642Z","etag":null,"topics":["authorization","permission","rbac"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Perer876.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,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-03T04:54:43.000Z","updated_at":"2025-08-12T05:38:40.000Z","dependencies_parsed_at":"2025-08-13T16:50:48.744Z","dependency_job_id":null,"html_url":"https://github.com/Perer876/guard","commit_stats":null,"previous_names":["perer876/guard"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/Perer876/guard","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Perer876%2Fguard","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Perer876%2Fguard/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Perer876%2Fguard/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Perer876%2Fguard/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Perer876","download_url":"https://codeload.github.com/Perer876/guard/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Perer876%2Fguard/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28607170,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T16:10:39.856Z","status":"ssl_error","status_checked_at":"2026-01-20T16:10:39.493Z","response_time":117,"last_error":"SSL_read: 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":["authorization","permission","rbac"],"created_at":"2025-07-12T00:33:02.022Z","updated_at":"2026-01-20T16:30:35.755Z","avatar_url":"https://github.com/Perer876.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003e [!IMPORTANT]\n\u003e Still in development, not feature complete.\n\n# Guard\n\nLightweight, enum-based definition, querying and mapping of permissions in PHP applications.\n\n## Usage\n\nYou can define roles and permissions using an enum. \n\nFor example, you can define roles like this:\n```php\n\u003c?php declare(strict_types=1);\n\nnamespace App\\Permissions;\n\nuse Guard\\Role;\n\nenum UserRole: string implements Role\n{\n    case Admin = 'admin';\n    case User = 'user';\n    case Guest = 'guest';\n}\n```\n\nThen, you can specify which roles are granted to each permission.\n\n```php\n\u003c?php declare(strict_types=1);\n\nnamespace App\\Permissions;\n\nuse Guard\\GrantTo;\nuse Guard\\Permission;\n\n#[GrantTo(UserRole::Admin)] // \u003c- Top level: It's granted to all permissions\nenum TodoPermission implements Permission\n{\n    #[GrantTo(UserRole::Member)] // \u003c- Fine-grained: It's granted to this specific permission\n    case ViewAny;\n\n    #[GrantTo(UserRole::Member, UserRole::Viewer)] // \u003c- Multiple roles can be granted\n    case View;\n\n    #[GrantTo(UserRole::Member)]\n    #[GrantTo(UserRole::Editor)]\n    case Create;\n\n    #[GrantTo(UserRole::Member, UserRole::Editor)]\n    case Update;\n    \n    case Delete;\n}\n```\nBefore you can check permissions, you need to implement the `Subject` interface \nin your user model.\nYou also need to return the user's roles in a `getRoles` method and must add the \n`AsSubject` trait to the subject so you can check permissions.\n\n```php\n\u003c?php declare(strict_types=1);\n\nnamespace App\\Models;\n\nuse App\\Permissions\\UserRole;\nuse Guard\\AsSubject;\nuse Guard\\Subject;\nuse Illuminate\\Foundation\\Auth\\User as Authenticatable;\nuse Override;\n\nfinal class User extends Authenticatable implements Subject\n{\n    use AsSubject;\n    \n    /** @return iterable\u003cUserRole\u003e */\n    #[Override]\n    public function getRoles(): iterable\n    {\n        yield $this-\u003erole;\n    }\n    \n    /** @return array\u003cstring, string\u003e */\n    protected function casts(): array\n    {\n        return [\n            'role' =\u003e UserRole::class,\n        ];\n    }\n    \n    /* ... */\n}\n```\n\nIn a policy, for example, you can check the user model permissions like this:\n\n```php\n$user-\u003ehasPermission(TodoPermission::ViewAny);\n```\n\n## Installation\n\nYou can install the package via Composer:\n```bash\ncomposer require perer876/permission:v1.0.0-alpha.2\n```\n\n## Documentation\n\nComing soon.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperer876%2Fguard","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fperer876%2Fguard","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperer876%2Fguard/lists"}