diff --git a/src/Symfony/Component/DependencyInjection/Container.php b/src/Symfony/Component/DependencyInjection/Container.php index ab0abf316fc9a..40e171b3d8191 100644 --- a/src/Symfony/Component/DependencyInjection/Container.php +++ b/src/Symfony/Component/DependencyInjection/Container.php @@ -240,8 +240,9 @@ public function has($id) { $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 @@ public function has($id) */ 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 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE */ 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); } /**
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: