{"id":20138409,"url":"https://github.com/zakirullin/conditional-middleware","last_synced_at":"2025-10-29T06:32:47.052Z","repository":{"id":57089187,"uuid":"133351852","full_name":"zakirullin/conditional-middleware","owner":"zakirullin","description":" PSR-15 middleware that makes it possible to add conditional middlewares, based on request","archived":false,"fork":false,"pushed_at":"2019-04-25T09:25:38.000Z","size":8,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-15T20:39:20.850Z","etag":null,"topics":["middleware","middleware-pipeline","psr-15","psr-7"],"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/zakirullin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-14T11:40:36.000Z","updated_at":"2025-06-19T12:33:25.000Z","dependencies_parsed_at":"2022-08-20T16:50:25.347Z","dependency_job_id":null,"html_url":"https://github.com/zakirullin/conditional-middleware","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/zakirullin/conditional-middleware","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zakirullin%2Fconditional-middleware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zakirullin%2Fconditional-middleware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zakirullin%2Fconditional-middleware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zakirullin%2Fconditional-middleware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zakirullin","download_url":"https://codeload.github.com/zakirullin/conditional-middleware/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zakirullin%2Fconditional-middleware/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281576593,"owners_count":26524883,"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","status":"online","status_checked_at":"2025-10-29T02:00:06.901Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["middleware","middleware-pipeline","psr-15","psr-7"],"created_at":"2024-11-13T21:37:55.318Z","updated_at":"2025-10-29T06:32:46.989Z","avatar_url":"https://github.com/zakirullin.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# zakirullin/conditional-middleware\n\n[![Build Status](https://img.shields.io/travis/zakirullin/conditional-middleware.svg?style=flat-square)](https://travis-ci.org/zakirullin/conditional-middleware)\n[![Scrutinizer](https://img.shields.io/scrutinizer/g/zakirullin/conditional-middleware.svg?style=flat-square)](https://scrutinizer-ci.com/g/zakirullin/conditional-middleware/)\n![PHP from Packagist](https://img.shields.io/packagist/php-v/zakirullin/conditional-middleware.svg?style=flat-square)\n![GitHub commits](https://img.shields.io/github/commits-since/zakirullin/conditional-middleware/0.1.0.svg?style=flat-square)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)\n\nPSR-15 middleware that makes it possible to add conditional middlewares, based on `request`\n\n## Requirements\n\n* PHP \u003e= 7.1\n* A [PSR-7](https://packagist.org/providers/psr/http-message-implementation) http message implementation ([Diactoros](https://github.com/zendframework/zend-diactoros), [Guzzle](https://github.com/guzzle/psr7), [Slim](https://github.com/slimphp/Slim), etc...)\n* A [PSR-15 middleware dispatcher](https://github.com/middlewares/awesome-psr15-middlewares#dispatcher)\n\n## Installation\n\nThis package is installable and autoloadable via Composer as [zakirullin/conditional-middleware](https://packagist.org/packages/zakirullin/conditional-middleware).\n\n```sh\ncomposer require zakirullin/conditional-middleware \n```\n\n## PHP\n\n```php\n$shouldProtect = function (\\Psr\\Http\\Message\\ServerRequestInterface $request) {\n    $handler = $request-\u003egetAttribute('handler');\n    return $handler != 'login';\n};\n$getIdentity = function (\\Psr\\Http\\Message\\ServerRequestInterface $request) {\n    $session = $request-\u003egetAttribute('session');\n    return [$session-\u003eget('userId')];\n};\n\n$dispatcher = new Dispatcher([\n    ...\n    new \\Zakirullin\\Middlewares\\CSRF($shouldProtect, $getIdentity, 'secret'),\n    ...\n]);\n```\n\n## Options\n\n```php \n__construct(\n    callable $shouldProtect,\n    callable $getIdentity,\n    string $secret,\n    string $attribute = self::ATTRIBUTE,\n    int $ttl = self::TTL,\n    string $algorithm = self::ALGORITHM\n)\n```\n\n#### `name(string $name)`\n\nThe session name. If it's not defined, the default `PHPSESSID` will be used.\n\n---\n\nThe MIT License (MIT). Please see [LICENSE](LICENSE) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzakirullin%2Fconditional-middleware","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzakirullin%2Fconditional-middleware","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzakirullin%2Fconditional-middleware/lists"}