8000 [DependencyInjection] Fix duplication of placeholders by mickadoo · Pull Request #20199 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[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
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[DependencyInjection] Changes from code review in how placeholders ar…
…e merged and set
  • Loading branch information
mickadoo committed Oct 11, 2016
commit a0373ba5e95a6baff38626b164c34a2b3cbdfa69
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

current()?

Copy link
Member

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

return $placeholder; // return first result
}
}
if (preg_match('/\W/', $env)) {
throw new InvalidArgumentException(sprintf('Invalid %s name: only "word" characters are allowed.', $name));
Expand All @@ -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);
Expand All @@ -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(
Copy link
Member

Choose a reason for hiding this comment

The 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())
);
}
}
0