From 05568dd6c8334754f3258bd80d198753cfa84cee Mon Sep 17 00:00:00 2001 From: maximilian-walter Date: Fri, 17 Jan 2020 14:01:05 +0100 Subject: [PATCH] Bugfix for commands with a namespace If more than one class was found by including a PHP-file, the detection of the right class did not support namespaces. --- src/Core/CommandCollector.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Core/CommandCollector.php b/src/Core/CommandCollector.php index 7315c7f..160093f 100644 --- a/src/Core/CommandCollector.php +++ b/src/Core/CommandCollector.php @@ -15,6 +15,8 @@ use Composer\Repository\InstalledFilesystemRepository; use OxidEsales\Eshop\Core\Registry; use OxidEsales\Eshop\Core\Module\ModuleList; +use ReflectionClass; +use ReflectionException; use Symfony\Component\Console\Command\Command; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -275,7 +277,15 @@ private function getAllClassesFromPhpFile($pathToPhpFile) //this avoids warnings when module developer use there own command base class, that is not instantiable $name = basename($pathToPhpFile, '.php'); foreach ($newClasses as $newClass) { - if ($newClass == $name) { + // The filename does not contain the namespace of a class, so use the short-name of the class for + // comparison + try { + $newClassWithoutNamespace = (new ReflectionClass($newClass))->getShortName(); + } catch (ReflectionException $exception) { + $newClassWithoutNamespace = $newClass; + } + + if ($newClassWithoutNamespace == $name) { return [$newClass]; } }