示例#1
0
 /**
  * ConsoleOutput constructor.
  *
  * @param int|mixed                     $verbosity The verbosity
  * @param boolean                       $decorated If output should be decorated
  * @param OutputFormatterInterface|null $formatter Formatter
  */
 public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null)
 {
     $outputStream = 'php://stdout';
     if (!$this->hasStdoutSupport()) {
         $outputStream = 'php://output';
     }
     parent::__construct(fopen($outputStream, 'w'), $verbosity, $decorated, $formatter);
 }
示例#2
0
 /**
  * Output a string
  *
  * @param string   $message            The message
  * @param int|bool $verbosityOrNewLine Severity or whether to print a newline
  * @param bool     $newLine            Whether to print a newline
  * @param bool     $raw                If true, don't style the output
  *
  * @return void
  */
 public function output($message, $verbosityOrNewLine = OutputInterface::VERBOSITY_NORMAL, $newLine = true, $raw = false)
 {
     if (is_bool($verbosityOrNewLine)) {
         $newLine = $verbosityOrNewLine;
         $verbosityOrNewLine = OutputInterface::VERBOSITY_NORMAL;
     }
     if ($this->debugOutput) {
         $this->debugOutput->write($message, $newLine, $raw ? OutputInterface::OUTPUT_RAW : $this->outputType);
     }
     $verbosity = $this->output->getVerbosity();
     if ($verbosity !== 0 && $verbosityOrNewLine <= $verbosity) {
         $this->output->write($message, $newLine, $raw ? OutputInterface::OUTPUT_RAW : $this->outputType);
     }
 }
示例#3
0
 /**
  * Load the configuration
  *
  * @return void
  */
 protected function loadConfig()
 {
     $this->config = new Config();
     $expectedFile = 'kite.php';
     $app = null;
     $indicators = ['TYPO3' => ['typo3conf', 'Kite.php'], 'Magento' => ['app/etc', 'kite.php']];
     foreach ($indicators as $appName => $dirAndFile) {
         list($dir, $file) = $dirAndFile;
         if (is_dir($dir)) {
             $app = $appName;
             $expectedFile = $dir . '/' . $file;
             break;
         }
     }
     try {
         $this->config->loadConfigFile($expectedFile);
     } catch (\Exception $e) {
         if ($app) {
             $message = ['You appear to be in a ' . $app . ' root directory but', 'there is no kite config file at the expected', 'location (' . $expectedFile . ').'];
         } else {
             $message = ['You are either not in an application root directory or', 'you have no appropriate config file yet.', '', 'The config file path is expected to be:'];
             foreach ($indicators as $appName => $dirAndFile) {
                 $message[] = '  - "' . implode('/', $dirAndFile) . '" for ' . $appName . ' applications or';
             }
             $message[] = '  - "' . $expectedFile . '" for any other application';
         }
         $lMax = 0;
         foreach ($message as $line) {
             if (($l = strlen($line)) > $lMax) {
                 $lMax = $l;
             }
         }
         $this->output->writeln('<warning>' . str_repeat(' ', $lMax + 4) . '</warning>');
         foreach ($message as $line) {
             $line = str_pad($line, $lMax + 2);
             $this->output->writeln("<warning>  {$line}</warning>");
         }
         $this->output->writeln('<warning>' . str_repeat(' ', $lMax + 4) . '</warning>');
     }
 }
示例#4
0
 /**
  * Assert that the indention only indents when there was actual output on the
  * previous indention level
  *
  * @return void
  */
 public function testIndention()
 {
     $n = PHP_EOL;
     $expected = 'Cosmological Constant' . $n . '  Einstein, the frizzy-haired,' . $n . '  said E equals MC squared.' . $n . '  Thus all mass decreases' . $n . '  as activity ceases?' . $n . '    Not my mass, my ass declared!' . $n . '- Michael R. Burch' . $n;
     ob_start();
     $stream = fopen('php://output', 'rw');
     $output = new Output($stream);
     $output->indent();
     $output->writeln('Cosmological Constant');
     $output->indent();
     $output->writeln('Einstein, the frizzy-haired,');
     $output->writeln('said E equals MC squared.');
     $output->indent();
     $output->outdent();
     $output->writeln('Thus all mass decreases');
     $output->writeln('as activity ceases?');
     $output->indent();
     $output->indent();
     $output->writeln('Not my mass, my ass declared!');
     $output->outdent();
     $output->outdent();
     $output->outdent();
     $output->outdent();
     $output->writeln('- Michael R. Burch');
     $this->assertEquals($expected, ob_get_clean());
 }