minor #19689 [DI] Cleanup array_key_exists (ro0NL)
This PR was squashed before being merged into the 2.7 branch (closes #19689).
Discussion
----------
[DI] Cleanup array_key_exists
| Q | A
| ------------- | ---
| Branch? | 2.7
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | comma-separated list of tickets fixed by the PR, if any
| License | MIT
| Doc PR | reference to the documentation PR, if any
Investigated this a bit, and to me it looks like left-over code. `null` doesnt end up in `$this->services` by design (this was done in https://github.com/symfony/symfony/pull/8582) so it seems. The test added then for regression still passes :)
I cant believe we guarantee BC for users doing `$this->services['id'] = null` (due protected), allowing them to break the design of `has`, `get` and `initialized` right now.
This also happens for `$this->definitions` in `ContainerBuilder`, maybe because `Container` did it alteady.. but im not sure.
Then again, there's this comment: https://github.com/symfony/symfony/pull/14470#issuecomment-96268162
Commits
-------
3306c70
[DI] Cleanup array_key_exists
This commit is contained in:
commit
c89f80a9cd
@ -223,7 +223,6 @@ class Container implements IntrospectableContainerInterface
|
||||
if ('service_container' === $id
|
||||
|| isset($this->aliases[$id])
|
||||
|| isset($this->services[$id])
|
||||
|| array_key_exists($id, $this->services)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
@ -266,7 +265,7 @@ class Container implements IntrospectableContainerInterface
|
||||
$id = $this->aliases[$id];
|
||||
}
|
||||
// Re-use shared service instance if it exists.
|
||||
if (isset($this->services[$id]) || array_key_exists($id, $this->services)) {
|
||||
if (isset($this->services[$id])) {
|
||||
return $this->services[$id];
|
||||
}
|
||||
|
||||
@ -348,7 +347,7 @@ class Container implements IntrospectableContainerInterface
|
||||
$id = $this->aliases[$id];
|
||||
}
|
||||
|
||||
return isset($this->services[$id]) || array_key_exists($id, $this->services);
|
||||
return isset($this->services[$id]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -436,7 +436,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
||||
return $service;
|
||||
}
|
||||
|
||||
if (!array_key_exists($id, $this->definitions) && isset($this->aliasDefinitions[$id])) {
|
||||
if (!isset($this->definitions[$id]) && isset($this->aliasDefinitions[$id])) {
|
||||
return $this->get($this->aliasDefinitions[$id]);
|
||||
}
|
||||
|
||||
@ -784,7 +784,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
||||
*/
|
||||
public function hasDefinition($id)
|
||||
{
|
||||
return array_key_exists(strtolower($id), $this->definitions);
|
||||
return isset($this->definitions[strtolower($id)]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -800,7 +800,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
||||
{
|
||||
$id = strtolower($id);
|
||||
|
||||
if (!array_key_exists($id, $this->definitions)) {
|
||||
if (!isset($this->definitions[$id])) {
|
||||
throw new ServiceNotFoundException($id);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user