From f81213e1b8760741e5d11eae86d20ad85f3e3109 Mon Sep 17 00:00:00 2001 From: Tom Wright Date: Mon, 30 Oct 2023 14:36:42 +0000 Subject: [PATCH] Use interface for default resolver if instantiable Signed-off-by: Tom Wright --- CHANGELOG.md | 2 ++ src/Handler.php | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a1f2e2..dbf2131 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +* Use interface for default resolver if instantiable + ## v0.2.14 (2023-10-29) * Added default resolver interface for nameless resolution * Refactored package file structure diff --git a/src/Handler.php b/src/Handler.php index 0240d7f..7335676 100644 --- a/src/Handler.php +++ b/src/Handler.php @@ -182,6 +182,13 @@ class_exists($name) && // Make sure there's at least one resolver for interface $this->ensureResolver($interface); + if ( + $name === null && + (new ReflectionClass($interface))->isInstantiable() + ) { + $name = $interface; + } + if ($name !== null) { $name = $this->normalize($interface, $name); }