-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DI] Remove case insensitive parameter names #24052
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,8 +25,6 @@ class ParameterBag implements ParameterBagInterface | |
protected $parameters = array(); | ||
protected $resolved = false; | ||
|
||
private $normalizedNames = array(); | ||
|
||
/** | ||
* @param array $parameters An array of parameters | ||
*/ | ||
|
@@ -68,7 +66,7 @@ public function all() | |
*/ | ||
public function get($name) | ||
{ | ||
$name = $this->normalizeName($name); | ||
$name = (string) $name; | ||
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. Why these string casts? 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. Previously implied by https://github.com/symfony/symfony/blob/master/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php#L1558 leads to 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. then the dumper should be updated on the lowest branch for making it cast to string beforehand IMHO 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. why? we don't use strict types (fortunately), so casting is just fine IMHO - and is functionally similar to adding the type hint on the signature (if we could) 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. It's a matter of contract. If 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.
The thing is we used Therefor i dont think it's part of this PR, which is now merged anyway. But maybe for the sake of consistency, we could cast beforehand, where needed. And deprecate passing stringish values or just ignore the fact it was possible before, regarding end users. 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. In the past we usually rejected explicit type casts and let it be the user's responsibility to respect our API. 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. And in the past also we had to revert as bugfix because we broke things with this policy... 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. But we break BC in this case :) Technically at least, passing a stringish object actually worked as expected before. Core uses it :) So yes there's an inconsistency between Now if everywhere we'd do edit: missed comment in between, as usual :) 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. Lets just keep it. This will always be a case-by-case decision until we have type declarations. |
||
|
||
if (!array_key_exists($name, $this->parameters)) { | ||
if (!$name) { | ||
|
@@ -113,15 +111,15 @@ public function get($name) | |
*/ | ||
public function set($name, $value) | ||
{ | ||
$this->parameters[$this->normalizeName($name)] = $value; | ||
$this->parameters[(string) $name] = $value; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function has($name) | ||
{ | ||
return array_key_exists($this->normalizeName($name), $this->parameters); | ||
return array_key_exists((string) $name, $this->parameters); | ||
} | ||
|
||
/** | ||
|
@@ -131,7 +129,7 @@ public function has($name) | |
*/ | ||
public function remove($name) | ||
{ | ||
unset($this->parameters[$this->normalizeName($name)]); | ||
unset($this->parameters[(string) $name]); | ||
} | ||
|
||
/** | ||
|
@@ -208,13 +206,12 @@ public function resolveString($value, array $resolving = array()) | |
// a non-string in a parameter value | ||
if (preg_match('/^%([^%\s]+)%$/', $value, $match)) { | ||
$key = $match[1]; | ||
$lcKey = strtolower($key); // strtolower() to be removed in 4.0 | ||
|
||
if (isset($resolving[$lcKey])) { | ||
if (isset($resolving[$key])) { | ||
throw new ParameterCircularReferenceException(array_keys($resolving)); | ||
} | ||
|
||
$resolving[$lcKey] = true; | ||
$resolving[$key] = true; | ||
|
||
return $this->resolved ? $this->get($key) : $this->resolveValue($this->get($key), $resolving); | ||
} | ||
|
@@ -226,8 +223,7 @@ public function resolveString($value, array $resolving = array()) | |
} | ||
|
||
$key = $match[1]; | ||
$lcKey = strtolower($key); // strtolower() to be removed in 4.0 | ||
if (isset($resolving[$lcKey])) { | ||
if (isset($resolving[$key])) { | ||
throw new ParameterCircularReferenceException(array_keys($resolving)); | ||
} | ||
|
||
|
@@ -238,7 +234,7 @@ public function resolveString($value, array $resolving = array()) | |
} | ||
|
||
$resolved = (string) $resolved; | ||
$resolving[$lcKey] = true; | ||
$resolving[$key] = true; | ||
|
||
return $this->isResolved() ? $resolved : $this->resolveString($resolved, $resolving); | ||
}, $value); | ||
|
@@ -290,18 +286,4 @@ public function unescapeValue($value) | |
|
||
return $value; | ||
} | ||
|
||
private function normalizeName($name) | ||
{ | ||
if (isset($this->normalizedNames[$normalizedName = strtolower($name)])) { | ||
$normalizedName = $this->normalizedNames[$normalizedName]; | ||
if ((string) $name !== $normalizedName) { | ||
@trigger_error(sprintf('Parameter names will be made case sensitive in Symfony 4.0. Using "%s" instead of "%s" is deprecated since version 3.4.', $name, $normalizedName), E_USER_DEPRECATED); | ||
} | ||
} else { | ||
$normalizedName = $this->normalizedNames[$normalizedName] = (string) $name; | ||
} | ||
|
||
return $normalizedName; | ||
} | ||
} |
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.
3.4 is ok :)