Add explicit @version special route token support for API major versioning within a single module

Đang mở
#550 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
45/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
php
Lĩnh vực
api, backend

Hướng nghiên cứu

Bắt đầu bằng cách lần theo việc xử lý @version trong src/Router/PatternCompiler.php, src/Router/RouteBuilder.php, src/Router/RouteDispatcher.php, src/Router/MatchedRoute.php và src/Http/Traits/Request/Route.php; trước tiên hãy kiểm tra các template của DemoApi và các dependency #546 và #548. Được xem là hoàn thành khi các major version được cấu hình và được hỗ trợ khớp nhau, các controller nhận biết version được resolve trong một module, các giá trị version vẫn là một phần của route context, và các test bao phủ việc matching và resolution.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

routing

Summary

Add API major versioning support based on the explicit special route token:

  • @version

so a single API module can expose multiple major API versions concurrently, such as:

  • /api/v1/posts
  • /api/v2/posts

without treating each version as a separate module.

Why

Quantum needs a clean framework-level API versioning model.

The intended ownership model is:

  • one logical Api module
  • multiple supported API major versions inside that module

With the special route token foundation in place, versioning can be expressed explicitly in route patterns instead of relying on:

  • duplicated route trees
  • positional URL conventions
  • separate modules per version
  • hidden dispatch tricks

Goal

Allow routes to explicitly declare API major version position using:

  • @version

and let the framework treat the matched version as framework-owned route context for version-aware controller resolution.

Proposed Direction

API routes that are versioned should explicitly include:

  • @version

Examples:

$route->get('@version/posts', 'PostController', 'posts');
$route->get('@version/post/[uuid=:any]', 'PostController', 'post');
$route->post('@version/signin', 'AuthController', 'signin');

This should allow URLs such as:

  • /api/v1/posts
  • /api/v2/posts
  • /api/v1/signin

depending on module prefix configuration and supported versions.

Config Direction

Supported API versions should be declared in module config.

A likely shape is:

'Api' => [
    'prefix' => 'api',
    'enabled' => true,
    'versions' => ['v1', 'v2'],
]

The route token:

  • @version

should then match only those configured supported versions.

Controller Resolution Direction

Matched version values should be used by the framework to resolve version-specific controllers inside the same module.

Examples:

  • v1 + PostController
    resolves to:

    • {ModuleBaseNamespace}\Api\Controllers\V1\PostController
  • v2 + PostController
    resolves to:

    • {ModuleBaseNamespace}\Api\Controllers\V2\PostController

This allows one route shape to map to different major-version controller implementations inside a single module.

Important behavior

The resolved version should be:

  • matched through the @version token
  • validated against configured supported versions
  • made available to framework internals as version route context
  • used for version-aware controller resolution
  • kept distinct from ordinary controller action parameters by default

Scope

This ticket should focus on major API versioning only.

It should not introduce:

  • minor or patch versioning in the URL
  • header-based minor/patch runtime negotiation
  • separate modules per API version

Minor and patch changes should remain outside the first implementation scope.

Acceptance Criteria

  • routes can explicitly declare API version position using @version
  • matched @version values are validated against configured supported versions
  • a single API module can expose multiple supported major versions concurrently
  • matched version values are used for version-aware controller resolution within the same module
  • routed version values do not become ordinary positional controller action parameters by default
  • tests cover @version route matching and version-aware controller resolution behavior
  • templates and examples can be updated to use @version where appropriate

Notes

Relevant code:

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

This ticket depends on:

Ngôn ngữ chính
PHP
Star
36
Fork
22
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của quantum-php/framework

Tất cả issue của quantum-php/framework

Issue tương tự

Thêm issue về PHP

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.