Skip to content

[DX][FrameworkBundle] Show private aliases in debug:container #22385

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
May 3, 2017

Conversation

chalasr
Copy link
Member

@chalasr chalasr commented Apr 11, 2017

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #16388 Haehnchen/idea-php-symfony2-plugin#618
License MIT
Doc PR n/a

By building and compiling the container without TYPE_REMOVING passes, private aliases are available (shown when --show-private is passed). The ContainerBuilderDebugDumpPass now makes use of the ConfigCache component, removing the need for clearing the cache to get the debug:container output up to date (in sync with latest config).

Config

services:
    AppBundle\Foo:
        public: false

    foo_consumer1:
        class: AppBundle\Foo
        arguments: [ '@AppBundle\Foo' ]

    foo_consumer2:
        class: AppBundle\Foo
        arguments: [ '@AppBundle\Foo' ]

    foo_alias:
        alias: AppBundle\Foo

    foo_private_alias:
        public: false
        alias: AppBundle\Foo

Before

before

After

after

@chalasr chalasr force-pushed the debug-container-privates branch from d5615bf to d18ba64 Compare April 11, 2017 21:44
@chalasr chalasr changed the title [FrameworkBundle] Show private aliases in debug:container [DX][FrameworkBundle] Show private aliases in debug:container Apr 11, 2017
@chalasr chalasr force-pushed the debug-container-privates branch 5 times, most recently from 4581894 to 7d744e0 Compare April 12, 2017 09:35
@chalasr
Copy link
Member Author

chalasr commented Apr 12, 2017

Change documented and functionally tested.

@chalasr chalasr force-pushed the debug-container-privates branch 2 times, most recently from 374f779 to a065014 Compare April 12, 2017 09:40
@nicolas-grekas nicolas-grekas added this to the 3.4 milestone Apr 13, 2017
@chalasr
Copy link
Member Author

chalasr commented Apr 13, 2017

I can't imagine any existing feature impacted by this change. Also, the fixed ticket is 2 years old and it seems everyone agree this would be useful, it makes things simpler.

That said , I would love to get this in 3.3.

@chalasr
Copy link
Member Author

chalasr commented Apr 14, 2017

Added some screenshots to the PR body.

@javiereguiluz javiereguiluz added the DX DX = Developer eXperience (anything that improves the experience of using Symfony) label Apr 14, 2017
Copy link
Member

@javiereguiluz javiereguiluz left a comment

Choose a reason for hiding this comment

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

I can't review this proposal technically, but from the DX point of view is perfect! Thanks @chalasr.

throw new \LogicException('Debug information about the container is only available in debug mode.');
}

