예제 #1
0
 /**
  * Run the dotenv diff
  */
 public static function run()
 {
     $output = new ConsoleOutput();
     $formatter = new FormatterHelper();
     $env = self::readFile('.env');
     $envExample = self::readFile('.env.example');
     // Check which variables are missing and which ones are extra
     $envKeys = array_keys($env);
     $envExampleKeys = array_keys($envExample);
     $missing = array_diff($envExampleKeys, $envKeys);
     $extra = array_diff($envKeys, $envExampleKeys);
     if (count($missing) > 0 || count($extra) > 0) {
         $output->writeln('');
         $warning = $formatter->formatBlock('Warning: Your .env and .env.example files are not in sync.', 'bg=blue;fg=white', true);
         $output->writeln($warning);
     }
     if (count($missing) > 0) {
         $output->writeln("\n<comment>The following variables are missing from your .env file:<comment>");
         foreach ($missing as $variable) {
             $output->writeln(sprintf('<info>%s=%s<info>', $variable, $envExample[$variable]));
         }
     }
     if (count($extra) > 0) {
         $output->writeln("\n<comment>The following variables are in your .env file but not in .env.example:<comment>");
         foreach ($extra as $variable) {
             $output->writeln(sprintf('<info>%s=%s<info>', $variable, $env[$variable]));
         }
     }
     $output->writeln('');
 }
예제 #2
0
 public function testTruncatingWithNegativeLength()
 {
     $formatter = new FormatterHelper();
     $message = 'testing truncate';
     $this->assertSame('testing tru...', $formatter->truncate($message, -5));
     $this->assertSame('...', $formatter->truncate($message, -100));
 }
 public function notify(\Exception $exception)
 {
     if (!$exception instanceof ServiceNotFoundException) {
         return;
     }
     $serviceId = $exception->getId();
     $guessedFqcn = $this->guessFqcn($serviceId);
     $definition = new Definition();
     $definition->setClass($guessedFqcn);
     $containerBuilder = new ContainerBuilder();
     $containerBuilder->addDefinitions([$serviceId => $definition]);
     $dumper = new YamlDumper($containerBuilder);
     $result = $dumper->dump();
     $message = sprintf('Service `%s` missing. Define it in your services.yml:', $serviceId);
     $this->output->writeln('--- ' . $message . PHP_EOL);
     $this->output->write($result, true);
     $errorMessages = ['Service ' . $serviceId . ' was not found.'];
     $formatter = new FormatterHelper();
     $formattedBlock = $formatter->formatBlock($errorMessages, 'error', true);
     $this->output->writeln('');
     $this->output->writeln($formattedBlock);
     $this->output->writeln('');
     $question = sprintf('<question>Do you want to create a specification for %s? (Y/n)</question>', $guessedFqcn);
     $dialog = new DialogHelper();
     if ($dialog->askConfirmation($this->output, $question, true)) {
         $this->specRunner->runDescCommand($guessedFqcn);
     }
 }
예제 #4
0
 public function testFormatBlock()
 {
     $formatter = new FormatterHelper();
     $this->assertEquals('<error> Some text to display </error>', $formatter->formatBlock('Some text to display', 'error'), '::formatBlock() formats a message in a block');
     $this->assertEquals("<error> Some text to display </error>\n<error> foo bar              </error>", $formatter->formatBlock(array('Some text to display', 'foo bar'), 'error'), '::formatBlock() formats a message in a block');
     $this->assertEquals("<error>                        </error>\n<error>  Some text to display  </error>\n<error>                        </error>", $formatter->formatBlock('Some text to display', 'error', true), '::formatBlock() formats a message in a block');
 }
예제 #5
0
 public function testFormatBlockWithDiacriticLetters()
 {
     if (!extension_loaded('mbstring')) {
         $this->markTestSkipped('This test requires mbstring to work.');
     }
     $formatter = new FormatterHelper();
     $this->assertEquals('<error>                       </error>' . "\n" . '<error>  Du texte à afficher  </error>' . "\n" . '<error>                       </error>', $formatter->formatBlock('Du texte à afficher', 'error', true), '::formatBlock() formats a message in a block');
 }
