{"id":13711846,"url":"https://github.com/middlewares/aura-router","last_synced_at":"2026-01-07T23:54:59.754Z","repository":{"id":53043871,"uuid":"69786176","full_name":"middlewares/aura-router","owner":"middlewares","description":"PSR-15 middleware to use Aura.Router","archived":false,"fork":false,"pushed_at":"2025-03-26T14:46:30.000Z","size":59,"stargazers_count":9,"open_issues_count":2,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-29T09:52:15.866Z","etag":null,"topics":["aura","http","middleware","psr-15","router"],"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/middlewares.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-02T08:11:19.000Z","updated_at":"2025-04-04T10:50:06.000Z","dependencies_parsed_at":"2022-09-09T18:55:17.553Z","dependency_job_id":null,"html_url":"https://github.com/middlewares/aura-router","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/middlewares%2Faura-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/middlewares%2Faura-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/middlewares%2Faura-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/middlewares%2Faura-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/middlewares","download_url":"https://codeload.github.com/middlewares/aura-router/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252772157,"owners_count":21801865,"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":["aura","http","middleware","psr-15","router"],"created_at":"2024-08-02T23:01:12.242Z","updated_at":"2026-01-07T23:54:59.741Z","avatar_url":"https://github.com/middlewares.png","language":"PHP","funding_links":[],"categories":["Packages"],"sub_categories":["Router"],"readme":"# middlewares/aura-router\n\n[![Latest Version on Packagist][ico-version]][link-packagist]\n[![Software License][ico-license]](LICENSE)\n![Testing][ico-ga]\n[![Total Downloads][ico-downloads]][link-downloads]\n\nMiddleware to use [Aura.Router](https://github.com/auraphp/Aura.Router/) with a few more extras.\n\n## Requirements\n\n* PHP \u003e= 7.2\n* A [PSR-7 http library](https://github.com/middlewares/awesome-psr15-middlewares#psr-7-implementations)\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 [middlewares/aura-router](https://packagist.org/packages/middlewares/aura-router).\n\n```sh\ncomposer require middlewares/aura-router\n```\n\n## Example\n\nIn this example, we are using [middleware/request-handler](https://github.com/middlewares/request-handler) to execute the route handler:\n\n```php\n// Create the router\n$router = new Aura\\Router\\RouterContainer();\n\n$map = $router-\u003egetMap();\n\n$map-\u003eget('hello', '/hello/{name}', function ($request) {\n\n    // The route parameters are mapped to attributes\n    $name = $request-\u003egetAttribute('name');\n\n    // You can echo the output (it will be captured and wrote into the body)\n    echo sprintf('Hello %s', $name);\n\n    // Or return a string\n    return sprintf('Hello %s', $name);\n\n    // Or return a response\n    return new Response();\n});\n\n$dispatcher = new Dispatcher([\n    new Middlewares\\AuraRouter($router),\n    new Middlewares\\RequestHandler()\n]);\n\n$response = $dispatcher-\u003edispatch(new ServerRequest('/hello/world'));\n```\n\n**Aura.Router** allows to define anything as the router handler (a closure, callback, action object, controller class, etc.). The middleware will store this handler in a request attribute.\n\n## Usage\n\nCreate the middleware with a `Aura\\Router\\RouterContainer` instance:\n\n```php\n$routerContainer = new Aura\\Router\\RouterContainer();\n\n$route = new Middlewares\\AuraRouter($routerContainer);\n```\n\nOptionally, you can provide a `Psr\\Http\\Message\\ResponseFactoryInterface` as the second argument, that will be used to create the error responses (`404`, `405` or `406`). If it's not defined, [Middleware\\Utils\\Factory](https://github.com/middlewares/utils#factory) will be used to detect it automatically.\n\n```php\n$routerContainer = new Aura\\Router\\RouterContainer();\n$map = $router-\u003egetMap();\n$map-\u003eget('list', '/users', 'listUsers')-\u003eextras(\n    'key' =\u003e 'value'\n]);\n\n$optionalResponseFactory = new MyOwnResponseFactory();\n\n$middleware = new Middlewares\\AuraRouter($routerContainer, $optionalResponseFactory);\n\n$dispatcher = new Dispatcher([\n    // Hold the resolved route handler reference in an attribute called \"handler\"\n    // (default: request-handler)\n    $middleware-\u003ehandlerAttribute('handler'),\n       \n    // Hold Aura's resolved route instance in an attribute called \"aura-route\"\n    // (default: route)\n    $middleware-\u003erouteAttribute('aura-route'),\n\n    // Execute the route handler\n    (new Middlewares\\RequestHandler())-\u003ehandlerAttribute('handler')\n]);\n\n// then, inside our Request Handler or Middleware\npublic function process(\n    ServerRequestInterface $request,\n    RequestHandlerInterface $handler\n): ResponseInterface {\n    /** @var string $handler this returns 'listUsers' */\n    $handler = $request-\u003egetAttribute('handler');\n    \n    /** @var Route $route this returns the resolved Route instance */\n    $route = $request-\u003egetAttribute('aura-route');\n    \n    // example to retrieve the previously set extra key/value \"value\"\n    $route-\u003eextras['key'];\n    \n    // example to retrieve the route name \"list\"\n    $route-\u003ename;\n}\n```\n\n---\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information about recent changes and [CONTRIBUTING](CONTRIBUTING.md) for contributing details.\n\nThe MIT License (MIT). Please see [LICENSE](LICENSE) for more information.\n\n[ico-version]: https://img.shields.io/packagist/v/middlewares/aura-router.svg?style=flat-square\n[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square\n[ico-ga]: https://github.com/middlewares/aura-router/workflows/testing/badge.svg\n[ico-downloads]: https://img.shields.io/packagist/dt/middlewares/aura-router.svg?style=flat-square\n\n[link-packagist]: https://packagist.org/packages/middlewares/aura-router\n[link-downloads]: https://packagist.org/packages/middlewares/aura-router\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiddlewares%2Faura-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmiddlewares%2Faura-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiddlewares%2Faura-router/lists"}