コード例 #1
0
 /**
  * Constructor.
  *
  * @param integer $verbosity The verbosity level (self::VERBOSITY_QUIET, self::VERBOSITY_NORMAL, self::VERBOSITY_VERBOSE)
  * @param Boolean $decorated Whether to decorate messages or not (null for auto-guessing)
  */
 public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = null)
 {
     parent::__construct(fopen('php://stdout', 'w'), $verbosity, $decorated);
 }
コード例 #2
0
ファイル: Application.php プロジェクト: koolkode/console
 public function process(InputInterface $input = NULL, OutputInterface $output = NULL)
 {
     foreach ($this->commands as $namespace => $commands) {
         ksort($commands);
     }
     if ($input === NULL) {
         $input = new StreamInput(fopen('php://stdin', 'rb'));
     }
     if ($output === NULL) {
         $output = new StreamOutput(fopen('php://stdout', 'wb'), fopen('php://stderr', 'wb'));
     }
     $argv = $this->args;
     $this->interactive = empty($argv);
     if ($this->interactive) {
         $output->writeLine('');
         $output->writeLine(strtoupper($this->title));
         $output->writeLine(str_repeat('-', strlen($this->title)));
         $output->writeLine('');
         $this->listCommands($input, $output);
         $output->writeLine('');
     }
     while (true) {
         if ($this->interactive) {
             $output->write('> ');
             $this->parseInput($input->readLine(), $input);
         } else {
             $this->parseInput(implode(' ', $argv), $input);
         }
         $cmd = [$input->getArgument(0, ''), $input->getArgument(1, '')];
         if ($cmd[0] == 'exit') {
             break;
         }
         if ($cmd[0] == 'help') {
             $output->writeLine('');
             $this->listCommands($input, $output);
             $output->writeLine('');
             if ($this->interactive) {
                 continue;
             }
             break;
         }
         if ($this->interactive) {
             $output->writeLine('');
         }
         if (count($cmd) != 2 || empty($this->commands[$cmd[0]][$cmd[1]])) {
             $output->writeErrorLine('No such command: %s', implode(' ', $cmd));
             $output->writeErrorLine('');
             if ($this->interactive) {
                 continue;
             }
             break;
         }
         $command = $this->commands[$cmd[0]][$cmd[1]];
         $command->populateFields($input);
         $command->process($this, $input, $output);
         if ($this->interactive) {
             $output->writeLine('');
         } else {
             break;
         }
     }
 }
コード例 #3
0
 public function testCanGetTerminalWidth()
 {
     //
     // what happens if there is no COLUMNS set?
     //
     $outputEngine = new StreamOutput('php://stdout');
     $outputEngine->forceTty();
     // perform the test
     $this->assertFalse(getenv('COLUMNS'));
     $this->assertEquals(78, $outputEngine->getColumnsHint());
     //
     // and if we set COLUMNS to something sensible?
     //
     putenv('COLUMNS=10');
     $outputEngine = new StreamOutput('php://stdout');
     $outputEngine->forceTty();
     // perform the test
     //
     // we always leave a 2-character margin at the right hand
     // side of the screen for readability purposes
     $this->assertEquals(10, getenv('COLUMNS'));
     $this->assertEquals(8, $outputEngine->getColumnsHint());
     //
     // and if we set COLUMNS to something stupid?
     //
     putenv('COLUMNS=');
     $outputEngine = new StreamOutput('php://stdout');
     $outputEngine->forceTty();
     // perform the test
     $this->assertEquals('', getenv('COLUMNS'));
     $this->assertEquals(78, $outputEngine->getColumnsHint());
 }