예제 #6
0
 protected function executeWithBlueprint(Blueprint $blueprint, InputInterface $input, OutputInterface $output)
 {
     $blueprintAction = new BlueprintAction($blueprint, $this->profileManager, $output);
     $blueprintAction->validateTemplate();
     // will throw an exception if there's a problem
     $formatter = new FormatterHelper();
     $formattedBlock = $formatter->formatBlock(['No validation errors found.'], 'info', true);
     $output->writeln("\n\n{$formattedBlock}\n\n");
 }
예제 #7
0
 protected function executeWithStack(Stack $stack, InputInterface $input, OutputInterface $output)
 {
     $blueprint = $this->blueprintFactory->getBlueprintByStack($stack);
     $diff = new Diff($output);
     $diff->setStack($stack)->setBlueprint($blueprint);
     $formatter = new FormatterHelper();
     $output->writeln("\n" . $formatter->formatBlock(['Parameters:'], 'error', true) . "\n");
     $diff->diffParameters();
     $output->writeln("\n" . $formatter->formatBlock(['Template:'], 'error', true) . "\n");
     $diff->diffTemplates();
 }
 public static function format(ConstraintViolationList $problems, GeneratorInterface $generator, FormatterHelper $formatter)
 {
     $messages = [];
     // add header message
     $problemCount = count($problems);
     $name = $generator->getName();
     $messages[] = "While trying to call the generator '{$name}', {$problemCount} problems were found:";
     $messages[] = "";
     /** @var ConstraintViolation $problem */
     foreach ($problems as $problem) {
         $messages[] = "In \$arguments{$problem->getPropertyPath()}: {$problem->getMessage()}";
     }
     return $formatter->formatBlock($messages, 'error', true);
 }
예제 #9
0
 /**
  * {@inheritdoc}
  */
 public function log($level, $message, array $context = [])
 {
     if (!array_key_exists($level, $this->formats)) {
         return;
     }
     $string = \Spiral\interpolate($message, $context);
     if (!empty($this->formats[$level])) {
         //Formatting string
         $string = \Spiral\interpolate('<{format}>{string}</{format}>', ['string' => $string, 'format' => $this->formats[$level]]);
     }
     if (!empty($this->section) && !empty($this->formatter)) {
         $string = $this->formatter->formatSection($this->section, $string);
     }
     $this->output->writeln($string);
 }
예제 #10
0
 /**
  * Print a debugging message out in a big red block
  *
  * @param $string
  */
 protected function printErrorBlock($string)
 {
     if ($this->formatterHelper === null) {
         $this->formatterHelper = new FormatterHelper();
     }
     $output = $this->formatterHelper->formatBlock($string, 'bg=red;fg=white', true);
     $this->printDebug($output);
 }
예제 #11
0
 /**
  * Sets up suite for a test.
  *
  * @param Environment $env
  * @param SpecificationIterator $iterator
  * @param Boolean $skip
  *
  * @return Setup
  */
 public function setUp(Environment $env, SpecificationIterator $iterator, $skip)
 {
     spl_autoload_register(function ($class) {
         $errorMessages = [$class . ' was not found.'];
         $formatter = new FormatterHelper();
         $formattedBlock = $formatter->formatBlock($errorMessages, 'error', true);
         $this->output->writeln('');
         $this->output->writeln($formattedBlock);
         $this->output->writeln('');
         $question = sprintf('Do you want to create a specification for %s? (Y/n)', $class);
         $questionBlock = $formatter->formatBlock($question, 'question', true);
         $dialog = new DialogHelper();
         if ($dialog->askConfirmation($this->output, $questionBlock, true)) {
             $this->output->writeln('');
             $this->specRunner->runDescCommand($class);
         }
     }, true, false);
     return $this->baseTester->setUp($env, $iterator, $skip);
 }
 public function renderErrors(Suite $suite)
 {
     $this->renderSuite($suite);
     if (true === $suite->isSuccessful()) {
         return;
     }
     $formatter = new FormatterHelper();
     foreach ($suite->getTests() as $test) {
         if (true === $test->isSuccessful()) {
             continue;
         }
         $this->output->writeln('');
         $lines = [$test];
         if (false === empty($test->getErrorOutput())) {
             $lines[] = '';
             $lines[] = $test->getErrorOutput();
         }
         $this->output->writeln($formatter->formatBlock($lines, 'error', true));
     }
 }
