{"id":16695167,"url":"https://github.com/davidepastore/slim-restrict-route","last_synced_at":"2026-02-11T18:33:24.533Z","repository":{"id":56963346,"uuid":"57071167","full_name":"DavidePastore/Slim-Restrict-Route","owner":"DavidePastore","description":"A Slim middleware to restrict ip addresses that will access to your routes","archived":false,"fork":false,"pushed_at":"2020-05-25T22:42:31.000Z","size":26,"stargazers_count":22,"open_issues_count":0,"forks_count":9,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-19T21:43:52.611Z","etag":null,"topics":["ip","middleware","php","restricted","slim-framework"],"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/DavidePastore.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-25T19:44:51.000Z","updated_at":"2023-09-26T22:10:37.000Z","dependencies_parsed_at":"2022-08-21T05:40:27.561Z","dependency_job_id":null,"html_url":"https://github.com/DavidePastore/Slim-Restrict-Route","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DavidePastore%2FSlim-Restrict-Route","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DavidePastore%2FSlim-Restrict-Route/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DavidePastore%2FSlim-Restrict-Route/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DavidePastore%2FSlim-Restrict-Route/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DavidePastore","download_url":"https://codeload.github.com/DavidePastore/Slim-Restrict-Route/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221817792,"owners_count":16885628,"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":["ip","middleware","php","restricted","slim-framework"],"created_at":"2024-10-12T17:05:43.744Z","updated_at":"2026-02-11T18:33:24.501Z","avatar_url":"https://github.com/DavidePastore.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Slim Framework Restrict Route\n\n[![Latest version][ico-version]][link-packagist]\n[![Build Status][ico-travis]][link-travis]\n[![Coverage Status][ico-scrutinizer]][link-scrutinizer]\n[![Quality Score][ico-code-quality]][link-code-quality]\n[![Total Downloads][ico-downloads]][link-downloads]\n[![PSR2 Conformance][ico-styleci]][link-styleci]\n\n\nA slim middleware to restrict ip addresses that will access to your routes. It internally uses `Ip` Validator of [Respect/Validation][respect-validation] and [rka-ip-address-middleware][rka-ip-address-middleware].\n\n## Install\n\nVia Composer\n\n``` bash\n$ composer require davidepastore/slim-restrict-route\n```\n\nRequires Slim 3.0.0 or newer.\n\n## Usage\n\nYou have to register also the [`RKA\\Middleware\\IpAddress`][rka-ip-address-middleware] middleware to correctly read the ip address.\nIn most cases you want to register `DavidePastore\\Slim\\RestrictRoute` for a single route, however,\nas it is middleware, you can also register it for all routes.\n\n\n### Register per route\n\n```php\n$app = new \\Slim\\App();\n\n$app-\u003eadd(new RKA\\Middleware\\IpAddress());\n\n$options = array(\n  'ip' =\u003e '192.*.*.*'\n);\n\n$app-\u003eget('/api/myEndPoint',function ($req, $res, $args) {\n  //Your amazing route code\n})-\u003eadd(new \\DavidePastore\\Slim\\RestrictRoute\\RestrictRoute($options));\n\n$app-\u003erun();\n```\n\n\n### Register for all routes\n\n```php\n$app = new \\Slim\\App();\n\n$app-\u003eadd(new RKA\\Middleware\\IpAddress());\n\n$options = array(\n  'ip' =\u003e '192.*.*.*'\n);\n\n// Register middleware for all routes\n// If you are implementing per-route checks you must not add this\n$app-\u003eadd(new \\DavidePastore\\Slim\\RestrictRoute\\RestrictRoute($options));\n\n$app-\u003eget('/foo', function ($req, $res, $args) {\n  //Your amazing route code\n});\n\n$app-\u003epost('/bar', function ($req, $res, $args) {\n  //Your amazing route code\n});\n\n$app-\u003erun();\n```\n\n## Ip address\n\nYou can restrict route using a different value of `ip` in the `options` given to `\\RestrictRoute`:\n* any of the filters provided by PHP regarding `FILTER_VALIDATE_IP` (e.g.: `FILTER_FLAG_NO_PRIV_RANGE`);\n* asterisk (`*`) to filter ip that are in the given subnet (e.g.: `192.*`);\n* ranges (`-`) to filter ip that are in the given range (e.g.: `192.168.0.0-192.168.255.255`);\n* single ip (e.g.: `192.168.0.1-192.168.0.1`);\n* array of ranges to filter ip (e.g.: `array('192.0.0.0-192.255.255.255', '178.0.0.*')`).\n\nYou can find more syntax information on the `Ip` validator [documentation](https://github.com/Respect/Validation/blob/master/docs/Ip.md) and in its [Unit Test class](https://github.com/Respect/Validation/blob/master/tests/unit/Rules/IpTest.php).\n\n## Testing\n\n``` bash\n$ phpunit\n```\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n## Credits\n\n- [Davide Pastore](https://github.com/davidepastore)\n\n\n[respect-validation]: https://github.com/Respect/Validation/\n[rka-ip-address-middleware]: https://github.com/akrabat/rka-ip-address-middleware\n[ico-version]: https://img.shields.io/packagist/v/DavidePastore/Slim-Restrict-Route.svg?style=flat-square\n[ico-travis]: https://travis-ci.org/DavidePastore/Slim-Restrict-Route.svg?branch=master\n[ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/DavidePastore/Slim-Restrict-Route.svg?style=flat-square\n[ico-code-quality]: https://img.shields.io/scrutinizer/g/davidepastore/Slim-Restrict-Route.svg?style=flat-square\n[ico-downloads]: https://img.shields.io/packagist/dt/davidepastore/slim-restrict-route.svg?style=flat-square\n[ico-styleci]: https://styleci.io/repos/57071167/shield\n\n[link-packagist]: https://packagist.org/packages/davidepastore/slim-restrict-route\n[link-travis]: https://travis-ci.org/DavidePastore/Slim-Restrict-Route\n[link-scrutinizer]: https://scrutinizer-ci.com/g/DavidePastore/Slim-Restrict-Route/code-structure\n[link-code-quality]: https://scrutinizer-ci.com/g/DavidePastore/Slim-Restrict-Route\n[link-downloads]: https://packagist.org/packages/davidepastore/slim-restrict-route\n[link-styleci]: https://styleci.io/repos/57071167/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidepastore%2Fslim-restrict-route","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavidepastore%2Fslim-restrict-route","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidepastore%2Fslim-restrict-route/lists"}