if (!is_file($cachedFile = $this->getContainer()->getParameter('debug.container.dump'))) {
throw new \LogicException('Debug information about the container could not be found. Please clear the cache and try again.');
if (is_file($cachedFile = $this->getContainer()->getParameter('debug.container.dump'))) {
Copy link
Member

Choose a reason for hiding this comment

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

AFAIK, debug.container.dump was only added by the compiler pass you deprecated. So this looks suspicious to me

Copy link
Member Author

Choose a reason for hiding this comment

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

This parameter isn't added by the pass, but loaded from there https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/Resources/config/debug.xml#L8. Do you think it's time to remove it?

if (!$this->getApplication()->getKernel()->isDebug()) {
$kernel = $this->getApplication()->getKernel();

if (!$kernel->isDebug()) {
Copy link
Member

Choose a reason for hiding this comment

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

do we actually need to keep this restriction ? Previously, it was because you the compiler pass was only dumping the file in debug mode. But you don't rely on this file anymore.

Copy link
Member Author

Choose a reason for hiding this comment

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

If we're sure there is nothing wrong to get these informations available in non debug mode, I would be glad to remove this check.

$container->compile();
$filesystem = new Filesystem();
try {
$filesystem->dumpFile($cachedFile, (new XmlDumper($container))->dump());
Copy link
Member

Choose a reason for hiding this comment

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

why dumping it ? If the goal is to use a cache to make next calls to the command faster, you must use the ConfigCache component to invalidate the cache when the container changes. Otherwise, the command will give outdated data once you edit the container.

Copy link
Member Author

Choose a reason for hiding this comment

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

The goal is indeed to make the next call faster, as it is currently. About invalidation, it seems to work naturally when clearing the cache, maybe due to the fact this dump is named %kernel.cache_dir%/%kernel.container_class%.xml? Not sure if it's worth dumping it at all, I think it's relevant to don't need to clear the cache for getting debug informations. WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

except that in dev, I never clear the cache fuly (except when running a composer command doing it for me), as cache files are refreshed individually when needed in debug mode (which is the main feature of the debug mode)

Copy link
Member Author

Choose a reason for hiding this comment

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

updated to use config cache, removed the debug.container.dump parameter also

Copy link
Member Author

Choose a reason for hiding this comment

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

parameter removal and compiler pass deprecation reverted, it now leverages the debug mode properly which isn't the case currently. It would be great if you could have a look

@chalasr chalasr force-pushed the debug-container-privates branch 2 times, most recently from 43d9aae to badb0dc Compare April 14, 2017 14:05
$container = $buildContainer();
$container->getCompilerPassConfig()->setRemovingPasses(array());
$container->compile();
$cache->write((new XmlDumper($container))->dump(), array(new FileResource($cacheDir.'/'.$containerClass.'.php')));
Copy link
Member

Choose a reason for hiding this comment

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

you should rather register the ContainerBuilder resources here rather than a FileResource for the compiled container

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@chalasr chalasr force-pushed the debug-container-privates branch 2 times, most recently from 57596c0 to 84b1a47 Compare April 14, 2017 14:12
@nicolas-grekas
Copy link
Member

I may have read too quickly, but doesn't this remove an XML file that maybe of use to some tier tools? Eg the phpstorm SF plugin and the likes?

@chalasr chalasr force-pushed the debug-container-privates branch 2 times, most recently from 1cad653 to 57db321 Compare April 14, 2017 15:28
@chalasr
Copy link
Member Author

chalasr commented Apr 14, 2017

@nicolas-grekas You're right, the phpstorm plugin relies on.
I managed to make this work using the container dumped by the ContainerBuilderDebugDumpPass, this does not deprecate it anymore. It should even improve the features of the phpstorm plugin.

@Haehnchen
Copy link
Contributor

Haehnchen commented Apr 14, 2017

PhpStorm Plugin point of view. as i see this PR just extends the xml files, so i am able to resolve Haehnchen/idea-php-symfony2-plugin#618 on my side

@chalasr chalasr force-pushed the debug-container-privates branch from 8dde8ae to 5810d77 Compare April 14, 2017 17:46
@nicolas-grekas
Copy link
Member

👍

@chalasr chalasr force-pushed the debug-container-privates branch 2 times, most recently from c0d418d to 051b200 Compare April 14, 2017 17:50
@nicolas-grekas
Copy link
Member

ping @symfony/deciders
OK to merge this one for 3.3 as requested?

@chalasr chalasr force-pushed the debug-container-privates branch 7 times, most recently from 051b200 to 6746c06 Compare April 20, 2017 21:14
@chalasr chalasr force-pushed the debug-container-privates branch from 6746c06 to 883723e Compare April 20, 2017 22:49
@chalasr
Copy link
Member Author

chalasr commented Apr 21, 2017

PR rebased.

@weaverryan
Copy link
Member

👍 (and 👍 for 3.3 for me, it's really a bug fix)

@chalasr
Copy link
Member Author

chalasr commented Apr 25, 2017

I think we are good here.

@chalasr
Copy link
Member Author

chalasr commented Apr 28, 2017

Can we reconsider the milestone here? A lot of services can be made private in 3.3, it would be too bad to miss them.

@weaverryan
Copy link
Member

I also think we should reconsider this a bug fix for 3.3. "Types" are much more important in 3.3... but there's no way to get a list of them. And currently we can't even use debug:container because almost all of the types aliases are private and don't show up currently.

When I run debug:container --show-private and filter for ids that are class names, I get exactly 4. With this PR I get 36.

Would it be possible to bump this to 3.3 as a bug fix?

@fabpot
Copy link
Member

fabpot commented May 3, 2017

Thank you @chalasr.

@fabpot fabpot merged commit 883723e into symfony:master May 3, 2017
fabpot added a commit that referenced this pull request May 3, 2017
…ntainer (chalasr)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[DX][FrameworkBundle] Show private aliases in debug:container

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #16388 Haehnchen/idea-php-symfony2-plugin#618
| License       | MIT
| Doc PR        | n/a

By building and compiling the container without `TYPE_REMOVING` passes, private aliases are available (shown when `--show-private` is passed). The ContainerBuilderDebugDumpPass now makes use of the ConfigCache component, removing the need for clearing the cache to get the debug:container output up to date (in sync with latest config).

Config
-------

```yaml
services:
    AppBundle\Foo:
        public: false

    foo_consumer1:
        class: AppBundle\Foo
        arguments: [ '@appbundle\Foo' ]

    foo_consumer2:
        class: AppBundle\Foo
        arguments: [ '@appbundle\Foo' ]

    foo_alias:
        alias: AppBundle\Foo

    foo_private_alias:
        public: false
        alias: AppBundle\Foo
```

Before
-------

![before](http://image.prntscr.com/image/2a69485a4a764316a90260b4e3dfc2a2.png)

After
------

![after](http://image.prntscr.com/image/ea42daa0e5c94841a28dd256450dc8ef.png)

Commits
-------

883723e Show private aliases in debug:container
@chalasr chalasr deleted the debug-container-privates branch May 3, 2017 19:27
fabpot added a commit that referenced this pull request May 4, 2017
This PR was squashed before being merged into the 3.3-dev branch (closes #22624).

Discussion
----------

debug:container --types (classes/interfaces)

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | none, but needed in symfony/symfony-docs#7807
| License       | MIT
| Doc PR        | n/a

In Symfony 3.3, the *type* (i.e. class/interface) is the most important thing about a service. But, we don't have a way for the user to know *what* types are available. This builds on top of `debug:container` to make `debug:container --types`:

<img width="1272" alt="screen shot 2017-05-03 at 3 42 37 pm" src="https://cloud.githubusercontent.com/assets/121003/25678671/8bebacaa-3018-11e7-9cf6-b7654e2cae88.png">

I think we need this for 3.3, so I've made the diff as *small* as possible. We could make improvements for 3.4, but just *having* this is the most important. I could even remove `format` support to make the diff smaller.

~~This depends on #22385, which fixes a "bug" where private services aren't really shown.~~

Thanks!

Commits
-------

25a39c2 debug:container --types (classes/interfaces)
@fabpot fabpot mentioned this pull request May 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Deprecation 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.

8 participants