Skip to content

[Routing] Improvements for debug:router command #59991

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
javiereguiluz opened this issue Mar 17, 2025 · 5 comments
Open

[Routing] Improvements for debug:router command #59991

javiereguiluz opened this issue Mar 17, 2025 · 5 comments

Comments

@javiereguiluz
Copy link
Member

javiereguiluz commented Mar 17, 2025

Description

This PR proposes several changes/tweaks for the debug:router command.

For reference purposes, this is the output when running it in the Symfony Demo application:

$ php bin/console debug:router

 -------------------------- ---------- -------- ------ ---------------------------------------------------------
  Name                       Method     Scheme   Host   Path
 -------------------------- ---------- -------- ------ ---------------------------------------------------------
  _preview_error             ANY        ANY      ANY    /_error/{code}.{_format}
  _logout_main               ANY        ANY      ANY    /logout
  ux_live_component          ANY        ANY      ANY    /{_locale}/_components/{_live_component}/{_live_action}
  _wdt_stylesheet            ANY        ANY      ANY    /_wdt/styles.css
  _wdt                       ANY        ANY      ANY    /_wdt/{token}
  _profiler_home             ANY        ANY      ANY    /_profiler/
  _profiler_search           ANY        ANY      ANY    /_profiler/search
  _profiler_search_bar       ANY        ANY      ANY    /_profiler/search_bar
  _profiler_phpinfo          ANY        ANY      ANY    /_profiler/phpinfo
  _profiler_xdebug           ANY        ANY      ANY    /_profiler/xdebug
  _profiler_font             ANY        ANY      ANY    /_profiler/font/{fontName}.woff2
  _profiler_search_results   ANY        ANY      ANY    /_profiler/{token}/search/results
  _profiler_open_file        ANY        ANY      ANY    /_profiler/open
  _profiler                  ANY        ANY      ANY    /_profiler/{token}
  _profiler_router           ANY        ANY      ANY    /_profiler/{token}/router
  _profiler_exception        ANY        ANY      ANY    /_profiler/{token}/exception
  _profiler_exception_css    ANY        ANY      ANY    /_profiler/{token}/exception.css
  homepage                   ANY        ANY      ANY    /{_locale}
  admin_index                GET        ANY      ANY    /{_locale}/admin/post/
  admin_post_index           GET        ANY      ANY    /{_locale}/admin/post/
  admin_post_new             GET|POST   ANY      ANY    /{_locale}/admin/post/new
  admin_post_show            GET        ANY      ANY    /{_locale}/admin/post/{id}
  admin_post_edit            GET|POST   ANY      ANY    /{_locale}/admin/post/{id}/edit
  admin_post_delete          POST       ANY      ANY    /{_locale}/admin/post/{id}/delete
  blog_index                 GET        ANY      ANY    /{_locale}/blog/
  blog_rss                   GET        ANY      ANY    /{_locale}/blog/rss.xml
  blog_index_paginated       GET        ANY      ANY    /{_locale}/blog/page/{page}
  blog_post                  GET        ANY      ANY    /{_locale}/blog/posts/{slug}
  comment_new                POST       ANY      ANY    /{_locale}/blog/comment/{postSlug}/new
  blog_search                GET        ANY      ANY    /{_locale}/blog/search
  security_login             ANY        ANY      ANY    /{_locale}/login
  user_edit                  GET|POST   ANY      ANY    /{_locale}/profile/edit
  user_change_password       GET|POST   ANY      ANY    /{_locale}/profile/change-password
 -------------------------- ---------- -------- ------ ---------------------------------------------------------

Example

(1) If the value of scheme and host is ANY for all routes, don't display those columns. In my experience, it's rare to have different values for these columns, so this is just "noise" and makes rows overflow because route paths can be very long.

(2) Partial search should look into route paths too.

For example, if the route name is user_change_password and the path is /{_locale}/profile/change-password, the following search should display the route:

$ php bin/console debug:router change-password

  The route "change-password" does not exist.

