-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] Fix duplication of placeholders #20199
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1e9d875
[DependencyInjection] Fix duplication of placeholders when merging En…
mickadoo a0373ba
[DependencyInjection] Changes from code review in how placeholders ar…
mickadoo 92da498
[DependencyInjection] Changes from code review to revert unnecessary …
mickadoo 574da52
[DependencyInjection] Changes from code review to use assertCount ins…
mickadoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[DependencyInjection] Changes from code review in how placeholders ar…
…e merged and set
- Loading branch information
commit a0373ba5e95a6baff38626b164c34a2b3cbdfa69
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,9 @@ public function get($name) | |
$env = substr($name, 4, -1); | ||
|
||
if (isset($this->envPlaceholders[$env])) { | ||
return $this->envPlaceholders[$env][0]; | ||
foreach ($this->envPlaceholders[$env] as $placeholder) { | ||
return $placeholder; // return first result | ||
} | ||
} | ||
if (preg_match('/\W/', $env)) { | ||
throw new InvalidArgumentException(sprintf('Invalid %s name: only "word" characters are allowed.', $name)); | ||
|
@@ -44,7 +46,11 @@ public function get($name) | |
} | ||
} | ||
|
||
return $this->envPlaceholders[$env][] = sprintf('env_%s_%s', $env, md5($name.uniqid(mt_rand(), true))); | ||
$uniqueName = md5($name.uniqid(mt_rand(), true)); | ||
$placeholder = sprintf('env_%s_%s', $env, $uniqueName); | ||
$this->envPlaceholders[$env][$placeholder] = $placeholder; | ||
|
||
return $placeholder; | ||
} | ||
|
||
return parent::get($name); | ||
|
@@ -62,17 +68,12 @@ public function getEnvPlaceholders() | |
|
||
/** | ||
* Merges the env placeholders of another EnvPlaceholderParameterBag. | ||
* | ||
* @param EnvPlaceholderParameterBag $bag | ||
*/ | ||
public function mergeEnvPlaceholders(self $bag) | ||
{ | ||
$newPlaceholders = $bag->getEnvPlaceholders(); | ||
|
||
foreach ($newPlaceholders as $key => $newEntries) { | ||
$existingEntries = isset($this->envPlaceholders[$key]) ? $this->envPlaceholders[$key] : array(); | ||
$mergedEntries = array_merge($existingEntries, $newEntries); | ||
$this->envPlaceholders[$key] = array_unique($mergedEntries); | ||
} | ||
$this->envPlaceholders = array_map( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this change is not needed anymore: now that keys are strings, they are already unique |
||
'array_unique', | ||
array_merge_recursive($this->envPlaceholders, $bag->getEnvPlaceholders()) | ||
); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
current()
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see #20199 (comment), same applies to
current