Skip to content

[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

Merged
merged 1 commit into from
Jan 2, 2017

Conversation

lyrixx
Copy link
Member

@lyrixx lyrixx commented Dec 7, 2016

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:
screenshot7

After:
screenshot3

@carsonbot carsonbot added Status: Needs Review DX DX = Developer eXperience (anything that improves the experience of using Symfony) FrameworkBundle Feature labels Dec 7, 2016
@nicolas-grekas nicolas-grekas added this to the 3.x milestone Dec 7, 2016
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));
Copy link
Member

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)

@yceruto
Copy link
Member

yceruto commented Dec 7, 2016

What do you think about to move the code to convertController() method to cover bin/console debug:router too (i.e. without name argument) ?

@lyrixx
Copy link
Member Author

lyrixx commented Dec 7, 2016

@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);
Copy link
Member

@yceruto yceruto Dec 7, 2016

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.

@lyrixx lyrixx force-pushed the debug-router-with-service branch from 09f9626 to aadae0d Compare December 8, 2016 19:20
@lyrixx
Copy link
Member Author

lyrixx commented Dec 8, 2016

@yceruto Thanks for the review. I have addressed your comments.

@lyrixx
Copy link
Member Author

lyrixx commented Dec 8, 2016

Actually, I would like to propose a new approach for this comment. Instead of displaying:

| Defaults     | _controller: AppBundle:Default:index                    |

Could we display:

| Defaults     | _controller: AppBundle:Default:index                              |
                      (class: AppBundle\Controller\DefaultController::indexAction) |

@fabpot
Copy link
Member

fabpot commented Dec 9, 2016

What about removing the parentheses?

@stof
Copy link
Member

stof commented Dec 9, 2016

This implementation has a drawback: it instantiate the controller (and of its dependencies).
could we use the dumped ContainerBuilder (used by debug:container) to look at the service definition instead (and skipping this enhanced behavior when we don't have this dumped ContainerBuilder) ?

@lyrixx
Copy link
Member Author

lyrixx commented Dec 13, 2016

@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.

@lyrixx lyrixx force-pushed the debug-router-with-service branch from aadae0d to 543f496 Compare December 13, 2016 17:57
@lyrixx lyrixx changed the title [DX][FrameworkBundle] Display the class name in 'debug:router' when the controller is a service [DX][FrameworkBundle] Display the class name in 'debug:router' Dec 13, 2016
@lyrixx
Copy link
Member Author

lyrixx commented Dec 13, 2016

I update the code to always display the class name (a:b:c or service:method notation).
And I updated the screenshot.

@lyrixx lyrixx force-pushed the debug-router-with-service branch from 543f496 to cd2a6c3 Compare December 13, 2016 18:01
$nameParser = $this->getContainer()->get('controller_name_converter');
try {
$shortNotation = $nameParser->build($controller);
$route->setDefault('_controller', sprintf("%s\n class: %s", $shortNotation, $controller));
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@lyrixx lyrixx force-pushed the debug-router-with-service branch from cd2a6c3 to 2219eaf Compare December 13, 2016 20:17
@lyrixx
Copy link
Member Author

lyrixx commented Dec 22, 2016

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));
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member Author

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 ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so

Copy link
Member Author

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.

@lyrixx lyrixx force-pushed the debug-router-with-service branch from 2219eaf to 9d91804 Compare December 27, 2016 10:45
@lyrixx lyrixx changed the title [DX][FrameworkBundle] Display the class name in 'debug:router' [FrameworkBundle] Display the controller class name in 'debug:router' Dec 27, 2016
@lyrixx lyrixx force-pushed the debug-router-with-service branch from 9d91804 to f88d154 Compare December 30, 2016 10:07
@@ -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']) {
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Fixed.

@lyrixx lyrixx force-pushed the debug-router-with-service branch from f88d154 to 157a830 Compare December 30, 2016 10:47
@fabpot
Copy link
Member

fabpot commented Jan 2, 2017

Thank you @lyrixx.

@fabpot fabpot merged commit 157a830 into symfony:master Jan 2, 2017
fabpot added a commit that referenced this pull request Jan 2, 2017
… '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:
![screenshot7](https://cloud.githubusercontent.com/assets/408368/21152351/318af764-c166-11e6-8245-1729779e9809.png)

After:
![screenshot3](https://cloud.githubusercontent.com/assets/408368/21563210/02cf043e-ce80-11e6-94be-34736d85bb3b.png)

Commits
-------

157a830 [FrameworkBundle] Display the controller class name in 'debug:router'
@lyrixx lyrixx deleted the debug-router-with-service branch January 2, 2017 21:52
@nicolas-grekas nicolas-grekas modified the milestones: 3.x, 3.3 Mar 24, 2017
@fabpot fabpot mentioned this pull request May 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DX DX = Developer eXperience (anything that improves the experience of using Symfony) Feature FrameworkBundle Status: Needs Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants