{"id":20719730,"url":"https://github.com/slince/middleware","last_synced_at":"2025-04-23T14:23:51.877Z","repository":{"id":57053333,"uuid":"92489247","full_name":"slince/middleware","owner":"slince","description":":whale: A PSR15 middleware dispatcher","archived":false,"fork":false,"pushed_at":"2019-04-30T11:40:32.000Z","size":17,"stargazers_count":17,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-30T00:31:20.779Z","etag":null,"topics":["dispatcher","http","http-messages","middleware","middleware-dispatchers","psr-15","psr-7"],"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/slince.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}},"created_at":"2017-05-26T08:26:19.000Z","updated_at":"2025-02-14T14:29:00.000Z","dependencies_parsed_at":"2022-08-24T03:41:07.728Z","dependency_job_id":null,"html_url":"https://github.com/slince/middleware","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slince%2Fmiddleware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slince%2Fmiddleware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slince%2Fmiddleware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slince%2Fmiddleware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/slince","download_url":"https://codeload.github.com/slince/middleware/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250448960,"owners_count":21432353,"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":["dispatcher","http","http-messages","middleware","middleware-dispatchers","psr-15","psr-7"],"created_at":"2024-11-17T03:18:10.770Z","updated_at":"2025-04-23T14:23:51.854Z","avatar_url":"https://github.com/slince.png","language":"PHP","readme":"﻿# Middleware Dispatcher\n\n[![Build Status](https://img.shields.io/travis/slince/middleware/master.svg?style=flat-square)](https://travis-ci.org/slince/middleware)\n[![Coverage Status](https://img.shields.io/codecov/c/github/slince/middleware.svg?style=flat-square)](https://codecov.io/github/slince/middleware)\n[![Latest Stable Version](https://img.shields.io/packagist/v/slince/middleware.svg?style=flat-square\u0026label=stable)](https://packagist.org/packages/slince/middleware)\n[![Scrutinizer](https://img.shields.io/scrutinizer/g/slince/middleware.svg?style=flat-square)](https://scrutinizer-ci.com/g/slince/middleware/?branch=master)\n\nThe package is a flexible PSR-15 middleware dispatcher for PSR-7 request message that help to create middlewares and dispatch.\n\n## Installation\n\nInstall via composer\n\n```bash\ncomposer require slince/middleware\n```\n\n## Quick example\n\n```php\n$dispatcher = new Slince\\Middleware\\Dispatcher([$middleware1, $middleware2]);\n\n$response = $dispatcher-\u003eprocess(Zend\\Diactoros\\ServerRequestFactory::fromGlobals());\n\nvar_dump($response instanceof Psr\\Http\\Message\\ResponseInterface);\n```\n\n## Usage\n\n### Add middleware\n\nAdd PSR-15 middlewares to the queue\n\n```php\nuse Psr\\Http\\Message\\ServerRequestInterface;\nuse Interop\\Http\\Server\\MiddlewareInterface;\nuse Interop\\Http\\Server\\RequestHandlerInterface;\nuse Zend\\Diactoros\\Response;\n\nclass MyMiddleware implements MiddlewareInteface\n{\n    public function process(ServerRequestInterface $request, RequestHandlerInterface $next) \n    {\n        $response = new Response();\n        $response-\u003egetBody()-\u003ewrite('hello world');\n        return $response;\n    }\n}\n$dispatcher = new Slince\\Middleware\\Dispatcher([\n    new MyMiddleware()\n]);\n```\nOr add a callable function directly\n\n```php\n$dispatcher-\u003epush(function(ServerRequestInterface $request, RequestHandlerInterface $next){\n    return $delegate-\u003eprocess($request);\n});\n```\n\n### Dispatch\n\n```php\ntry {\n    $response = $dispatcher-\u003eprocess(Zend\\Diactoros\\ServerRequestFactory::fromGlobals());\n} catch (Slince\\Middleware\\Exception\\MissingResponseException $exception) {\n    //...\n}\n```\n\nA `MissingResponseException` will be thrown if the middleware did not return a invalid response or the queue was exhausted\n\n## License\n \nThe MIT license. See [MIT](https://opensource.org/licenses/MIT)","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslince%2Fmiddleware","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fslince%2Fmiddleware","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslince%2Fmiddleware/lists"}