diff --git a/src/Bean/Resource/CustomComponentsRegister.php b/src/Bean/Resource/CustomComponentsRegister.php index c728726a..3c204e9e 100644 --- a/src/Bean/Resource/CustomComponentsRegister.php +++ b/src/Bean/Resource/CustomComponentsRegister.php @@ -6,15 +6,17 @@ trait CustomComponentsRegister { /** - * Register the custom components namespace + * Register the server namespace * @author limx */ - public function registerCustomComponentsNamespace() + public function registerServerNamespace() { foreach ($this->customComponents as $ns => $componentDir) { if (is_int($ns)) { $ns = $componentDir; $componentDir = ComposerHelper::getDirByNamespace($ns); + $ns = rtrim($ns, "\\"); + $componentDir = rtrim($componentDir, "/"); } $this->componentNamespaces[] = $ns; @@ -30,4 +32,47 @@ public function registerCustomComponentsNamespace() } } } + + /** + * Register the worker namespace + * @author limx + */ + public function registerWorkerNamespace() + { + foreach ($this->customComponents as $ns => $componentDir) { + if (is_int($ns)) { + $ns = $componentDir; + $componentDir = ComposerHelper::getDirByNamespace($ns); + $ns = rtrim($ns, "\\"); + $componentDir = rtrim($componentDir, "/"); + } + + $this->componentNamespaces[] = $ns; + + if (!is_dir($componentDir)) { + continue; + } + + $scanDirs = scandir($componentDir, null); + + foreach ($scanDirs as $dir) { + if ($dir == '.' || $dir == '..') { + continue; + } + if (\in_array($dir, $this->serverScan, true)) { + continue; + } + + $scanDir = $componentDir . DS . $dir; + + if (!is_dir($scanDir)) { + $this->scanFiles[$ns][] = $scanDir; + continue; + } + $scanNs = $ns . '\\' . $dir; + + $this->scanNamespaces[$scanNs] = $scanDir; + } + } + } } \ No newline at end of file diff --git a/src/Bean/Resource/ServerAnnotationResource.php b/src/Bean/Resource/ServerAnnotationResource.php index 316367fa..1f037713 100644 --- a/src/Bean/Resource/ServerAnnotationResource.php +++ b/src/Bean/Resource/ServerAnnotationResource.php @@ -49,6 +49,6 @@ public function registerNamespace() } } - $this->registerCustomComponentsNamespace(); + $this->registerServerNamespace(); } } \ No newline at end of file diff --git a/src/Bean/Resource/WorkerAnnotationResource.php b/src/Bean/Resource/WorkerAnnotationResource.php index 53c482a4..f9b85ebb 100644 --- a/src/Bean/Resource/WorkerAnnotationResource.php +++ b/src/Bean/Resource/WorkerAnnotationResource.php @@ -70,6 +70,6 @@ public function registerNamespace() } } - $this->registerCustomComponentsNamespace(); + $this->registerWorkerNamespace(); } } diff --git a/test/config/properties/app.php b/test/config/properties/app.php index 1e3bf4db..2b2cdd17 100644 --- a/test/config/properties/app.php +++ b/test/config/properties/app.php @@ -11,6 +11,7 @@ 'version' => '1.0', 'autoInitBean' => true, 'beanScan' => [ + 'SwoftTest\\Aop' => BASE_PATH . '/Cases/Aop', 'SwoftTest\\Bean' => BASE_PATH . '/Cases/Bean', 'SwoftTest\\Pool' => BASE_PATH . '/Cases/Pool', ], @@ -18,7 +19,6 @@ 'env' => 'Base', 'components' => [ 'custom' => [ - 'SwoftTest' => BASE_PATH . '/Cases', 'SwoftTest' ] ],