-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] Display the controller class name in 'debug:router' #20809
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
Conversation
if ($route->hasDefault('_controller') && 'txt' === $input->getOption('format')) { | ||
list($service, $method) = explode(':', $route->getDefault('_controller'), 2); | ||
try { | ||
$route->setDefault('_controller', sprintf("%s:%s\n (service: %s)", get_class($this->getContainer()->get($service)), $method, $service)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be ::
for fully-qualified class name and method (CNP)
What do you think about to move the code to |
@yceruto I did it at the first attempt, but the output was really ugly :/ |
@@ -87,6 +88,15 @@ protected function execute(InputInterface $input, OutputInterface $output) | |||
|
|||
$this->convertController($route); | |||
|
|||
// Converts a short notation service:method to a class::method. | |||
if ($route->hasDefault('_controller') && 'txt' === $input->getOption('format')) { | |||
list($service, $method) = explode(':', $route->getDefault('_controller'), 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Be careful with this, it's not always service:method
pattern, when a short notation controller (a:b:c
) is provided (most of the time), things like this could happen:
# services.yml
services:
appbundle:
class: stdClass
list($service, $method) = explode(':', 'AppBundle:Default:index', 2);
// $service <<< 'AppBundle'
// $method <<< 'Default:index'
// so
$this->getContainer()->get($service) //case insensitive
// return a valid service "appbundle"
and then shows a wrong output:
$ bin/console debug:router index
+--------------+---------------------------------------------------------+
| Property | Value |
+--------------+---------------------------------------------------------+
| Defaults | _controller: stdClass:Default:index |
| | (service: AppBundle) |
you may need to check if it's service:method
pattern before.
09f9626
to
aadae0d
Compare
@yceruto Thanks for the review. I have addressed your comments. |
Actually, I would like to propose a new approach for this comment. Instead of displaying:
Could we display:
|
What about removing the parentheses? |
This implementation has a drawback: it instantiate the controller (and of its dependencies). |
@stof I think using the "dev" container is not a good idea, because some route could only exist in production, and it will became hard to debug. Thus, here we only instantiate one controller (and yes all deps). IMHO It's not a big deal. |
aadae0d
to
543f496
Compare
I update the code to always display the class name ( |
543f496
to
cd2a6c3
Compare
$nameParser = $this->getContainer()->get('controller_name_converter'); | ||
try { | ||
$shortNotation = $nameParser->build($controller); | ||
$route->setDefault('_controller', sprintf("%s\n class: %s", $shortNotation, $controller)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the screenshots, that's not a class
, but a method
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
cd2a6c3
to
2219eaf
Compare
I think this PR is ready |
if (1 === substr_count($controller, ':')) { | ||
list($service, $method) = explode(':', $controller); | ||
try { | ||
$route->setDefault('_controller', sprintf("%s\n method: %s::%s", $service, get_class($this->getContainer()->get($service)), $method)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand what you are doing here. IIUC, you are storing the text representation of the controller in the route _controller
? Looks like it should be done when displaying the route instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, but I used the same hack as the previous implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So is it a real problem ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. I also update the screenshot.
2219eaf
to
9d91804
Compare
9d91804
to
f88d154
Compare
@@ -92,6 +92,9 @@ protected function describeRoute(Route $route, array $options = array()) | |||
array('Defaults', $this->formatRouterConfig($route->getDefaults())), | |||
array('Options', $this->formatRouterConfig($route->getOptions())), | |||
); | |||
if ($options['callable']) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the build failures, you need to check first that the callable
key does exist.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Fixed.
f88d154
to
157a830
Compare
Thank you @lyrixx. |
… 'debug:router' (lyrixx) This PR was merged into the 3.3-dev branch. Discussion ---------- [FrameworkBundle] Display the controller class name in 'debug:router' | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - --- Before:  After:  Commits ------- 157a830 [FrameworkBundle] Display the controller class name in 'debug:router'
Before:

After:
