{"id":13711757,"url":"https://github.com/equip/dispatch","last_synced_at":"2026-01-11T16:52:51.782Z","repository":{"id":53156181,"uuid":"73659186","full_name":"equip/dispatch","owner":"equip","description":"An HTTP Interop compatible middleware dispatcher","archived":false,"fork":false,"pushed_at":"2021-04-11T06:13:05.000Z","size":37,"stargazers_count":25,"open_issues_count":1,"forks_count":2,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-11-13T22:35:03.439Z","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/equip.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":"2016-11-14T02:28:22.000Z","updated_at":"2023-09-26T22:45:20.000Z","dependencies_parsed_at":"2022-08-21T11:50:39.819Z","dependency_job_id":null,"html_url":"https://github.com/equip/dispatch","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/equip%2Fdispatch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/equip%2Fdispatch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/equip%2Fdispatch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/equip%2Fdispatch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/equip","download_url":"https://codeload.github.com/equip/dispatch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252772135,"owners_count":21801861,"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-08-02T23:01:11.282Z","updated_at":"2026-01-11T16:52:51.777Z","avatar_url":"https://github.com/equip.png","language":"PHP","readme":"Equip Dispatch\n==============\n\n[![Latest Stable Version](https://img.shields.io/packagist/v/equip/dispatch.svg)](https://packagist.org/packages/equip/dispatch)\n[![License](https://img.shields.io/packagist/l/equip/dispatch.svg)](https://github.com/equip/dispatch/blob/master/LICENSE)\n[![Build Status](https://travis-ci.org/equip/dispatch.svg)](https://travis-ci.org/equip/dispatch)\n[![Code Coverage](https://scrutinizer-ci.com/g/equip/dispatch/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/equip/dispatch/?branch=master)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/equip/dispatch/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/equip/dispatch/?branch=master)\n\nAn HTTP Interop compatible middleware dispatcher in [Equip](http://equip.github.io/).\nAttempts to be [PSR-1](http://www.php-fig.org/psr/psr-1/), [PSR-2](http://www.php-fig.org/psr/psr-2/),\n[PSR-4](http://www.php-fig.org/psr/psr-4/), [PSR-7](http://www.php-fig.org/psr/psr-7/),\nand [PSR-15](http://www.php-fig.org/psr/psr-15/) compliant.\n\nHeavily influenced by the design of [Tari by ircmaxwell](https://github.com/ircmaxell/Tari-PHP).\n\nFor more information, see [the documentation](http://equipframework.readthedocs.org/en/latest/dispatch).\n\n## Install\n\n```\ncomposer require equip/dispatch\n```\n\n## Usage\n\nThe `MiddlewareCollection` is a container for middleware that acts as the entry point.\nIt takes two arguments:\n\n- An array of `$middleware` which must be instances of server middleware.\n- A callable `$default` that acts as the terminator for the collection and returns\n  an empty response.\n\nOnce the collection is prepared it can dispatched with a server request and will return\nthe response for output.\n\n### Example\n\n```php\nuse Equip\\Dispatch\\MiddlewareCollection;\n\n// Any implementation of PSR-15 MiddlewareInterface\n$middleware = [\n    new FooMiddleware(),\n    // ...\n];\n\n// Default handler for end of collection\n$default = function (ServerRequestInterface $request) {\n    // Any implementation of PSR-7 ResponseInterface\n    return new Response();\n};\n\n$collection = new MiddlewareCollection($middleware);\n\n// Any implementation of PSR-7 ServerRequestInterface\n$request = ServerRequest::fromGlobals();\n$response = $collection-\u003edispatch($request, $default);\n```\n\n### Nested Collections\n\nThe `MiddlewareCollection` also implements the `MiddlewareInterface` to allow\ncollections to be nested:\n\n```php\nuse Equip\\Dispatch\\MiddlewareCollection;\n\n// Any implementation of PSR-15 MiddlewareInterface\n$middleware = [\n    new FooMiddleware(),\n\n    // A nested collection\n    new MiddlewareCollection(...),\n\n    // More middleware\n    new BarMiddleware(),\n    // ...\n];\n\n$collection = new MiddlewareCollection($middleware);\n\n// HTTP factories can also be used\n$default = [$responseFactory, 'createResponse'];\n$request = $serverRequestFactory-\u003ecreateRequest($_SERVER);\n\n$response = $collection-\u003edispatch($request, $default);\n```\n","funding_links":[],"categories":["Packages"],"sub_categories":["Dispatcher"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fequip%2Fdispatch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fequip%2Fdispatch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fequip%2Fdispatch/lists"}