From 951def89f5b28cbeda9db0b85ed1ac8affc0e954 Mon Sep 17 00:00:00 2001 From: Kolya1222 Date: Wed, 21 Jan 2026 17:00:29 +0700 Subject: [PATCH] create_command_create_command --- .../Console/Commands/MakeCommandCommand.php | 87 +++++++++++++++++++ core/src/Console/Commands/stubs/command.stub | 32 +++++++ core/src/Providers/ArtisanServiceProvider.php | 13 +++ 3 files changed, 132 insertions(+) create mode 100644 core/src/Console/Commands/MakeCommandCommand.php create mode 100644 core/src/Console/Commands/stubs/command.stub diff --git a/core/src/Console/Commands/MakeCommandCommand.php b/core/src/Console/Commands/MakeCommandCommand.php new file mode 100644 index 0000000000..7d2df2a5ff --- /dev/null +++ b/core/src/Console/Commands/MakeCommandCommand.php @@ -0,0 +1,87 @@ +getCleanRootNamespace(); + $name = Str::replaceFirst($rootNamespace, '', $name); + $name = ltrim($name, '\\'); + + if ($rootNamespace === 'EvolutionCMS') { + return EVO_CORE_PATH . 'src/' . str_replace('\\', '/', $name) . '.php'; + } else { + return $this->resolveCustomPath($rootNamespace, $name); + } + } + + protected function getCleanRootNamespace() + { + $evo = Core::getInstance(); + $namespace = $evo->getConfig('ControllerNamespace'); + + if (empty($namespace) || trim($namespace) === '') { + return 'EvolutionCMS'; + } + $namespace = rtrim($namespace, '\\'); + $namespace = str_replace('\Controllers', '', $namespace); + + return $namespace; + } + + protected function getDefaultNamespace($rootNamespace) + { + $cleanNamespace = $this->getCleanRootNamespace(); + return $cleanNamespace . '\Console\Commands'; + } + + protected function rootNamespace() + { + return $this->getCleanRootNamespace(); + } + + protected function resolveCustomPath($namespace, $className) + { + $parts = explode('\\', $namespace); + if (count($parts) >= 2) { + $packageName = $parts[1]; + $basePath = EVO_CORE_PATH . 'custom/packages/' . strtolower($packageName) . '/src/'; + } else { + $basePath = EVO_CORE_PATH . 'custom/commands/'; + } + $fullPath = $basePath . str_replace('\\', '/', $className) . '.php'; + $directory = dirname($fullPath); + if (!is_dir($directory)) { + mkdir($directory, 0755, true); + } + return $fullPath; + } + + protected function qualifyClass($name) + { + $name = ltrim($name, '\\/'); + $name = str_replace('/', '\\', $name); + + $rootNamespace = $this->rootNamespace(); + + if (Str::startsWith($name, $rootNamespace)) { + return $name; + } + return $this->getDefaultNamespace($rootNamespace) . '\\' . $name; + } +} \ No newline at end of file diff --git a/core/src/Console/Commands/stubs/command.stub b/core/src/Console/Commands/stubs/command.stub new file mode 100644 index 0000000000..17204f6c11 --- /dev/null +++ b/core/src/Console/Commands/stubs/command.stub @@ -0,0 +1,32 @@ + 'command.siteupdate', 'Extras' => 'command.extras', 'RouteList' => 'command.route.list', + 'CommandMake' => 'command.make.command', ]; /** @@ -428,6 +429,18 @@ protected function registerRouteListCommand() }); } + /** + * Register the command. + * + * @return void + */ + protected function registerCommandMakeCommand() + { + $this->app->singleton('command.make.command', function ($app) { + return new Console\Commands\MakeCommandCommand($app['files']); + }); + } + /** * Get the services provided by the provider. *