| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 | 
							- <?php
 
- declare (strict_types = 1);
 
- namespace app\admin\command;
 
- // 引入框架内置类
 
- use think\console\Input;
 
- use think\console\Output;
 
- use think\console\input\Argument;
 
- use think\console\input\Option;
 
- use think\console\Command;
 
- use app\common\facade\ControllerUtils;
 
- class MakeController extends Command
 
- {
 
-     protected $type = "Model";
 
-     protected function configure()
 
-     {
 
-         $this->setName('MakeModel')
 
-             ->addArgument('name', Argument::OPTIONAL, "console name")
 
-             ->setDescription('Create a new model class');
 
-     }
 
-     protected function execute(Input $input, Output $output)
 
-     {
 
-         $name = trim($input->getArgument('name'));
 
-         $classname = $this->getClassName($name);
 
-         try {
 
-             ControllerUtils::makeModel($classname);
 
-             $output->writeln('<info>' . $this->type . ':' . $classname . ' created successfully.</info>');
 
-         } catch (\Exception $e) {
 
-             $output->writeln('<error>' . $e->getMessage() . '</error>');
 
-         }
 
-     }
 
-     protected function getClassName($name)
 
-     {
 
-         if (strpos($name, '\\') !== false) {
 
-             return $name;
 
-         }
 
-         if (strpos($name, '@')) {
 
-             [$app, $name] = explode('@', $name);
 
-         } else {
 
-             $app = '';
 
-         }
 
-         if (strpos($name, '/') !== false) {
 
-             $name = str_replace('/', '\\', $name);
 
-         }
 
-         return $this->getNamespace($app) . '\\' . $name;
 
-     }
 
-     protected function getNamespace(string $app): string
 
-     {
 
-         return 'app' . ($app ? '\\' . $app : '') . '\\controller';
 
-     }
 
- }
 
 
  |