{"id":20678877,"url":"https://github.com/phpgt/routing","last_synced_at":"2025-07-23T09:35:57.103Z","repository":{"id":41397550,"uuid":"337060717","full_name":"phpgt/Routing","owner":"phpgt","description":"Middleware that routes HTTP requests to your code.","archived":false,"fork":false,"pushed_at":"2025-06-06T10:57:23.000Z","size":280,"stargazers_count":0,"open_issues_count":7,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-18T21:15:58.428Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/phpgt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["phpgt"]}},"created_at":"2021-02-08T11:56:12.000Z","updated_at":"2025-06-05T22:36:21.000Z","dependencies_parsed_at":"2025-01-17T15:15:38.754Z","dependency_job_id":"232fb44a-5ef9-4478-8ca2-b9882525d5b7","html_url":"https://github.com/phpgt/Routing","commit_stats":{"total_commits":68,"total_committers":2,"mean_commits":34.0,"dds":"0.044117647058823484","last_synced_commit":"e00c1e0b42e781d3f0865cc488baee9c15b8c323"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/phpgt/Routing","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpgt%2FRouting","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpgt%2FRouting/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpgt%2FRouting/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpgt%2FRouting/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phpgt","download_url":"https://codeload.github.com/phpgt/Routing/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpgt%2FRouting/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266655669,"owners_count":23963554,"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-07-23T02:00:09.312Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"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":[],"created_at":"2024-11-16T21:22:53.369Z","updated_at":"2025-07-23T09:35:57.080Z","avatar_url":"https://github.com/phpgt.png","language":"PHP","funding_links":["https://github.com/sponsors/phpgt"],"categories":[],"sub_categories":[],"readme":"Routes HTTP requests to logic and view files.\n=============================================\n\nAs HTTP requests are received by an application, the appropriate logic methods need to be called, along with certain files being loaded to construct the correct view for the request. This is done by taking the HTTP request and _routing_ it to the matching areas of the application source code.\n\nThis repository breaks down the concept of routing into three areas of responsibility:\n\n1. Matching an HTTP request to an appropriate callback function.\n2. Creating an Assembly of logic and view files that match the request.\n3. Processing the Assemblies, in order to create the correct HTTP response.\n\nWhen referring to Requests within this repository, we are always referring to a [PSR-7 HTTP Message][psr-7].\n\n***\n\n\u003ca href=\"https://github.com/PhpGt/Routing/actions\" target=\"_blank\"\u003e\n\t\u003cimg src=\"https://badge.status.php.gt/routing-build.svg\" alt=\"Build status\" /\u003e\n\u003c/a\u003e\n\u003ca href=\"https://scrutinizer-ci.com/g/PhpGt/Routing\" target=\"_blank\"\u003e\n\t\u003cimg src=\"https://badge.status.php.gt/routing-quality.svg\" alt=\"Code quality\" /\u003e\n\u003c/a\u003e\n\u003ca href=\"https://scrutinizer-ci.com/g/PhpGt/Routing\" target=\"_blank\"\u003e\n\t\u003cimg src=\"https://badge.status.php.gt/routing-coverage.svg\" alt=\"Code coverage\" /\u003e\n\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/PhpGt/Routing\" target=\"_blank\"\u003e\n\t\u003cimg src=\"https://badge.status.php.gt/routing-version.svg\" alt=\"Current version\" /\u003e\n\u003c/a\u003e\n\u003ca href=\"http://www.php.gt/routing\" target=\"_blank\"\u003e\n\t\u003cimg src=\"https://badge.status.php.gt/routing-docs.svg\" alt=\"PHP.G/Routing documentation\" /\u003e\n\u003c/a\u003e\n\nPlanning\n--------\n\nMain flow:\n\n+ Your application can have a `router.php` in project root, but is completely optional due to `router.default.php` being provided by WebEngine. You can use the router.php file to add complicated rules that define which source files are used to build up the response, rather than always being limited to using path-based rules, as is currently the case with WebEngine. \n+ The name of the application's router is defined in config by `app_router_path` key.\n+ The application router defines a class called `Router` in the application's root namespace, which extends `Gt\\Routing\\AbstractRouter`.\n+ BaseRouter's `go()` method is called, supplying a PSR-7 `RequestInterface` which will call functions of the application's router.\n+ The application router can have any number of functions. They are made \"routable\" by adding an Attribute that extends `Route`. Available Attributes include `Get`, `Post` (and other HTTP verbs) or `Any` to match on all verbs.\n+ The simplest routable function has the Any attribute with no parameters (`#[Any()]`), which will be executed for every request.\n+ Available Attribute parameters include: `name` to provide the route a name for future reference, `accept` to provide a Content-type to match the Request's `Accept` header with, `path` to define a matching path (with pattern matching), `function` to define the function to call.\n+ Only the functions that have Attributes that match the incoming request will be executed.\n+ It's the job of the application's routable functions to add appropriate view and logic files to the Router's `Assembly` objects. The framework (WebEngine in my case) will then use the Assembly objects to build up the appropriate `View` and execute the appropriate `Logic` objects in the correct order.\n\nTODO List:\n----------\n\n+ [x] Perform content negotiation when there are multiple matches. For example: an API route might explicitly accept \"application/xml\" but the default accept header of web browsers also sends this for page requests, but it gives it a q=0.9 - as long as there is a route with text/html or application/xhtml+xml with a higher q value, it should be preferred.\n+ [ ] Take a RequestInterface and a project directory, and construct the appropriate Assembly objects - matching the URL path to directory paths, extracting dynamic paths where appropriate.\n\n[psr-7]: https://www.php-fig.org/psr/psr-7/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpgt%2Frouting","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphpgt%2Frouting","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpgt%2Frouting/lists"}