{"id":23107957,"url":"https://github.com/andrewdyer/gate","last_synced_at":"2026-04-18T01:11:23.795Z","repository":{"id":56948000,"uuid":"242252586","full_name":"andrewdyer/gate","owner":"andrewdyer","description":"Check if a user is authorized to perform a given action","archived":false,"fork":false,"pushed_at":"2024-12-23T00:13:31.000Z","size":33,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-06T01:09:46.240Z","etag":null,"topics":["authorization","gate","permissions","php"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andrewdyer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2020-02-22T00:07:12.000Z","updated_at":"2024-12-23T00:08:42.000Z","dependencies_parsed_at":"2025-02-09T10:41:36.921Z","dependency_job_id":"d727a524-f845-4a16-afb3-b8195c5d2fb3","html_url":"https://github.com/andrewdyer/gate","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/andrewdyer/gate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewdyer%2Fgate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewdyer%2Fgate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewdyer%2Fgate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewdyer%2Fgate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andrewdyer","download_url":"https://codeload.github.com/andrewdyer/gate/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewdyer%2Fgate/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29374082,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-12T08:51:36.827Z","status":"ssl_error","status_checked_at":"2026-02-12T08:51:26.849Z","response_time":55,"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","gate","permissions","php"],"created_at":"2024-12-17T01:16:30.242Z","updated_at":"2026-02-12T17:33:36.629Z","avatar_url":"https://github.com/andrewdyer.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Gate\n\n[![Latest Stable Version](https://poser.pugx.org/andrewdyer/gate/v/stable)](https://packagist.org/packages/andrewdyer/gate)\n[![Total Downloads](https://poser.pugx.org/andrewdyer/gate/downloads)](https://packagist.org/packages/andrewdyer/gate)\n[![Daily Downloads](https://poser.pugx.org/andrewdyer/gate/d/daily)](https://packagist.org/packages/andrewdyer/gate)\n[![Monthly Downloads](https://poser.pugx.org/andrewdyer/gate/d/monthly)](https://packagist.org/packages/andrewdyer/gate)\n[![Latest Unstable Version](https://poser.pugx.org/andrewdyer/gate/v/unstable)](https://packagist.org/packages/andrewdyer/gate)\n[![License](https://poser.pugx.org/andrewdyer/gate/license)](https://packagist.org/packages/andrewdyer/gate)\n[![composer.lock](https://poser.pugx.org/andrewdyer/gate/composerlock)](https://packagist.org/packages/andrewdyer/gate)\n\nCheck if a user is authorized to perform a given action.\n\n## License\nLicensed under MIT. Totally free for private or commercial projects.\n\n## Installation\n```text\ncomposer require andrewdyer/gate\n```\n\n## Getting Started\n\nTo get started with the Gate library, you need to create an instance of the `Gate` class and pass an `Authenticatable` user to it.\n\n```php\nuse Anddye\\Gate\\Gate;\nuse Anddye\\Gate\\Authenticatable;\n\nclass User implements Authenticatable {\n    // User implementation\n}\n\n$user = new User();\n$gate = new Gate($user);\n```\n\n## Usage\n\n### Defining Abilities\n\nYou can define abilities using the `define` method. The first argument is the name of the ability, and the second argument is a callback that determines if the user has the ability.\n\n```php\n$gate-\u003edefine('edit-post', function ($user, $post) {\n    return $user-\u003eid === $post-\u003euser_id;\n});\n```\n\n### Checking Abilities\n\nYou can check abilities using the `allows` and `denies` methods.\n\n```php\nif ($gate-\u003eallows('edit-post', $post)) {\n    // The user can edit the post\n}\n\nif ($gate-\u003edenies('edit-post', $post)) {\n    // The user cannot edit the post\n}\n```\n\n### Authorizing Actions\n\nYou can authorize actions using the `authorize` method. This method will throw an `UnauthorizedException` if the user does not have the required abilities.\n\n```php\ntry {\n    $gate-\u003eauthorize(['edit-post'], $post);\n    // The user is authorized to edit the post\n} catch (UnauthorizedException $e) {\n    // The user is not authorized to edit the post\n}\n```\n\n### Registering Before Callbacks\n\nYou can register a callback to run before all checks using the `before` method.\n\n```php\n$gate-\u003ebefore(function ($user, $ability) {\n    if ($user-\u003eisAdmin()) {\n        return true;\n    }\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrewdyer%2Fgate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandrewdyer%2Fgate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrewdyer%2Fgate/lists"}