Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix/broken merging of parameter bag env placeholders#20214

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

@mickadoo
Copy link
Contributor

@mickadoomickadoo commentedOct 13, 2016
edited by nicolas-grekas
Loading

QA
Branch?"master"
Bug fix?yes
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#20213
LicenseMIT
Doc PRreference to the documentation PR, if any

In PR#20199 I made changes after review that broke the use of env variables, sorry about that - should have checked it a bit more before making the changes.

@nicolas-grekas, I know you're very busy with all that merging, but if you could take a look at this it would be great since you know most about it.

CharlyP, fl0s, LJaschinski, jvasseur, adumas37, and qboisson reacted with thumbs up emoji
@CharlyP
Copy link

Nice! Works like a charm on my project ;)

mickadoo reacted with thumbs up emoji

publicfunctionmergeEnvPlaceholders(self$bag)
{
$this->envPlaceholders =array_merge_recursive($this->envPlaceholders,$bag->getEnvPlaceholders());
$newPlaceholders =$bag->getEnvPlaceholders();

Choose a reason for hiding this comment

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

I propose keeping the above $placeholder index and use this here:

@@ -71,6 +71,12 @@ class EnvPlaceholderParameterBag extends ParameterBag      */     public function mergeEnvPlaceholders(self $bag)     {-        $this->envPlaceholders = array_merge_recursive($this->envPlaceholders, $bag->getEnvPlaceholders());+        if ($newPlaceholders = $bag->getEnvPlaceholders()) {+            $this->envPlaceholders += $newPlaceholders;++            foreach ($newPlaceholders as $env => $placeholders) {+                $this->envPlaceholders[$env] += $placeholders;+            }+        }     } }

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

@nicolas-grekas Can you maybe explain the reason for the change here a bit more, I'm not seeing it.
With$this->envPlaceholders += $newPlaceholders; you're saying merge the new into the existing, fair enough. Then it's looping through each of the new ones and merging the existing ones with it? Won't this already have been done by the first merge?

Copy link
Member

@nicolas-grekasnicolas-grekasOct 13, 2016
edited
Loading

Choose a reason for hiding this comment

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

The array is recursive, but the+ isn't. So: the 1st+ adds the new keys to the property, then+ in the foreach adds the new entries to previously existing keys.

Copy link
ContributorAuthor

@mickadoomickadooOct 13, 2016
edited
Loading

Choose a reason for hiding this comment

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

In that case why not just use a singlearray_merge then?
(edit) bad suggestion. that would not merge the individual elements from, instead just overwrite them using the second value

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

@nicolas-grekas I was trying to make a test for this but I need your input.

param bag A has placeholders:
'DB_USER' => ['env_DB_USER_1']

param bag B has placeholders:
'DB_USER' => ['env_DB_USER_1'], 'DB_HOST_1' => ['env_DB_HOST_1]

After the merge I would expect param bag A to have placeholders:
'DB_USER' => ['env_DB_USER_1'], 'DB_HOST_1' => ['env_DB_HOST_1]

right?

Now lets make things a little more interesting with param bag C which has a different unique identifier for one of the placeholders:

'DB_USER' => ['env_DB_USER_2']

So now we go and merge that into param bag A (after merging B). Do you expect:

A)'DB_USER' => ['env_DB_USER_2'], 'DB_HOST_1' => ['env_DB_HOST_1]

or

B)'DB_USER' => ['env_DB_USER_1', 'env_DB_USER_2'], 'DB_HOST_1' => ['env_DB_HOST_1]

If you're expecting B) like I am then I'll happily make your changes (which work as expected) once I reintroduce the$this->envPlaceholders[$env][$placeholder] = $placeholder; from above. If I left it without it your suggestion wouldn't work. The changes on my branch as they are now work in either case. I'm happy with both, using+= looks nice and neat.

Just let me know the decision and i'll push the changes and the new test.

Sorry for the delay, just want to be sure I get this right this time.

Choose a reason for hiding this comment

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

B) is the only right answer. We though array_merge_recursive would do it, but you proved us wrong. Now we're trying to achieve B), nothing else :)

just want to be sure I get this right this time.

I ran my proposal with your tests, so we're safe, isn't it ;)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Pushed changes, and this time Iactually tried it out on a project. I think I put too much faith in the tests last time. That or I didn't write enough tests...
Are there tests for actual retrieving of a parameter after the bag has been merged?

Choose a reason for hiding this comment

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

Are there tests for actual retrieving of a parameter after the bag has been merged?

I don't think so

@nicolas-grekas
Copy link
Member

👍

1 similar comment
@stof
Copy link
Member

👍

@nicolas-grekas
Copy link
Member

Thank you@mickadoo.

mickadoo reacted with thumbs up emoji

@mickadoomickadoo deleted the fix/broken_merging_of_parameter_bag_env_placeholders branchOctober 14, 2016 14:42
@fabpotfabpot mentioned this pull requestOct 27, 2016
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

5 participants

@mickadoo@CharlyP@nicolas-grekas@stof@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp