setName('apiadmin:autoBuild')->setDescription('ApiAdmin自动构建文件'); } protected function execute(Input $input, Output $output): void { $config = $this->parseConfig($output); (new AutoBuild())->run($config); } /** * 获取cli配置输入 * @param $output * @return array * @author zhaoxiang */ private function parseConfig($output): array { $output->comment('Do you need to build a control? 1 or 0 (default 1)'); $input = trim(fgets(fopen('php://stdin', 'r'))); $dsn['control'] = strlen($input) ? $input : 1; if ($dsn['control']) { $dsn['name'] = $this->getControlName($output); } $output->comment('Do you need to build a menu? 1 or 0 (default 1):'); $input = trim(fgets(fopen('php://stdin', 'r'))); $dsn['menu'] = strlen($input) ? $input : 1; if ($dsn['menu']) { $output->comment('Do you need to create a route? 1 or 0 (default 0):'); $input = trim(fgets(fopen('php://stdin', 'r'))); $dsn['route'] = strlen($input) ? $input : 0; } $output->comment('Do you need to build a model? 1 or 0 (default 0):'); $input = trim(fgets(fopen('php://stdin', 'r'))); $dsn['model'] = strlen($input) ? $input : 0; if ($dsn['model']) { $dsn['modelName'] = $this->getModelName($output); $output->comment('Do you need to create a table? 1 or 0 (default 0):'); $input = trim(fgets(fopen('php://stdin', 'r'))); $dsn['table'] = strlen($input) ? $input : 0; } $output->comment('please choose module (1:admin;2:api, default 1):'); $input = trim(fgets(fopen('php://stdin', 'r'))); $dsn['module'] = strlen($input) ? $input : 1; return $dsn; } /** * 递归获取控制器名称 * @param $output * @return string * @author zhaoxiang */ private function getModelName($output): string { $output->comment('Please input model name'); $input = trim(fgets(fopen('php://stdin', 'r'))); if ($input) { return $input; } else { return $this->getModelName($output); } } /** * 递归获取控制器名称 * @param $output * @return string * @author zhaoxiang */ private function getControlName($output): string { $output->comment('Please input controller name'); $input = trim(fgets(fopen('php://stdin', 'r'))); if ($input) { return $input; } else { return $this->getControlName($output); } } }