Skip to content
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

[DI][FrameworkBundle] Hide service ids that start with a dot #26921

Merged
merged 1 commit into from Apr 20, 2018

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Apr 13, 2018

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? yes
Tests pass? yes
Fixed tickets #26630
License MIT
Doc PR -

Now that services are private by default, debug:container should display them by default.
In fact, the public/private concept should not trigger a difference in visibility for this command.

Instead, I propose to handle service ids that start with a dot as hidden services.

PR should be ready.

(For reference, I tried using a tag instead in #26891, but that doesn't work in practice when working on the implementation.)

@nicolas-grekas
Copy link
Member Author

ping @symfony/deciders this would be great in 4.1, the current state is clumsy.

@lyrixx
Copy link
Member

lyrixx commented Apr 20, 2018

I like the idea.

But Why did you choose a dot? I think it would be better to choose an underscore even if the meaning of a name starting with a dot in the unix FS is to hide it.

The underscore is already used in the framework (or other lib) to mean "it's internal / private". I'm thinking to _locale, _format, _controller in the routing Component, _fragment in the HttpKernel, _profiler in the DebugBundle, _default in the DIC, and many more,

@nicolas-grekas
Copy link
Member Author

Good question :)
The reason is that an underscored service name cannot be loaded by the YamlFileLoader as they are forbidden. But we have tests that dump + reload configuration to ensure this is allowed. Dumping works, but not loading, for this reason.
So then, if underscore is not allowed, it must be a dot :)

@sroze
Copy link
Contributor

sroze commented Apr 20, 2018

I really like the idea as well. And tbh, hiding things that started with . is not a new idea so it's a nice choice.

The result of the debug:container command is going to be different though, as it will now include the private services. Do we consider this as a BC-break? 🙊

@nicolas-grekas
Copy link
Member Author

nicolas-grekas commented Apr 20, 2018

Do we consider this as a BC-break?

If we were to answer yes to this question, we couldn't do any improvement to any command we publish. The answer must be no.

@lyrixx
Copy link
Member

lyrixx commented Apr 20, 2018

So then, if underscore is not allowed, it must be a dot :)

okay, go for it ;)

@@ -250,7 +255,7 @@ protected function findDefinitionsByTag(ContainerBuilder $builder, $showPrivate)
foreach ($builder->findTaggedServiceIds($tag) as $serviceId => $attributes) {
$definition = $this->resolveServiceDefinition($builder, $serviceId);

if (!$definition instanceof Definition || !$showPrivate && !$definition->isPublic()) {
if ($showHidden xor '.' === $serviceId[0] ?? null) {
Copy link
Member

Choose a reason for hiding this comment

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

Can we use parentheses here? At least I have no idea by reading the code whether xor takes precedence over ?? or vice versa.

Copy link
Member

Choose a reason for hiding this comment

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

Is this actually what we want at all? Won't we skip non hidden service now if $showHidden is true?

Copy link
Member Author

Choose a reason for hiding this comment

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

parentheses added

Copy link
Member

Choose a reason for hiding this comment

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

Can we do that in the other files too that use the same condition? :)

Copy link
Member

Choose a reason for hiding this comment

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

never mind, I was looking at an outdated diff

@nicolas-grekas
Copy link
Member Author

Won't we skip non hidden service now if $showHidden is true?

That's correct: by default, you get non-hidden services, and if you add --show-hidden, you get only non-hidden ones. Much more useful IMHO.

@nicolas-grekas nicolas-grekas modified the milestones: 4.1, 4.2 Apr 20, 2018
using the <info>--show-private</info> flag:

<info>php %command.full_name% --show-private</info>

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 add some docs about the new flag.

Copy link
Member Author

Choose a reason for hiding this comment

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

added

@fabpot
Copy link
Member

fabpot commented Apr 20, 2018

Thank you @nicolas-grekas.

@fabpot fabpot merged commit cea051e into symfony:master Apr 20, 2018
fabpot added a commit that referenced this pull request Apr 20, 2018
… a dot (nicolas-grekas)

This PR was merged into the 4.1-dev branch.

Discussion
----------

[DI][FrameworkBundle] Hide service ids that start with a dot

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | #26630
| License       | MIT
| Doc PR        | -

Now that services are private by default, `debug:container` should display them by default.
In fact, the public/private concept should not trigger a difference in visibility for this command.

Instead, I propose to handle service ids that start with a dot as hidden services.

PR should be ready.

(For reference, I tried using a tag instead in #26891, but that doesn't work in practice when working on the implementation.)

Commits
-------

cea051e [DI][FrameworkBundle] Hide service ids that start with a dot
@nicolas-grekas nicolas-grekas deleted the container.hidden branch April 25, 2018 16:41
nicolas-grekas added a commit that referenced this pull request May 4, 2018
…as-grekas)

This PR was merged into the 4.1-dev branch.

Discussion
----------

[FrameworkBundle] Hide some lock-related services

| Q             | A
| ------------- | ---
| Branch?       | 4.1
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

I don't know why, but I missed these in #26921

Commits
-------

d06d8b2 [FrameworkBundle] Hide some lock-related services
@fabpot fabpot mentioned this pull request May 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants