예제 #1
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  * @param                 $filename
  * @param                 $formatter
  */
 protected function process(InputInterface $input, OutputInterface $output, $filename, $formatter)
 {
     $language = $input->getOption('language') ? KeyLighter::get()->getLanguage($input->getOption('language')) : Language::byFilename($filename);
     if (!($source = $this->content($filename))) {
         throw new InvalidArgumentException(sprintf('Specified file %s doesn\'t exist, check if given path is correct.', $filename));
     }
     if ($output->isVerbose()) {
         $output->writeln(sprintf("Used file: <path>%s</path>, Language: <language>%s</language>, Formatter: <formatter>%s</formatter>", $filename, $language->getFQN(), get_class($formatter)));
         $verbose = new VerboseOutput($output, $input, $language, $formatter, $source);
         $formatted = $verbose->process();
     } else {
         $formatted = KeyLighter::get()->highlight($source, $language, $formatter);
     }
     if (!$input->getOption('no-output')) {
         $output->writeln($formatted);
     }
 }
예제 #2
0
 public function testByFilename()
 {
     KeyLighter::get()->register(MockGreedyLanguage::class, ['extension' => ['*.mock']]);
     $this->assertInstanceOf(MockGreedyLanguage::class, Language::byFilename('file.mock'));
 }