Skip to content

[Routing] Improvements for debug:router command #59991

Open
@javiereguiluz

Description

@javiereguiluz

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?)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions