Skip to content

[DI] Turn services and aliases private by default, with BC layer #24238

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
Sep 19, 2017

Conversation

nicolas-grekas
Copy link
Member

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

With this PR, all services and aliases are made private by default.
This is done in a BC way, thanks to the layer introduced in #24104.

We will require bundles to explicitly opt-in for "public", either using "defaults", or stating public="true" explicitly. Same in DI extension, where calling ->setPublic(true) will be required in 4.0.

@@ -45,7 +46,7 @@ public function process(ContainerBuilder $container)
$aliases = array();
foreach ($container->getAliases() as $name => $target) {
$this->currentId = $name;
$aliases[$this->bag->resolveValue($name)] = $this->bag->resolveValue($target);
$aliases[$this->bag->resolveValue($name)] = (new Alias($this->bag->resolveValue((string) $target)))->setPublic($target->isPublic())->setPrivate($target->isPrivate());
Copy link
Member

Choose a reason for hiding this comment

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

was the old code actually resolving any parameter in aliases ? AFAIK, ParameterBag::resolveValue($object) is a no-op

Copy link
Member Author

Choose a reason for hiding this comment

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

was a no-op yes, so that's a bug fix (but not one we have to do on lower branches, can be seen as a new feat now, isn't it?)

Copy link
Member

Choose a reason for hiding this comment

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

well, I'm not sure we actually want to introduce this new feature here (especially not hidden inside a commit saying it turns aliases to private by default).
This should be discussed separately.

Copy link
Member

Choose a reason for hiding this comment

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

Btw, I'm sure we had several discussions in the past rejecting the addition of this feature. I don't remember whether another discussion after that decided to add it (and the implementation failed at it)

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 history, this non-working code was added before the 2.0.0 release. So this is clearly before discussions where we rejected this feature.
So you should not add a rejected feature here. I would rather remove this no-op code from the codebase

Copy link
Member Author

Choose a reason for hiding this comment

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

well, the key is still resolved, what should we do about it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Line reverted here as it's unrelated, I'll open another PR on 2.7 about this.

@nicolas-grekas
Copy link
Member Author

(failure false-positive, known composer bug)

$container->register('my.type1', __CLASS__.'_Type1')->addTag('form.type');
$container->register('my.type2', __CLASS__.'_Type2')->addTag('form.type');
$container->setDefinition('form.extension', $extDefinition->setPublic(true));
$container->register('my.type1', __CLASS__.'_Type1')->addTag('form.type')->setPublic(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

Such changes in tests cases aren't always strictly required, right? In most cases the visibility does not matter in those test cases.

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct, I did it in batch to, more fine grained would need more time...

Copy link
Member Author

Choose a reason for hiding this comment

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

Diff now reduced to the minimum.

@nicolas-grekas nicolas-grekas force-pushed the private-default branch 2 times, most recently from 6510d18 to 1fc59bc Compare September 18, 2017 14:08
@@ -25,6 +25,7 @@ public function __construct($id, $public = true)
{
$this->id = (string) $id;
$this->public = $public;
$this->private = 2 > func_num_args();
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't this be $public && 2 > func_num_args() ?

If I register an alias as private explicitly, it does not need to have the BC layer keeping it from being inlined.

Copy link
Member Author

@nicolas-grekas nicolas-grekas Sep 18, 2017

Choose a reason for hiding this comment

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

when "private" is set to true, the BC layer is enabled and triggers deprecations,
so here, we want it to be "false" when either true or false is passes.

Copy link
Member

Choose a reason for hiding this comment

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

hmm sorry, I misunderstood the condition (reading too fast).

@nicolas-grekas nicolas-grekas force-pushed the private-default branch 2 times, most recently from 2a04b39 to 57feec2 Compare September 18, 2017 15:48
@nicolas-grekas
Copy link
Member Author

Now with UPGRADE/CHANGELOG entries.

@nicolas-grekas nicolas-grekas merged commit 9948b09 into symfony:3.4 Sep 19, 2017
nicolas-grekas added a commit that referenced this pull request Sep 19, 2017
…h BC layer (nicolas-grekas)

This PR was merged into the 3.4 branch.

Discussion
----------

[DI] Turn services and aliases private by default, with BC layer

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

With this PR, all services and aliases are made private by default.
This is done in a BC way, thanks to the layer introduced in #24104.

We will require bundles to explicitly opt-in for "public", either using "defaults", or stating `public="true"` explicitly. Same in DI extension, where calling `->setPublic(true)` will be required in 4.0.

Commits
-------

9948b09 [DI] Turn services and aliases private by default, with BC layer
@nicolas-grekas nicolas-grekas deleted the private-default branch September 19, 2017 17:09
nicolas-grekas added a commit that referenced this pull request Sep 19, 2017
This PR was merged into the 3.4 branch.

Discussion
----------

[DI] Fix private-by-default BC layer

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

Spotted while merging 3.4 into master and by looking at the cross-versions CI.

Commits
-------

ff2ab58 [DI] Fix private-by-default BC layer
This was referenced Oct 18, 2017
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.

6 participants