In my opinion, folks are usually more aware of route paths rather than their names. For example, you might know that a route contains .woff2, so this should work:

$ php bin/console debug:router woff

# this would display the details of this route:
# _profiler_font   ANY   /_profiler/font/{fontName}.woff2

To avoid confusion, the list of routes shown for partial search, could also include the path (so the user can see where the match occurred) and even display the partial match character in other color or underlined:

❯ php bin/console debug:router page

 Select one of the matching routes:
  [0] blog_index_paginated (/{_locale}/blog/page/{page})
  [1] doc_page (/doc/{slug})

(3) Display route aliases in a new row instead of a new column. The table is so wide, that when adding a new column, it usually overflows and makes it very hard to process the contents.

When using the --show-aliases option, display route aliases in a single line below the route name:

$ php bin/console debug:router --show-aliases

 -------------------------- ---------- -------- ------ ---------------------------------------
  Name                       Method     Scheme   Host   Path
 -------------------------- ---------- -------- ------ ---------------------------------------
  # ...
  homepage                   ANY        ANY      ANY    /{_locale}
  aliases: home, index
  admin_index                GET        ANY      ANY    /{_locale}/admin/post/
  admin_post_index           GET        ANY      ANY    /{_locale}/admin/post/
  # ...
  blog_index                 GET        ANY      ANY    /{_locale}/blog/
  aliases: blog, news
  blog_rss                   GET        ANY      ANY    /{_locale}/blog/rss.xml
  blog_index_paginated       GET        ANY      ANY    /{_locale}/blog/page/{page}
  aliases: blog_page
  blog_post                  GET        ANY      ANY    /{_locale}/blog/posts/{slug}
  comment_new                POST       ANY      ANY    /{_locale}/blog/comment/{postSlug}/new
  # ...
 -------------------------- ---------- -------- ------ ---------------------------------------

Note: maybe display the aliases: label in yellow for better visibility

(4) Always show aliases when displaying a single route details.

If I define an alias e.g. for the blog_index route, I can't see it even if I add the --show-aliases option explicitly. Aliases should be displayed by default in route details. No option should be required.

❯ php bin/console debug:router blog_index --show-aliases

+--------------+--------------------------------------------------------------------------------------------------------------------------------------+
| Property     | Value                                                                                                                                |
+--------------+--------------------------------------------------------------------------------------------------------------------------------------+
| Route Name   | blog_index                                                                                                                           |
| Aliases      | blog, news                                                                                                                           |
| Path         | /{_locale}/blog/                                                                                                                     |
| Path Regex   | {^/(?P<_locale>ar|bg|bn|bs|ca|cs|de|en|es|eu|fr|hr|id|it|ja|lt|ne|nl|pl|pt_BR|ro|ru|sl|sq|sr_Cyrl|sr_Latn|tr|uk|vi|zh_CN)/blog/$}sDu |
| Host         | ANY                                                                                                                                  |
| Host Regex   |                                                                                                                                      |
| Scheme       | ANY                                                                                                                                  |
| Method       | GET                                                                                                                                  |
| Requirements | _locale: ar|bg|bn|bs|ca|cs|de|en|es|eu|fr|hr|id|it|ja|lt|ne|nl|pl|pt_BR|ro|ru|sl|sq|sr_Cyrl|sr_Latn|tr|uk|vi|zh_CN                   |
| Class        | Symfony\Component\Routing\Route                                                                                                      |
| Defaults     | _controller: App\Controller\BlogController::index()                                                                                  |
|              | _format: html                                                                                                                        |
|              | _locale: en                                                                                                                          |
|              | page: 1                                                                                                                              |
| Options      | compiler_class: Symfony\Component\Routing\RouteCompiler                                                                              |
|              | utf8: true                                                                                                                           |
+--------------+--------------------------------------------------------------------------------------------------------------------------------------+

(5) Tweak some help comments:

$ php bin/console debug:router --help

