Skip to content

Commit 12b7d21

Browse files
gladtoeatufrank
andauthored
规范应用 namespace (#130)
Co-authored-by: frank <noikiy@qq.com>
1 parent d23f28d commit 12b7d21

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/Command/CreateCommand.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ public function __invoke(): int
6060
return AbstractCommand::SUCCESS;
6161
}
6262

63+
public function createNamespace(string $path, string $name): string
64+
{
65+
$pluginPath = Str::replace(Plugin::PLUGIN_PATH . '/', '', $path);
66+
list($orgName) = explode('/', $pluginPath);
67+
return 'Plugin\\' . Str::studly($orgName) . '\\' . Str::studly($name);
68+
}
69+
6370
public function createMineJson(string $path, string $name, PluginTypeEnum $pluginType): void
6471
{
6572
$output = new \stdClass();
@@ -74,7 +81,7 @@ public function createMineJson(string $path, string $name, PluginTypeEnum $plugi
7481
],
7582
];
7683
if ($pluginType === PluginTypeEnum::Backend || $pluginType === PluginTypeEnum::Mix) {
77-
$namespace = 'Plugin\\' . ucwords(str_replace('/', '\\', Str::studly($name)));
84+
$namespace = $this->createNamespace($path, $name) ?? 'Plugin\\' . ucwords(str_replace('/', '\\', Str::studly($name)));
7885

7986
$this->createInstallScript($namespace, $path);
8087
$this->createUninstallScript($namespace, $path);

0 commit comments

Comments
 (0)