예제 #13
0
 /**
  * @return bool
  */
 private function changeUser()
 {
     $user = $this->container->getConfig()->get('command.user');
     // Bypass cache commands as we need the sudoer user to run the commands
     if (null !== $user && (!isset($_SERVER['argv'][1]) || $_SERVER['argv'][1] !== 'flushall') && (!isset($_SERVER['argv'][1]) || $_SERVER['argv'][1] !== 'redis:flushall') && (!isset($_SERVER['argv'][1]) || $_SERVER['argv'][1] !== 'apc:flushall')) {
         $name = $user;
         $user = posix_getpwnam($user);
         posix_setgid($user['gid']);
         posix_setuid($user['uid']);
         if (posix_geteuid() !== (int) $user['uid']) {
             $output = new ConsoleOutput();
             $formatter = new FormatterHelper();
             $output->writeln('', true);
             $errorMessages = array('', ' [Error] ', ' Could not change user to ' . $name . ' ', '');
             $formattedBlock = $formatter->formatBlock($errorMessages, 'error');
             $output->writeln($formattedBlock);
             $output->writeln('', true);
             return false;
         }
     }
     return true;
 }
 /**
  * Search for dependencies in this package.
  *
  * @param PackageInterface $package  The package to search in.
  * @param string           $type     One of "prod" or "dev".
  * @param array|Link[]     $requires The require links.
  *
  * @return void
  */
 private function searchInRequires(PackageInterface $package, $type, array $requires)
 {
     if (isset($requires[$this->packageName])) {
         $link = $requires[$this->packageName];
         $constraint = $link->getPrettyConstraint();
         $section = $package->getPrettyString();
         $message = sprintf('<comment>%s</comment> %s %s', 'dev' == $type ? 'require-dev' : 'require', $this->packageName, $constraint);
         $this->progress->clear();
         // Hack to get the cursor on the line beginning
         $this->output->write("\n");
         $this->output->writeln($this->formatter->formatSection($section, $message));
         $this->progress->display();
     }
 }
예제 #15
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  *
  * @return int
  */
 public function doRun(InputInterface $input, OutputInterface $output)
 {
     $output->writeln(self::$logo);
     if (0 === count($this->files)) {
         $output->writeln('<info>No files given to check.</info>');
         return 0;
     }
     /* @var $command \Symfony\Component\Console\Command\Command */
     foreach ($this->getDefaultCommands() as $command) {
         if (false === $this->configuration[$command->getName()]['enabled']) {
             continue;
         }
         try {
             $command->run($input, $output);
         } catch (\Exception $e) {
             $formattedBlock = $this->formatter->formatBlock($e->getMessage(), 'error');
             $output->writeln($formattedBlock);
             return 1;
         }
     }
     $output->writeln('<info>Well done!</info>');
     return 0;
 }
예제 #16
0
 public function testGet()
 {
     $application = new Application();
     $command = new \TestCommand();
     $command->setApplication($application);
     $formatterHelper = new FormatterHelper();
     $this->assertEquals($formatterHelper->getName(), $command->getHelper('formatter')->getName(), '->__get() returns the correct helper');
 }
예제 #17
0
 /**
  * Finish current licenser process log and display results in the output.
  */
 public function finishProcess()
 {
     $total = $this->countTotal();
     $additions = $this->countAdditions();
     $updates = $this->countUpdates();
     $untouched = $this->countUntouched();
     $formatter = new FormatterHelper();
     //summary
     $this->output->writeln('', OutputInterface::VERBOSITY_VERBOSE);
     $this->output->writeln(sprintf('<fg=green>[+] Additions: %s</>', $additions), OutputInterface::VERBOSITY_VERBOSE);
     $this->output->writeln(sprintf('<fg=cyan>[u] Updates: %s</>', $updates), OutputInterface::VERBOSITY_VERBOSE);
     $this->output->writeln(sprintf('<fg=yellow>[=] Untouched: %s</>', $untouched), OutputInterface::VERBOSITY_VERBOSE);
     $this->output->writeln('');
     if ($this->watch->isStarted('licenser')) {
         $event = $this->watch->stop('licenser');
         $processMessage = sprintf('%s file(s) has been processed in %s ms, memory usage %.2F MiB', $total, $event->getDuration(), $event->getMemory() / 1024 / 1024);
         if ($this->mode & Licenser::MODE_NORMAL || $this->mode & Licenser::MODE_DRY_RUN) {
             $style = new OutputFormatterStyle('white', $this->mode === Licenser::MODE_DRY_RUN ? 'cyan' : 'green', ['bold']);
             $this->output->getFormatter()->setStyle('success', $style);
             $formattedBlock = $formatter->formatBlock($processMessage, 'success', true);
             $this->output->writeln($formattedBlock);
         } elseif ($this->mode & Licenser::MODE_CHECK_ONLY) {
             $needUpdate = $additions + $updates > 0;
             if ($needUpdate) {
                 $successMsg = sprintf('[WARN] %s file(s) should be updated.', $additions + $updates);
             } else {
                 $successMsg = '[OK] All files contains a valid license header.';
             }
             $style = new OutputFormatterStyle('white', $needUpdate ? 'red' : 'green', ['bold']);
             $this->output->getFormatter()->setStyle('success', $style);
             $formattedBlock = $formatter->formatBlock([$successMsg, $processMessage], 'success', true);
             $this->output->writeln($formattedBlock);
         }
         if ($this->mode === Licenser::MODE_DRY_RUN) {
             $this->output->writeln('');
             $this->output->writeln('<fg=yellow>NOTE: The command run in dry-run mode, it not made any changes.</>');
         }
     }
 }
예제 #18
0
파일: Console.php 프로젝트: wouterj/docbot
 private function outputBlock($message, $success = true)
 {
     $color = $success ? 'green' : 'red';
     $message = ($success ? '[OK]' : '[ERROR]') . ' ' . $message;
     $this->output->writeln($this->formatterHelper->formatBlock($message, 'bg=' . $color, true));
 }
예제 #19
0
 public function testFormatBlockLGEscaping()
 {
     $formatter = new FormatterHelper();
     $this->assertEquals('<error>                            </error>' . "\n" . '<error>  \\<info>some info\\</info>  </error>' . "\n" . '<error>                            </error>', $formatter->formatBlock('<info>some info</info>', 'error', true), '::formatBlock() escapes \'<\' chars');
 }
예제 #20
0
 /**
  * A wrapper around symfony's formatter helper to output a block.
  *
  * @param  string|array $messages Messages to output
  * @param  string       $type     The type of message to output
  * @return void
  */
 protected function block($messages, $type = 'error')
 {
     $output = [];
     if (!is_array($messages)) {
         $messages = (array) $messages;
     }
     $output[] = '';
     foreach ($messages as $message) {
         $output[] = trim($message);
     }
     $output[] = '';
     $formatter = new FormatterHelper();
     $this->line($formatter->formatBlock($output, $type));
 }
예제 #21
0
 /**
  * @param $lastStatus
  */
 protected function printStatus($lastStatus)
 {
     $formatter = new FormatterHelper();
     $formattedBlock = $this->isSuccessfulStatus($lastStatus) ? $formatter->formatBlock(['Completed', 'Last Status: ' . $lastStatus], 'info', true) : $formatter->formatBlock(['Error!', 'Last Status: ' . $lastStatus], 'error', true);
     $this->output->writeln("\n\n{$formattedBlock}\n\n");
 }
 /**
  * {@inheritdoc}
  */
 public function writeTitle($name)
 {
     $formatter = new FormatterHelper();
     $formattedBlock = $formatter->formatBlock([$name], 'info');
     $this->output->writeln($formattedBlock);
 }
예제 #23
0
    private function showHelp(OutputInterface $output, FormatterHelper $formatter)
    {
        $help = <<<HELP
To exit, type 'exit'.

# Selectors
My\\Entity(1)
My\\Entity being the class name of the entity, 1 being the ID of the entity to load.

# Property access
Article(1).title
Article(1).author.name
HELP;
        $output->writeln($formatter->formatBlock($help, 'info'));
    }
예제 #24
0
파일: Output.php 프로젝트: liip/rmt
 public function writeTitle($title, $large = true)
 {
     $this->writeEmptyLine();
     $this->writeln($this->formatterHelper->formatBlock($title, 'title', $large));
 }
 /**
  * @param string $text
  * @param string $style
  */
 public function writeSection($text, $style = 'bg=blue;fg=white')
 {
     $formatter = new FormatterHelper();
     $this->output->writeln(['', $formatter->formatBlock($text, $style, true), '']);
 }
예제 #26
0
 /**
  * Returns the line count of the message based on the terminal width.
  *
  * @param string $message
  *
  * @return int
  */
 private function getMessageLineCount($message)
 {
     $messageLength = FormatterHelper::strlenWithoutDecoration($this->output->getFormatter(), $message);
     return ceil($messageLength / $this->getTerminalWidth());
 }