writeln() 공개 메소드

输出信息并换行
public writeln ( string $messages, integer $type = self::OUTPUT_NORMAL )
$messages string
$type integer
예제 #1
0
파일: Build.php 프로젝트: peandloc/think
 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");
 }
예제 #2
0
 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>');
 }
예제 #3
0
 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>');
 }
예제 #4
0
파일: Ask.php 프로젝트: top-think/framework
 /**
  * 显示问题的提示信息
  */
 protected function writePrompt()
 {
     $text = $this->question->getQuestion();
     $default = $this->question->getDefault();
     switch (true) {
         case null === $default:
             $text = sprintf(' <info>%s</info>:', $text);
             break;
         case $this->question instanceof Confirmation:
             $text = sprintf(' <info>%s (yes/no)</info> [<comment>%s</comment>]:', $text, $default ? 'yes' : 'no');
             break;
         case $this->question instanceof Choice && $this->question->isMultiselect():
             $choices = $this->question->getChoices();
             $default = explode(',', $default);
             foreach ($default as $key => $value) {
                 $default[$key] = $choices[trim($value)];
             }
             $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, implode(', ', $default));
             break;
         case $this->question instanceof Choice:
             $choices = $this->question->getChoices();
             $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, $choices[$default]);
             break;
         default:
             $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, $default);
     }
     $this->output->writeln($text);
     if ($this->question instanceof Choice) {
         $width = max(array_map('strlen', array_keys($this->question->getChoices())));
         foreach ($this->question->getChoices() as $key => $value) {
             $this->output->writeln(sprintf("  [<comment>%-{$width}s</comment>] %s", $key, $value));
         }
     }
     $this->output->write(' > ');
 }
예제 #5
0
    protected function execute(Input $input, Output $output)
    {
        $classmapFile = <<<EOF
<?php
/**
 * 类库映射
 */
 
return [

EOF;
        $namespacesToScan = [App::$namespace . '\\' => realpath(rtrim(APP_PATH)), 'think\\' => LIB_PATH . 'think', 'behavior\\' => LIB_PATH . 'behavior', 'traits\\' => LIB_PATH . 'traits', '' => realpath(rtrim(EXTEND_PATH))];
        krsort($namespacesToScan);
        $classMap = [];
        foreach ($namespacesToScan as $namespace => $dir) {
            if (!is_dir($dir)) {
                continue;
            }
            $namespaceFilter = $namespace === '' ? null : $namespace;
            $classMap = $this->addClassMapCode($dir, $namespaceFilter, $classMap);
        }
        ksort($classMap);
        foreach ($classMap as $class => $code) {
            $classmapFile .= '    ' . var_export($class, true) . ' => ' . $code;
        }
        $classmapFile .= "];\n";
        if (!is_dir(RUNTIME_PATH)) {
            @mkdir(RUNTIME_PATH, 0755, true);
        }
        file_put_contents(RUNTIME_PATH . 'classmap' . EXT, $classmapFile);
        $output->writeln('<info>Succeed!</info>');
    }
예제 #6
0
 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>');
 }
예제 #7
0
 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>");
 }
예제 #8
0
파일: Autoload.php 프로젝트: GDdark/cici
 protected function createMap($path, $namespace = null)
 {
     if (is_string($path)) {
         if (is_file($path)) {
             $path = [new \SplFileInfo($path)];
         } elseif (is_dir($path)) {
             $objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path), \RecursiveIteratorIterator::SELF_FIRST);
             $path = [];
             /** @var \SplFileInfo $object */
             foreach ($objects as $object) {
                 if ($object->isFile() && $object->getExtension() == 'php') {
                     $path[] = $object;
                 }
             }
         } else {
             throw new \RuntimeException('Could not scan for classes inside "' . $path . '" which does not appear to be a file nor a folder');
         }
     }
     $map = [];
     /** @var \SplFileInfo $file */
     foreach ($path as $file) {
         $filePath = $file->getRealPath();
         if (pathinfo($filePath, PATHINFO_EXTENSION) != 'php') {
             continue;
         }
         $classes = $this->findClasses($filePath);
         foreach ($classes as $class) {
             if (null !== $namespace && 0 !== strpos($class, $namespace)) {
                 continue;
             }
             if (!isset($map[$class])) {
                 $map[$class] = $filePath;
             } elseif ($map[$class] !== $filePath && !preg_match('{/(test|fixture|example|stub)s?/}i', strtr($map[$class] . ' ' . $filePath, '\\', '/'))) {
                 $this->output->writeln('<warning>Warning: Ambiguous class resolution, "' . $class . '"' . ' was found in both "' . $map[$class] . '" and "' . $filePath . '", the first will be used.</warning>');
             }
         }
     }
     return $map;
 }
예제 #9
0
파일: Console.php 프로젝트: GDdark/cici
 /**
  * 执行指令
  * @param Input $input
  * @param Output       $output
  * @return int
  */
 public function doRun(Input $input, Output $output)
 {
     if (true === $input->hasParameterOption(['--version', '-V'])) {
         $output->writeln($this->getLongVersion());
         return 0;
     }
     $name = $this->getCommandName($input);
     if (true === $input->hasParameterOption(['--help', '-h'])) {
         if (!$name) {
             $name = 'help';
             $input = new Input(['help']);
         } else {
             $this->wantHelps = true;
         }
     }
     if (!$name) {
         $name = $this->defaultCommand;
         $input = new Input([$this->defaultCommand]);
     }
     $command = $this->find($name);
     $this->runningCommand = $command;
     $exitCode = $this->doRunCommand($command, $input, $output);
     $this->runningCommand = null;
     return $exitCode;
 }
예제 #10
0
파일: Question.php 프로젝트: Lofanmi/think
 /**
  * 从用户获取隐藏的响应
  * @param Output $output
  * @return string
  * @throws \RuntimeException
  */
 private function getHiddenResponse(Output $output, $inputStream)
 {
     if ('\\' === DS) {
         $exe = __DIR__ . '/../bin/hiddeninput.exe';
         if ('phar:' === substr(__FILE__, 0, 5)) {
             $tmpExe = sys_get_temp_dir() . '/hiddeninput.exe';
             copy($exe, $tmpExe);
             $exe = $tmpExe;
         }
         $value = rtrim(shell_exec($exe));
         $output->writeln('');
         if (isset($tmpExe)) {
             unlink($tmpExe);
         }
         return $value;
     }
     if ($this->hasSttyAvailable()) {
         $sttyMode = shell_exec('stty -g');
         shell_exec('stty -echo');
         $value = fgets($inputStream, 4096);
         shell_exec(sprintf('stty %s', $sttyMode));
         if (false === $value) {
             throw new \RuntimeException('Aborted');
         }
         $value = trim($value);
         $output->writeln('');
         return $value;
     }
     if (false !== ($shell = $this->getShell())) {
         $readCmd = $shell === 'csh' ? 'set mypassword = $<' : 'read -r mypassword';
         $command = sprintf("/usr/bin/env %s -c 'stty -echo; %s; stty echo; echo \$mypassword'", $shell, $readCmd);
         $value = rtrim(shell_exec($command));
         $output->writeln('');
         return $value;
     }
     throw new \RuntimeException('Unable to hide the response.');
 }
예제 #11
0
 protected function execute(Input $input, Output $output)
 {
     file_put_contents(RUNTIME_PATH . 'route.php', $this->buildRouteCache());
     $output->writeln('<info>Succeed!</info>');
 }