{"id":20603044,"url":"https://github.com/flightphp/permissions","last_synced_at":"2025-04-15T01:54:40.285Z","repository":{"id":242636642,"uuid":"810127498","full_name":"flightphp/permissions","owner":"flightphp","description":"Library for managing permissions in Flight Applications","archived":false,"fork":false,"pushed_at":"2024-12-22T04:14:49.000Z","size":8,"stargazers_count":7,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-15T01:54:32.499Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/flightphp.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}},"created_at":"2024-06-04T05:23:09.000Z","updated_at":"2025-03-22T11:29:20.000Z","dependencies_parsed_at":"2024-06-04T06:03:29.748Z","dependency_job_id":"8b34b176-bb2c-49d9-83bd-7a65efa11004","html_url":"https://github.com/flightphp/permissions","commit_stats":null,"previous_names":["flightphp/permissions"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flightphp%2Fpermissions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flightphp%2Fpermissions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flightphp%2Fpermissions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flightphp%2Fpermissions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flightphp","download_url":"https://codeload.github.com/flightphp/permissions/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248991540,"owners_count":21194894,"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-16T09:15:48.236Z","updated_at":"2025-04-15T01:54:40.268Z","avatar_url":"https://github.com/flightphp.png","language":"PHP","readme":"# Flight Permissions Plugin\n[![Latest Stable Version](https://poser.pugx.org/flightphp/permissions/v)](https://packagist.org/packages/flightphp/permissions)\n[![License](https://poser.pugx.org/flightphp/permissions/license)](https://packagist.org/packages/flightphp/permissions)\n[![PHP Version Require](https://poser.pugx.org/flightphp/permissions/require/php)](https://packagist.org/packages/flightphp/permissions)\n[![Dependencies](https://poser.pugx.org/flightphp/permissions/dependents)](https://packagist.org/packages/flightphp/permissions)\n\nPermissions are an important part to any application. Even in a RESTful API you'll need to check that the API key has permission to perform the action requested. In some cases it makes sense to handle authentication in a middleware, but in other cases, it's more helpful to have a standard set of permissions. \n\nThis library follows a CRUD based permissions systems. See [basic example](#basic-example) for example on how this is accomplished.\n\n## Basic Example\n\nLet's assume you have a feature in your application that checks if a user is logged in. You can create a permissions object like this:\n\n```php\n// index.php\nrequire 'vendor/autoload.php';\n\n// some code \n\n// then you probably have something that tells you who the current role is of the person\n// likely you have something where you pull the current role\n// from a session variable which defines this\n// after someone logs in, otherwise they will have a 'guest' or 'public' role.\n$current_role = 'admin';\n\n// setup permissions\n$permission = new \\flight\\Permission($current_role);\n$permission-\u003edefineRule('loggedIn', function($current_role) {\n\treturn $current_role !== 'guest';\n});\n\n// You'll probably want to persist this object in Flight somewhere\nFlight::set('permission', $permission);\n```\n\nThen in a controller somewhere, you might have something like this.\n\n```php\n\u003c?php\n\n// some controller\nclass SomeController {\n\tpublic function someAction() {\n\t\t$permission = Flight::get('permission');\n\t\tif ($permission-\u003ehas('loggedIn')) {\n\t\t\t// do something\n\t\t} else {\n\t\t\t// do something else\n\t\t}\n\t}\n}\n```\n\nYou can also use this to track if they have permission to do something in your application.\nFor instance, if your have a way that users can interact with posting on your software, you can \ncheck if they have permission to perform certain actions.\n\n```php\n$current_role = 'admin';\n\n// setup permissions\n$permission = new \\flight\\Permission($current_role);\n$permission-\u003edefineRule('post', function($current_role) {\n\tif($current_role === 'admin') {\n\t\t$permissions = ['create', 'read', 'update', 'delete'];\n\t} else if($current_role === 'editor') {\n\t\t$permissions = ['create', 'read', 'update'];\n\t} else if($current_role === 'author') {\n\t\t$permissions = ['create', 'read'];\n\t} else if($current_role === 'contributor') {\n\t\t$permissions = ['create'];\n\t} else {\n\t\t$permissions = [];\n\t}\n\treturn $permissions;\n});\nFlight::set('permission', $permission);\n```\n\nThen in a controller somewhere...\n\n```php\nclass PostController {\n\tpublic function create() {\n\t\t$permission = Flight::get('permission');\n\t\tif ($permission-\u003ecan('post.create')) {\n\t\t\t// do something\n\t\t} else {\n\t\t\t// do something else\n\t\t}\n\t}\n}\n```\n\nSee how much fun this is? Let's install it and get started!\n\n## Installation\n\nSimply install with Composer\n\n```php\ncomposer require flightphp/permissions \n```\n\n## Documentation\n\nHead over to the [documentation page](https://docs.flightphp.com/awesome-plugins/permissions) to learn more about usage and how cool this thing is! :)\n\n## License\n\nMIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflightphp%2Fpermissions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflightphp%2Fpermissions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflightphp%2Fpermissions/lists"}