From 77b1e496b5466c527bb4cb1b2a59b51b3010bb07 Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole Date: Sun, 1 Sep 2013 13:17:20 +0100 Subject: [PATCH 1/5] Use isset() instead of array_key_exists(). --- src/Symfony/Component/DependencyInjection/Container.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Container.php b/src/Symfony/Component/DependencyInjection/Container.php index ab0abf316fc9a..a2f313783bde2 100644 --- a/src/Symfony/Component/DependencyInjection/Container.php +++ b/src/Symfony/Component/DependencyInjection/Container.php @@ -240,8 +240,8 @@ 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]) + || isset($this->aliases[$id]) || method_exists($this, 'get'.strtr($id, array('_' => '', '.' => '_')).'Service') ; } @@ -275,7 +275,7 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE } // re-use shared service instance if it exists - if (array_key_exists($id, $this->services)) { + if (isset($this->services[$id])) { return $this->services[$id]; } @@ -339,7 +339,7 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE */ public function initialized($id) { - return array_key_exists(strtolower($id), $this->services); + return isset($this->services[strtolower($id)]); } /** From 6b3f864419e395bd89947c2386d8e11fa853a437 Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole Date: Sun, 1 Sep 2013 14:06:53 +0100 Subject: [PATCH 2/5] Use isset() || array_key_exists() - some services can be null. --- src/Symfony/Component/DependencyInjection/Container.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Container.php b/src/Symfony/Component/DependencyInjection/Container.php index a2f313783bde2..d0a647e094193 100644 --- a/src/Symfony/Component/DependencyInjection/Container.php +++ b/src/Symfony/Component/DependencyInjection/Container.php @@ -241,6 +241,7 @@ public function has($id) $id = strtolower($id); return isset($this->services[$id]) + || array_key_exists($id, $this->services) || isset($this->aliases[$id]) || method_exists($this, 'get'.strtr($id, array('_' => '', '.' => '_')).'Service') ; @@ -275,7 +276,7 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE } // re-use shared service instance if it exists - if (isset($this->services[$id])) { + if (isset($this->services[$id]) || array_key_exists($id, $this->services)) { return $this->services[$id]; } @@ -339,7 +340,8 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE */ public function initialized($id) { - return isset($this->services[strtolower($id)]); + $id = strtolower($id); + return isset($this->services[$id]) || array_key_exists($id, $this->services); } /** From 3af72b7c10b074d912db1803b20df38d2063f758 Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole Date: Mon, 2 Sep 2013 16:15:43 +0100 Subject: [PATCH 3/5] Avoid calling strtolower() unless necessary. --- .../DependencyInjection/Container.php | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Container.php b/src/Symfony/Component/DependencyInjection/Container.php index d0a647e094193..fe845e3340b41 100644 --- a/src/Symfony/Component/DependencyInjection/Container.php +++ b/src/Symfony/Component/DependencyInjection/Container.php @@ -268,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 (isset($this->services[$id]) || 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])) { From a60ed22dbbeb4079492df70ecce2af36fd8dde1a Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole Date: Mon, 2 Sep 2013 16:24:52 +0100 Subject: [PATCH 4/5] Four spaces. --- src/Symfony/Component/DependencyInjection/Container.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Container.php b/src/Symfony/Component/DependencyInjection/Container.php index fe845e3340b41..24a7197682641 100644 --- a/src/Symfony/Component/DependencyInjection/Container.php +++ b/src/Symfony/Component/DependencyInjection/Container.php @@ -274,10 +274,10 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE // calling strotolower() unless necessary. foreach (array(FALSE, TRUE) as $strtolower) { if ($strtolower) { - $id = strtolower($id); + $id = strtolower($id); } if (isset($this->aliases[$id])) { - $id = $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)) { From c24f47a554138d8587ec73190a827108643f8f06 Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole Date: Tue, 3 Sep 2013 11:08:34 +0100 Subject: [PATCH 5/5] Lowercase constants. --- src/Symfony/Component/DependencyInjection/Container.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/DependencyInjection/Container.php b/src/Symfony/Component/DependencyInjection/Container.php index 24a7197682641..40e171b3d8191 100644 --- a/src/Symfony/Component/DependencyInjection/Container.php +++ b/src/Symfony/Component/DependencyInjection/Container.php @@ -272,7 +272,7 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE // 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) { + foreach (array(false, true) as $strtolower) { if ($strtolower) { $id = strtolower($id); } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

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:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy