Skip to content

Commit

Permalink
修改自定义组件只能扫描Aop、Command、Bootstrap三个文件的BUG (swoft-cloud/swoft-component…
Browse files Browse the repository at this point in the history
…#169)

* 过滤掉使用ComposerHelper拿到的命名空间和组件地址后面的反斜杠

* 自定义组件根据Server和Worker进行区分加载

* 修改会把单元测试类库加入到scanFiles的问题
  • Loading branch information
limingxinleo authored and huangzhhui committed Aug 9, 2018
1 parent 0b5f320 commit 525097b
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 5 deletions.
49 changes: 47 additions & 2 deletions src/Bean/Resource/CustomComponentsRegister.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
}
}
}
2 changes: 1 addition & 1 deletion src/Bean/Resource/ServerAnnotationResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ public function registerNamespace()
}
}

$this->registerCustomComponentsNamespace();
$this->registerServerNamespace();
}
}
2 changes: 1 addition & 1 deletion src/Bean/Resource/WorkerAnnotationResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ public function registerNamespace()
}
}

$this->registerCustomComponentsNamespace();
$this->registerWorkerNamespace();
}
}
2 changes: 1 addition & 1 deletion test/config/properties/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
'version' => '1.0',
'autoInitBean' => true,
'beanScan' => [
'SwoftTest\\Aop' => BASE_PATH . '/Cases/Aop',
'SwoftTest\\Bean' => BASE_PATH . '/Cases/Bean',
'SwoftTest\\Pool' => BASE_PATH . '/Cases/Pool',
],
'bootScan' => [],
'env' => 'Base',
'components' => [
'custom' => [
'SwoftTest' => BASE_PATH . '/Cases',
'SwoftTest'
]
],
Expand Down

0 comments on commit 525097b

Please sign in to comment.