/**
  * Running a custom verifying exercise does nothing. There is no program required, therefore there is nothing
  * to run.
  *
  * @param Input $input The command line arguments passed to the command.
  * @param OutputInterface $output A wrapper around STDOUT.
  * @return bool If the solution was successfully executed, eg. exit code was 0.
  */
 public function run(Input $input, OutputInterface $output)
 {
     $message = 'Nothing to run here. This exercise does not require a code solution, ';
     $message .= 'so there is nothing to execute.';
     $output->writeLine($message);
     return true;
 }
 /**
  * @return int|void
  */
 public function __invoke()
 {
     if (empty($this->coreContributors)) {
         return;
     }
     $this->output->writeLine($this->color->__invoke("PHP School is bought to you by...")->yellow()->__toString());
     $this->output->emptyLine();
     $this->writeContributors($this->coreContributors);
     if (empty($this->appContributors)) {
         return;
     }
     $this->output->emptyLine();
     $this->output->emptyLine();
     $this->output->writeLine($this->color->__invoke("This workshop is brought to you by...")->yellow()->__toString());
     $this->output->writeLine("");
     $this->writeContributors($this->appContributors);
 }
Esempio n. 3
0
 /**
  * @return void
  */
 public function __invoke()
 {
     $this->output->writeLine($this->color->__invoke('Usage')->yellow()->bold());
     $this->output->writeLine("");
     $this->output->writeLine(sprintf("  %s", $this->color->__invoke($this->appName)->green()));
     $this->output->writeLine("    Show a menu to interactively select a workshop.");
     $this->output->writeLine(sprintf("  %s print", $this->color->__invoke($this->appName)->green()));
     $this->output->writeLine("    Print the instructions for the currently selected workshop.");
     $this->output->writeLine(sprintf("  %s verify program.php", $this->color->__invoke($this->appName)->green()));
     $this->output->writeLine("    Verify your program against the expected output.");
     $this->output->writeLine(sprintf("  %s help", $this->color->__invoke($this->appName)->green()));
     $this->output->writeLine("    Show this help.");
     $this->output->writeLine(sprintf("  %s credits", $this->color->__invoke($this->appName)->green()));
     $this->output->writeLine("    Show the people who made this happen.");
     $this->output->writeLine("");
     $this->output->writeLine($this->color->__invoke('Having trouble with a PHPSchool exercise?')->yellow()->bold());
     $this->output->writeLine("");
     $this->output->writeLine("  A team of expert helper elves is eagerly waiting to assist you in");
     $this->output->writeLine("  mastering the basics of PHP, simply go to:");
     $this->output->writeLine("    https://github.com/php-school/discussions");
     $this->output->writeLine("  and add a New Issue and let us know what you're having trouble");
     $this->output->writeLine("  with. There are no dumb questions!");
     $this->output->writeLine("");
     $this->output->writeLine("  If you're looking for general help with PHP, the #php");
     $this->output->writeLine("  channel on Freenode IRC is usually a great place to find someone");
     $this->output->writeLine("  willing to help. There is also the PHP StackOverflow Chat:");
     $this->output->writeLine("    https://chat.stackoverflow.com/rooms/11/php");
     $this->output->writeLine("");
     $this->output->writeLine($this->color->__invoke('Found a bug with PHPSchool or just want to contribute?')->yellow()->bold());
     $this->output->writeLine("  The official repository for PHPSchool is:");
     $this->output->writeLine("    https://github.com/php-school/php-workshop");
     $this->output->writeLine("  Feel free to file a bug report or (preferably) a pull request.");
     $this->output->writeLine("");
 }
Esempio n. 4
0
 /**
  * @param CliMenu $menu
  */
 public function __invoke(CliMenu $menu)
 {
     $this->userStateSerializer->serialize(new UserState());
     $this->output->writeLine("Status Reset!");
 }
Esempio n. 5
0
 /**
  * @param ExerciseInterface $exercise
  * @param UserState $userState
  * @param OutputInterface $output
  */
 private function renderSuccessInformation(ExerciseInterface $exercise, UserState $userState, OutputInterface $output)
 {
     $output->emptyLine();
     $output->writeLine($this->style(" PASS!", ['green', 'bg_default', 'bold']));
     $output->emptyLine();
     $output->writeLine("Here's the official solution in case you want to compare notes:");
     $output->writeLine($this->lineBreak());
     foreach ($exercise->getSolution()->getFiles() as $file) {
         $output->writeLine($this->style($file->getRelativePath(), ['bold', 'cyan', 'underline']));
         $output->emptyLine();
         $code = $file->getContents();
         if (pathinfo($file->getRelativePath(), PATHINFO_EXTENSION) === 'php') {
             $code = $this->syntaxHighlighter->highlight($code);
         }
         //make sure there is a new line at the end
         $code = preg_replace('/\\n$/', '', $code) . "\n";
         $output->write($code);
         $output->writeLine($this->lineBreak());
     }
     $completedCount = count($userState->getCompletedExercises());
     $numExercises = $this->exerciseRepository->count();
     $output->writeLine(sprintf('You have %d challenges left.', $numExercises - $completedCount));
     $output->writeLine(sprintf('Type "%s" to show the menu.', $this->appName));
     $output->emptyLine();
 }
Esempio n. 6
0
 /**
  * @param string $fileName
  * @param OutputInterface $output
  * @return bool
  */
 public function run($fileName, OutputInterface $output)
 {
     /** @var CliExecuteEvent $event */
     $event = $this->eventDispatcher->dispatch(new CliExecuteEvent('cli.run.user-execute.pre', new ArrayObject($this->exercise->getArgs())));
     $args = $event->getArgs();
     if (count($args)) {
         $glue = max(array_map('strlen', $args->getArrayCopy())) > 30 ? "\n" : ', ';
         $output->writeTitle('Arguments');
         $output->write(implode($glue, $args->getArrayCopy()));
         $output->emptyLine();
     }
     $output->writeTitle("Output");
     $process = $this->getPhpProcess($fileName, $args);
     $process->start();
     $this->eventDispatcher->dispatch(new CliExecuteEvent('cli.run.executing', $args, ['output' => $output]));
     $process->wait(function ($outputType, $outputBuffer) use($output) {
         $output->writeLine($outputBuffer);
     });
     return $process->isSuccessful();
 }
 /**
  * @param OutputInterface $output
  * @param $string
  * @param array $style
  */
 private function fullWidthBlock(OutputInterface $output, $string, array $style)
 {
     $stringLength = mb_strlen(StringUtil::stripAnsiEscapeSequence($string));
     $stringHalfLength = $stringLength / 2;
     $widthHalfLength = ceil($this->terminal->getWidth() / 2);
     $start = ceil($widthHalfLength - $stringHalfLength);
     $output->writeLine($this->style(str_repeat(' ', $this->terminal->getWidth()), $style));
     $output->writeLine($this->style(sprintf('%s%s%s', str_repeat(' ', $start), $string, str_repeat(' ', $this->terminal->getWidth() - $stringLength - $start)), $style));
     $output->writeLine($this->style(str_repeat(' ', $this->terminal->getWidth()), $style));
 }