From 8253dad043863e461a596d37a935dc4fba927cca Mon Sep 17 00:00:00 2001 From: Remi Collin Date: Fri, 22 Sep 2017 08:49:26 +0200 Subject: [PATCH 1/4] Improve PSR-11 has() method to return true on resolvable concrete classes --- src/Illuminate/Container/Container.php | 36 +++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/src/Illuminate/Container/Container.php b/src/Illuminate/Container/Container.php index 54d10354876a..9deafd7db714 100755 --- a/src/Illuminate/Container/Container.php +++ b/src/Illuminate/Container/Container.php @@ -160,7 +160,35 @@ public function bound($abstract) */ public function has($id) { - return $this->bound($id); + return $this->bound($id) || $this->isResolvable($id); + } + + /** + * Determine if a given class exist and can be instantiated + * + * @param string $concrete + * @return boolean + */ + protected function isResolvable($concrete) + { + if(! class_exists($concrete) && ! interface_exists($concrete)) { + return false; + } + + return $this->isInstantiable($concrete); + } + + /** + * Determine if the given abstract is instantiable + * + * @param string $concrete + * @return bool + */ + protected function isInstantiable($concrete) + { + $reflector = new ReflectionClass($concrete); + + return $reflector->isInstantiable(); } /** @@ -749,17 +777,17 @@ public function build($concrete) return $concrete($this, $this->getLastParameterOverride()); } - $reflector = new ReflectionClass($concrete); - // If the type is not instantiable, the developer is attempting to resolve // an abstract type such as an Interface of Abstract Class and there is // no binding registered for the abstractions so we need to bail out. - if (! $reflector->isInstantiable()) { + if (! $this->isInstantiable($concrete)) { return $this->notInstantiable($concrete); } $this->buildStack[] = $concrete; + $reflector = new ReflectionClass($concrete); + $constructor = $reflector->getConstructor(); // If there are no constructors, that means there are no dependencies then From 751e84254f613f5c11db66bd48726976eec0b9f0 Mon Sep 17 00:00:00 2001 From: Remi Collin Date: Fri, 22 Sep 2017 09:16:26 +0200 Subject: [PATCH 2/4] Style fixes --- src/Illuminate/Container/Container.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Illuminate/Container/Container.php b/src/Illuminate/Container/Container.php index 9deafd7db714..ce7e54814ea4 100755 --- a/src/Illuminate/Container/Container.php +++ b/src/Illuminate/Container/Container.php @@ -164,14 +164,14 @@ public function has($id) } /** - * Determine if a given class exist and can be instantiated + * Determine if a given class exist and can be instantiated. * * @param string $concrete - * @return boolean + * @return bool */ protected function isResolvable($concrete) { - if(! class_exists($concrete) && ! interface_exists($concrete)) { + if (! class_exists($concrete) && ! interface_exists($concrete)) { return false; } @@ -179,7 +179,7 @@ protected function isResolvable($concrete) } /** - * Determine if the given abstract is instantiable + * Determine if the given abstract is instantiable. * * @param string $concrete * @return bool From 61d2bcd1ddc05d0e98de8f040ba825811d73f1cd Mon Sep 17 00:00:00 2001 From: Remi Collin Date: Fri, 22 Sep 2017 09:17:33 +0200 Subject: [PATCH 3/4] Style fixes --- src/Illuminate/Container/Container.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Container/Container.php b/src/Illuminate/Container/Container.php index ce7e54814ea4..e9bc14198a3d 100755 --- a/src/Illuminate/Container/Container.php +++ b/src/Illuminate/Container/Container.php @@ -165,7 +165,7 @@ public function has($id) /** * Determine if a given class exist and can be instantiated. - * + * * @param string $concrete * @return bool */ @@ -180,9 +180,9 @@ protected function isResolvable($concrete) /** * Determine if the given abstract is instantiable. - * + * * @param string $concrete - * @return bool + * @return bool */ protected function isInstantiable($concrete) { From 4799769dce8ddf2199018f5b0365a21801715a4f Mon Sep 17 00:00:00 2001 From: Remi Collin Date: Fri, 22 Sep 2017 09:18:20 +0200 Subject: [PATCH 4/4] Style fixes --- src/Illuminate/Container/Container.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Container/Container.php b/src/Illuminate/Container/Container.php index e9bc14198a3d..3f3314e6a0c4 100755 --- a/src/Illuminate/Container/Container.php +++ b/src/Illuminate/Container/Container.php @@ -182,7 +182,7 @@ protected function isResolvable($concrete) * Determine if the given abstract is instantiable. * * @param string $concrete - * @return bool + * @return bool */ protected function isInstantiable($concrete) {