diff --git a/src/Bean/Resource/AnnotationResource.php b/src/Bean/Resource/AnnotationResource.php index bab52f5b..2d6d72d6 100644 --- a/src/Bean/Resource/AnnotationResource.php +++ b/src/Bean/Resource/AnnotationResource.php @@ -5,8 +5,7 @@ use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\Common\Annotations\AnnotationRegistry; use Swoft\Bean\Wrapper\WrapperInterface; -use Swoft\Helper\ComponentHelper; -use Swoft\Helper\JsonHelper; +use Swoft\Helper\ComposerHelper; /** * Annotation resource @@ -189,8 +188,6 @@ public function parseAnnotationsData() } /** - * 添加扫描namespace - * * @param array $namespaces */ public function addScanNamespace(array $namespaces) @@ -200,10 +197,12 @@ public function addScanNamespace(array $namespaces) $this->scanNamespaces[$key] = $namespace; continue; } - - $nsPath = str_replace("\\", "/", $namespace); - $nsPath = str_replace('App/', 'app/', $nsPath); - $this->scanNamespaces[$namespace] = BASE_PATH . "/" . $nsPath; + $nsPath = ComposerHelper::getDirByNamespace($namespace); + if (!$nsPath) { + $nsPath = str_replace("\\", "/", $namespace); + $nsPath = BASE_PATH . "/" . $nsPath; + } + $this->scanNamespaces[$namespace] = $nsPath; } $this->registerNamespace(); diff --git a/src/Helper/ComposerHelper.php b/src/Helper/ComposerHelper.php new file mode 100644 index 00000000..9ccde34b --- /dev/null +++ b/src/Helper/ComposerHelper.php @@ -0,0 +1,68 @@ +getPrefixesPsr4(); + $maxLength = 0; + foreach ($prefixesPsr4 as $prefix => $path) { + if (StringHelper::startsWith($namespace, $prefix)) { + $strLen = strlen($prefix); + if ($strLen > $maxLength) { + $dir = current($path) . DIRECTORY_SEPARATOR . substr($namespace, $strLen); + } + } + } + return $dir; + } + +}