Support nested module-relative controller resolution in routes while preserving explicit controller class references

Đang mở
#546 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ó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
64/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 theo dõi quá trình phân giải controller qua src/Router/RouteBuilder.php và src/Router/RouteDispatcher.php, sau đó kiểm tra src/Router/Route.php cùng metadata của request route và các đường dẫn liệt kê route. Xác minh các chuỗi controller dạng phẳng, dạng lồng nhau tương đối theo module và dạng được qualify đầy đủ một cách tường minh trong quá trình dispatch, liệt kê route và metadata; thêm test cho từng trường hợp và xác nhận rằng hành vi dạng phẳng hiện có vẫn được giữ nguyên.

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

Mô tả

routing

Summary

Enhance Quantum route controller resolution so route definitions can reference controllers in nested subnamespaces/folders within the current module, while preserving existing support for explicit fully qualified controller class references.

This should allow controller route strings such as:

  • PostController
  • V1\PostController
  • Admin\UserController

to resolve relative to the current module’s Controllers namespace, without breaking the ability to use explicit FQCN controller class strings where intentionally supported.

Why

Current route controller resolution in Quantum is too limited for deeper controller organization.

Today, flat shorthand works for controllers that live directly under:

  • {Module}\Controllers\...

However, the current resolution logic uses a simple backslash check to decide whether a handler should be prefixed with the module controller namespace.

That means a nested relative controller path such as:

  • V1\PostController

is currently treated the same way as an explicitly qualified controller class string, even though those are different use cases.

As a result, Quantum lacks a clean way to organize controllers inside nested subnamespaces within the current module.

Goal

Allow nested controller organization inside a module while preserving both:

  • current flat controller shorthand
  • intentional explicit FQCN controller class references

Proposed Direction

Update route controller resolution so it can distinguish between:

Module-relative controller shorthand

Examples:

  • PostController
  • V1\PostController
  • Admin\UserController

These should resolve relative to the current module’s Controllers namespace.

Examples:

  • PostController
    resolves to:

    • {ModuleBaseNamespace}\{CurrentModule}\Controllers\PostController
  • V1\PostController
    resolves to:

    • {ModuleBaseNamespace}\{CurrentModule}\Controllers\V1\PostController
  • Admin\UserController
    resolves to:

    • {ModuleBaseNamespace}\{CurrentModule}\Controllers\Admin\UserController
Explicit FQCN controller references

If the route handler is intentionally written as an explicit fully qualified controller class string, that behavior should remain supported.

Examples:

  • \Modules\Api\Controllers\V1\PostController
  • Modules\Api\Controllers\V1\PostController

The resolution logic should therefore no longer use “contains backslash” as the only distinction between shorthand and explicit controller references.

Instead, it should distinguish properly between:

  • nested module-relative controller paths
  • explicit FQCN controller class references

Why this matters

This is a prerequisite for cleaner future work such as:

  • API major versioning within a single module
  • better controller organization in larger modules
  • route-set mounting with version-specific controller subnamespaces

without forcing:

  • flat controller folders
  • duplicated route definitions
  • awkward controller naming workarounds

Acceptance Criteria

  • flat controller shorthand continues to work
  • nested controller shorthand such as V1\PostController and Admin\UserController resolves correctly within the current module
  • explicit FQCN controller class references remain supported if intentionally provided
  • route listing, dispatch, and request route metadata continue to work with nested resolved controllers
  • controller resolution no longer relies solely on “contains backslash” to decide whether a handler is relative or explicit
  • tests verify flat controller shorthand resolution such as PostController
  • tests verify nested module-relative controller shorthand such as V1\PostController
  • tests verify explicit FQCN controller class references continue to resolve correctly

Notes

Relevant code:

  • src/Router/RouteBuilder.php
  • src/Router/RouteDispatcher.php
  • src/Router/Route.php
  • src/Http/Traits/Request/Route.php
  • src/Console/Commands/RouteListCommand.php

This ticket should be treated as a routing foundation improvement and a prerequisite for cleaner API versioning support inside a single module.

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.