Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Add first-class special route token support for framework-owned URL segments such as @lang and @version

未关闭
#548 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
45/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
冷清
技术栈
php
领域
backend

调研方向

先阅读 src/Router/PatternCompiler.php 和 src/Router/RouteBuilder.php,然后跟踪 src/Router/Route.php、MatchedRoute.php、RouteDispatcher.php 以及 src/Http/Traits/Request/Route.php 如何编译、匹配并暴露路由值。完成的标准是:@version/@lang 等保留 token 可以在同一个 pattern 中共存,在不进行默认 action 绑定的情况下到达路由上下文,并保持普通参数不变,同时测试覆盖解析、匹配和上下文行为。

由索引模型根据 Issue 内容生成。

描述

routing

Summary

Add first-class router support for framework-owned special route tokens such as:

  • @lang
  • @version

so route definitions can explicitly declare special URL segments in a clear, semantic, and framework-native way.

Why

Quantum currently handles special routing concerns inconsistently.

For example:

  • language URL handling relies on config-driven segment position detection
  • API versioning has no clean framework-level model yet

This makes special URL segments feel implicit, positional, and harder to reason about than ordinary route structure.

A better model is to let routes explicitly declare framework-owned special segments in the route pattern itself.

Examples:

$route->get('@lang/posts', 'PostController', 'posts');
$route->get('@version/posts', 'PostController', 'posts');
$route->get('@version/@lang/posts', 'PostController', 'posts');

This makes route semantics explicit while allowing the framework to treat those segments differently from ordinary user-defined route parameters.

Goal

Introduce a routing foundation that supports reserved special route tokens for framework-level concerns.

This foundation should make it possible for Quantum to support explicit special URL segments without relying on brittle positional config or ad hoc route conventions.

Proposed Direction

Support reserved route tokens inside route patterns, beginning with the concept of framework-owned segments such as:

  • @lang
  • @version

These tokens should be recognized by the router as special routing constructs rather than ordinary route parameters.

The framework should be able to:

  • recognize these tokens during route compilation
  • match them correctly during request routing
  • attach their resolved values to framework route context
  • keep them distinct from normal action parameters unless explicitly intended otherwise

Important behavior

Special route tokens should be treated differently from ordinary route params.

They should be:

  • framework-reserved
  • semantically meaningful
  • available to framework internals such as language detection or version-aware controller resolution
  • prevented from behaving like ordinary positional controller action arguments by default

Initial scope

This ticket is the router foundation only.

It should establish the special-token mechanism itself, not fully implement every feature that may use it.

Follow-up features can then build on this foundation, including:

  • explicit @lang routing support
  • explicit @version API routing support

Acceptance Criteria

  • the router supports reserved special tokens inside route patterns
  • special tokens are recognized during route compilation and matching
  • matched special-token values are available to framework internals as route context
  • special-token values are kept distinct from ordinary controller action parameter binding by default
  • the routing system can support multiple special tokens in one path, such as @version/@lang/posts
  • tests cover special-token parsing, matching, and route context behavior
  • existing ordinary route parameter behavior remains intact

Notes

Relevant code:

  • src/Router/PatternCompiler.php
  • src/Router/RouteBuilder.php
  • src/Router/Route.php
  • src/Router/MatchedRoute.php
  • src/Router/RouteDispatcher.php
  • src/Http/Traits/Request/Route.php

This ticket should be treated as the routing foundation for future explicit @lang and @version support.

主要语言
PHP
星标
36
派生
22
PR 合并指标
30 天内没有已合并 PR

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

quantum-php/framework 的其他 Issue

查看 quantum-php/framework 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。