Usage:
  debug:router [options] [--] [<name>]

Arguments:
  name                    A route name

Options:
      --show-controllers  Show assigned controllers in overview
      --show-aliases      Show aliases in overview
      --format=FORMAT     The output format ("txt", "xml", "json", "md") [default: "txt"]
      --raw               To output raw route(s)
      --method=METHOD     Filter by HTTP method [default: ""]
      # ...
  • For --show-controllers and --show-aliases, I'd remove the in overview part. It should probably be in the list of routes, but this doesn't seem an important detail to mention
  • The description of --show-aliases ("Show aliases") could be updated to Display route aliases (if any)
  • The description of --show-controllers ("Show assigned controllers") could be updated to Display the controller asociated to each route
  • The --raw option is hard to understand. I didn't look into the code, but applying it makes no difference in the output to me
  • The --method option description could be updated as Only display routes matching this HTTP method (the word "filter" is sometimes confusing: filter in or filter out?)
@alexandre-daubois
Copy link
Member

alexandre-daubois commented Mar 18, 2025

I like what you propose here! For the third point however, I'm a bit skeptical. It feels a bit weird to have a new row like this (I understand that it may be personal taste here). Maybe this could be displayed like this:

$ php bin/console debug:router --show-aliases

 -------------------------- ---------- -------- ------ ---------------------------------------
  Name                       Method     Scheme   Host   Path
 -------------------------- ---------- -------- ------ ---------------------------------------
  # ...
  homepage (=home,index)     ANY        ANY      ANY    /{_locale}
  admin_index                GET        ANY      ANY    /{_locale}/admin/post/
  admin_post_index           GET        ANY      ANY    /{_locale}/admin/post/
 -------------------------- ---------- -------- ------ ---------------------------------------

Or:

$ php bin/console debug:router --show-aliases

 -------------------------------- ---------- -------- ------ ---------------------------------------
  Name                             Method     Scheme   Host   Path
 -------------------------------- ---------- -------- ------ ---------------------------------------
  # ...
  homepage (aliases: home, index)  ANY        ANY      ANY    /{_locale}
  admin_index                      GET        ANY      ANY    /{_locale}/admin/post/
  admin_post_index                 GET        ANY      ANY    /{_locale}/admin/post/
 -------------------------------- ---------- -------- ------ ---------------------------------------

And maybe display aliases in a color like yellow, this is a good idea 👍 I agree having a whole new column for aliases isn't really necessary to me. We could still deal with a new column if we get rid of scheme and host when ANY is used everywhere (I agree that most of the times, these columns are always the same).

@tcoch
Copy link

tcoch commented Mar 25, 2025

Regarding (1), should we also hide the method if there is a only ANY values to be coherent? Or do we want to keep this column to encourage people to specify it?

Regarding (3), if feels difficult to read. I'd keep the Aliases column in the table.
However one improvement could be to define a max size for this column, and breakline, to render something like this:

 -------------------------------- ---------- -------- ------ -------------------------- ---------------------------------
  Name                             Method     Scheme   Host   Path                       Aliases
 -------------------------------- ---------- -------- ------ -------------------------- ---------------------------------
  # ...
  homepage                         ANY        ANY      ANY    /{_locale}
  admin_index                      GET        ANY      ANY    /{_locale}/admin           route_alias_1|route_alias_2|
                                                                                         route_alias_3
  admin_post_index                 GET        ANY      ANY    /{_locale}/admin/post      route_alias_4|route_alias_5|
                                                                                         route_alias_6
  login                            GET        ANY      ANY    /{_locale}/login
  logout                           GET        ANY      ANY    /{_locale}/logout
 -------------------------------- ---------- -------- ------ -------------------------- ---------------------------------

No comment on (2) (4) and (5), looks great.

@mamazu
Copy link
Contributor

mamazu commented Apr 8, 2025

This issue does overlap with an older one I have proposed in Feburary maybe we could merge those two: #59767

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants