Use isset() instead of array_key_exists() in DIC
This commit is contained in:
parent
71621d7404
commit
e4b303973f
|
@ -240,8 +240,9 @@ class Container implements IntrospectableContainerInterface
|
|||
{
|
||||
$id = strtolower($id);
|
||||
|
||||
return array_key_exists($id, $this->services)
|
||||
|| array_key_exists($id, $this->aliases)
|
||||
return isset($this->services[$id])
|
||||
|| array_key_exists($id, $this->services)
|
||||
|| isset($this->aliases[$id])
|
||||
|| method_exists($this, 'get'.strtr($id, array('_' => '', '.' => '_')).'Service')
|
||||
;
|
||||
}
|
||||
|
@ -267,16 +268,21 @@ class Container implements IntrospectableContainerInterface
|
|||
*/
|
||||
public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE)
|
||||
{
|
||||
$id = strtolower($id);
|
||||
|
||||
// resolve aliases
|
||||
if (isset($this->aliases[$id])) {
|
||||
$id = $this->aliases[$id];
|
||||
}
|
||||
|
||||
// re-use shared service instance if it exists
|
||||
if (array_key_exists($id, $this->services)) {
|
||||
return $this->services[$id];
|
||||
// Attempt to retrieve the service by checking first aliases then
|
||||
// available services. Service IDs are case insensitive, however since
|
||||
// this method can be called thousands of times during a request, avoid
|
||||
// calling strotolower() unless necessary.
|
||||
foreach (array(false, true) as $strtolower) {
|
||||
if ($strtolower) {
|
||||
$id = strtolower($id);
|
||||
}
|
||||
if (isset($this->aliases[$id])) {
|
||||
$id = $this->aliases[$id];
|
||||
}
|
||||
// Re-use shared service instance if it exists.
|
||||
if (isset($this->services[$id]) || array_key_exists($id, $this->services)) {
|
||||
return $this->services[$id];
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->loading[$id])) {
|
||||
|
@ -339,7 +345,8 @@ class Container implements IntrospectableContainerInterface
|
|||
*/
|
||||
public function initialized($id)
|
||||
{
|
||||
return array_key_exists(strtolower($id), $this->services);
|
||||
$id = strtolower($id);
|
||||
return isset($this->services[$id]) || array_key_exists($id, $this->services);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Reference in New Issue