/** * {@inheritdoc} */ protected function execute(Input $input, Output $output) { if (null === $this->command) { $this->command = $this->getConsole()->find($input->getArgument('command_name')); } $output->describe($this->command, ['raw_text' => $input->getOption('raw')]); $this->command = null; }
/** * 向用户提问 * @param Input $input * @param Output $output * @param OutputQuestion $question * @return string */ public function ask(Input $input, Output $output, OutputQuestion $question) { if (!$input->isInteractive()) { return $question->getDefault(); } if (!$question->getValidator()) { return $this->doAsk($output, $question); } $interviewer = function () use($output, $question) { return $this->doAsk($output, $question); }; return $this->validateAttempts($interviewer, $output, $question); }
protected function execute(Input $input, Output $output) { if ($input->hasOption('config')) { $build = (include $input->getOption('config')); } else { $build = (include APP_PATH . 'build.php'); } if (empty($build)) { $output->writeln("Build Config Is Empty"); return; } \think\Build::run($build); $output->writeln("Successed"); }
protected function execute(Input $input, Output $output) { if ($input->hasOption('module')) { $module = $input->getOption('module') . DS; } else { $module = ''; } $content = '<?php ' . PHP_EOL . $this->buildCacheContent($module); if (!is_dir(RUNTIME_PATH . $module)) { @mkdir(RUNTIME_PATH . $module, 0755, true); } file_put_contents(RUNTIME_PATH . $module . 'init' . EXT, $content); $output->writeln('<info>Succeed!</info>'); }
public function run() { if (!$this->input->isInteractive()) { return $this->question->getDefault(); } if (!$this->question->getValidator()) { return $this->doAsk(); } $that = $this; $interviewer = function () use($that) { return $that->doAsk(); }; return $this->validateAttempts($interviewer); }
protected function execute(Input $input, Output $output) { $name = trim($input->getArgument('name')); $classname = $this->getClassName($name); $pathname = $this->getPathName($classname); if (is_file($pathname)) { $output->writeln('<error>' . $this->type . ' already exists!</error>'); return false; } if (!is_dir(dirname($pathname))) { mkdir(strtolower(dirname($pathname)), 0755, true); } file_put_contents($pathname, $this->buildClass($classname)); $output->writeln('<info>' . $this->type . ' created successfully.</info>'); }
protected function execute(Input $input, Output $output) { $path = $input->getOption('path') ?: RUNTIME_PATH; $files = scandir($path); if ($files) { foreach ($files as $file) { if ('.' != $file && '..' != $file && is_dir($path . $file)) { array_map('unlink', glob($path . $file . '/*.*')); } elseif (is_file($path . $file)) { unlink($path . $file); } } } $output->writeln("<info>Clear Successed</info>"); }
protected function execute(Input $input, Output $output) { if (!is_dir(RUNTIME_PATH . 'schema')) { @mkdir(RUNTIME_PATH . 'schema', 0755, true); } if ($input->hasOption('module')) { $module = $input->getOption('module'); // 读取模型 $list = scandir(APP_PATH . $module . DS . 'model'); $app = App::$namespace; foreach ($list as $file) { if ('.' == $file || '..' == $file) { continue; } $class = '\\' . $app . '\\' . $module . '\\model\\' . pathinfo($file, PATHINFO_FILENAME); $this->buildModelSchema($class); } $output->writeln('<info>Succeed!</info>'); return; } else { if ($input->hasOption('table')) { $table = $input->getOption('table'); if (!strpos($table, '.')) { $dbName = Db::getConfig('database'); } $tables[] = $table; } elseif ($input->hasOption('db')) { $dbName = $input->getOption('db'); $tables = Db::getTables($dbName); } elseif (!\think\Config::get('app_multi_module')) { $app = App::$namespace; $list = scandir(APP_PATH . 'model'); foreach ($list as $file) { if ('.' == $file || '..' == $file) { continue; } $class = '\\' . $app . '\\model\\' . pathinfo($file, PATHINFO_FILENAME); $this->buildModelSchema($class); } $output->writeln('<info>Succeed!</info>'); return; } else { $tables = Db::getTables(); } } $db = isset($dbName) ? $dbName . '.' : ''; $this->buildDataBaseSchema($tables, $db); $output->writeln('<info>Succeed!</info>'); }
/** * 获取指令的基础名称 * @param Input $input * @return string */ protected function getCommandName(Input $input) { return $input->getFirstArgument(); }
/** * {@inheritdoc} */ protected function execute(Input $input, Output $output) { $output->describe($this->getConsole(), ['raw_text' => $input->getOption('raw'), 'namespace' => $input->getArgument('namespace')]); }
protected function askQuestion(Input $input, Question $question) { $ask = new Ask($input, $this, $question); $answer = $ask->run(); if ($input->isInteractive()) { $this->newLine(); } return $answer; }
/** * 执行 * @param Input $input * @param Output $output * @return int * @throws \Exception * @see setCode() * @see execute() */ public function run(Input $input, Output $output) { $this->input = $input; $this->output = $output; $this->getSynopsis(true); $this->getSynopsis(false); $this->mergeConsoleDefinition(); try { $input->bind($this->definition); } catch (\Exception $e) { if (!$this->ignoreValidationErrors) { throw $e; } } $this->initialize($input, $output); if ($input->isInteractive()) { $this->interact($input, $output); } $input->validate(); if ($this->code) { $statusCode = call_user_func($this->code, $input, $output); } else { $statusCode = $this->execute($input, $output); } return is_numeric($statusCode) ? (int) $statusCode : 0; }
/** * {@inheritdoc} */ protected function execute(Input $input, Output $output) { $helper = new DescriptorHelper(); $helper->describe($output, $this->getConsole(), ['raw_text' => $input->getOption('raw'), 'namespace' => $input->getArgument('namespace')]); }