{"id":20520156,"url":"https://github.com/thomiceli/router","last_synced_at":"2025-10-25T00:00:21.074Z","repository":{"id":75313942,"uuid":"334979278","full_name":"thomiceli/router","owner":"thomiceli","description":null,"archived":false,"fork":false,"pushed_at":"2022-03-04T15:45:59.000Z","size":29,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-16T10:32:32.358Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thomiceli.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-02-01T14:39:58.000Z","updated_at":"2021-04-10T11:47:15.000Z","dependencies_parsed_at":null,"dependency_job_id":"6d0ecd9c-9285-4b2e-a596-03f438d490f5","html_url":"https://github.com/thomiceli/router","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomiceli%2Frouter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomiceli%2Frouter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomiceli%2Frouter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomiceli%2Frouter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thomiceli","download_url":"https://codeload.github.com/thomiceli/router/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242123449,"owners_count":20075361,"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-11-15T22:18:16.745Z","updated_at":"2025-10-25T00:00:15.970Z","avatar_url":"https://github.com/thomiceli.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# thomas-miceli/router\n\n```shell\n$ composer require thomas-miceli/router\n```\n\n### Dependencies\n* Nyholm's [PSR-7 implementation](https://github.com/nyholm/psr7) (to create HTTP OO messages) and [PSR-7 server](https://github.com/nyholm/psr7-server) (for server requests)\n* [PHP-DI](https://php-di.org) for dependency injection \n* [PSR-15 interfaces](https://www.php-fig.org/psr/psr-15/)\n\n### Working full example\n\n```php\n\u003c?php\n// index.php\nuse Psr\\Http\\Server\\RequestHandlerInterface;\nuse ThomasMiceli\\Router\\Http\\Request;\nuse ThomasMiceli\\Router\\Http\\Response;\nuse ThomasMiceli\\Router\\Router;\n\nrequire 'vendor/autoload.php';\n\n$router = new Router();\n\n$dependency = new stdClass();\n$dependency-\u003ehello = 'hello';\n$router-\u003eregisterInstance($dependency);\n\n$router-\u003emiddleware(function (Request $request, RequestHandlerInterface $handler) {\n    $request = $request-\u003ewithAttribute('global', true);\n    \n    // code executed before the route\n    $response = $handler-\u003ehandle($request);\n    // code executed after the route\n\n    return $response;\n});\n\n$router\n    -\u003eget('/hello/{name}', function ($name, Request $request, Response $response, stdClass $myClass) {\n        if ($request-\u003egetAttribute('route') === true) {\n            $myClass-\u003eroute_middleware = 'works';\n        }\n\n        if ($request-\u003egetAttribute('global') === true) {\n            $myClass-\u003eglobal_middleware = 'works';\n        }\n        $myClass-\u003ehello .= \" $name\";\n\n        return $response-\u003ejson($myClass);\n        // or\n        // $response-\u003egetBody()-\u003ewrite(\"$name\");\n        // return $response;\n\n    })\n    -\u003emiddleware(function (Request $request, RequestHandlerInterface $handler) {\n        // executed second\n        $request = $request-\u003ewithAttribute('route', true);\n\n        /** @var Response $response */\n        $response = $handler-\u003ehandle($request);\n        $response-\u003esetHeader('after', 'true');\n        return $response;\n    })\n    -\u003emiddleware(function (Request $request, RequestHandlerInterface $handler) {\n        // executed first\n        $request = $request-\u003ewithAttribute('route', false);\n        return $handler-\u003ehandle($request);\n    });\n\n$router-\u003erun();\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthomiceli%2Frouter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthomiceli%2Frouter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthomiceli%2Frouter/lists"}