{"id":22678293,"url":"https://github.com/hyperf-ext/http-server-router","last_synced_at":"2025-03-29T13:12:17.514Z","repository":{"id":56987682,"uuid":"322383546","full_name":"hyperf-ext/http-server-router","owner":"hyperf-ext","description":"Hyperf HTTP 服务器命名路由扩展组件。","archived":false,"fork":false,"pushed_at":"2021-07-30T18:48:39.000Z","size":28,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-04T13:44:37.182Z","etag":null,"topics":["hyperf","named-router","php","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/hyperf-ext.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":"2020-12-17T18:47:45.000Z","updated_at":"2023-07-09T17:25:43.000Z","dependencies_parsed_at":"2022-08-21T12:50:26.796Z","dependency_job_id":null,"html_url":"https://github.com/hyperf-ext/http-server-router","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperf-ext%2Fhttp-server-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperf-ext%2Fhttp-server-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperf-ext%2Fhttp-server-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperf-ext%2Fhttp-server-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hyperf-ext","download_url":"https://codeload.github.com/hyperf-ext/http-server-router/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246187242,"owners_count":20737462,"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":["hyperf","named-router","php","router"],"created_at":"2024-12-09T18:14:41.526Z","updated_at":"2025-03-29T13:12:17.491Z","avatar_url":"https://github.com/hyperf-ext.png","language":"PHP","readme":"# Hyperf HTTP 服务器命名路由扩展组件\n\n## 概要\n\n该组件通过绑定 `HyperfExt\\HttpServer\\Router\\DispatcherFactory` 到 `Hyperf\\HttpServer\\Router\\DispatcherFactory` 来实现扩展路由功能，由于修改了返回类型，PHP 版本必须 \u003e= 7.4。\n\n## 安装\n\n```shell\ncomposer require hyperf-ext/http-server-router\n```\n\n## 使用\n\n### 定义命名路由\n\n在路由选项中定义 `name` 参数来对路由命名，支持对路由组命名。\n\n```php\nuse Hyperf\\HttpServer\\Router\\Router;\n\nRouter::addGroup('/users/{id}', function () {\n    Router::get('/comments', 'App\\Controller\\IndexController@index', ['name' =\u003e 'comments.index']); // 该路由名称将被组合为 `users.comments.index`\n}, ['name' =\u003e 'users.']);\n```\n\n### 获取路由对象\n\n#### 通过路由名称获取指定路由\n\n```php\nuse Hyperf\\HttpServer\\Router\\Router;\n\n/** @var \\HyperfExt\\HttpServer\\Router\\Route $route */\n$route = Router::getRoute('users.comments.index');\n```\n\n#### 通过当前请求获取当前路由\n\n```php\nuse Hyperf\\HttpServer\\Router\\Router;\n\n/** @var \\HyperfExt\\HttpServer\\Router\\Route $route */\n$route = Router::getCurrentRoute();\n```\n\n### 生成指定路由的 URI\n\n```php\n/**\n * @var \\HyperfExt\\HttpServer\\Router\\Route $route\n * @var \\Hyperf\\HttpMessage\\Uri\\Uri $uri\n */\n$uri = $route-\u003ecreateUri([\n    'id' =\u003e 123,\n    'page_num' =\u003e 2,\n    'page_size' =\u003e 20,\n]);\n$link = (string) $uri; // 结果为 `/users/123/comments?page_num=2\u0026page_size=20`\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyperf-ext%2Fhttp-server-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhyperf-ext%2Fhttp-server-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyperf-ext%2Fhttp-server-router/lists"}