/**
  * @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);
 }
Example #2
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();
 }
Example #3
0
 /**
  * Runs a student's solution by invoking PHP via the `php-cgi` binary, populating all the super globals with
  * the information from the request objects returned from the exercise. The exercise can return multiple
  * requests so the solution will be invoked for however many requests there are.
  *
  * Running only runs the student's solution, the reference solution is not run and no verification is performed,
  * the output of the student's solution is written directly to the output.
  *
  * Events dispatched (for each request):
  *
  * * cgi.run.student-execute.pre
  * * cgi.run.student.executing
  *
  * @param string $fileName The absolute path to the student's solution.
  * @param OutputInterface $output A wrapper around STDOUT.
  * @return bool If the solution was successfully executed, eg. exit code was 0.
  */
 public function run($fileName, OutputInterface $output)
 {
     $success = true;
     foreach ($this->exercise->getRequests() as $i => $request) {
         $event = $this->eventDispatcher->dispatch(new CgiExecuteEvent('cgi.run.student-execute.pre', $request));
         $process = $this->getProcess($fileName, $event->getRequest());
         $output->writeTitle("Request");
         $output->emptyLine();
         $output->writeRequest($request);
         $output->writeTitle("Output");
         $output->emptyLine();
         $process->start();
         $this->eventDispatcher->dispatch(new CgiExecuteEvent('cgi.run.student.executing', $request, ['output' => $output]));
         $process->wait(function ($outputType, $outputBuffer) use($output) {
             $output->write($outputBuffer);
         });
         $output->emptyLine();
         if (!$process->isSuccessful()) {
             $success = false;
         }
         $output->lineBreak();
     }
     return $success;
 }
Example #4
0
 /**
  * Runs a student's solution by invoking PHP via the `php-cgi` binary, populating all the super globals with
  * the information from the request objects returned from the exercise. The exercise can return multiple
  * requests so the solution will be invoked for however many requests there are.
  *
  * Running only runs the student's solution, the reference solution is not run and no verification is performed,
  * the output of the student's solution is written directly to the output.
  *
  * Events dispatched (for each request):
  *
  * * cgi.run.student-execute.pre
  * * cgi.run.student.executing
  *
  * @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)
 {
     $this->eventDispatcher->dispatch(new ExerciseRunnerEvent('cgi.run.start', $this->exercise, $input));
     $success = true;
     foreach ($this->exercise->getRequests() as $i => $request) {
         $event = $this->eventDispatcher->dispatch(new CgiExecuteEvent('cgi.run.student-execute.pre', $request));
         $process = $this->getProcess($input->getArgument('program'), $event->getRequest());
         $output->writeTitle("Request");
         $output->emptyLine();
         $output->write($this->requestRenderer->renderRequest($request));
         $output->writeTitle("Output");
         $output->emptyLine();
         $process->start();
         $this->eventDispatcher->dispatch(new CgiExecuteEvent('cgi.run.student.executing', $request, ['output' => $output]));
         $process->wait(function ($outputType, $outputBuffer) use($output) {
             $output->write($outputBuffer);
         });
         $output->emptyLine();
         if (!$process->isSuccessful()) {
             $success = false;
         }
         $output->lineBreak();
     }
     $this->eventDispatcher->dispatch(new ExerciseRunnerEvent('cgi.run.finish', $this->exercise, $input));
     return $success;
 }
Example #5
0
 /**
  * Runs a student's solution by invoking PHP from the CLI passing the arguments gathered from the exercise
  * as command line arguments to PHP.
  *
  * Running only runs the student's solution, the reference solution is not run and no verification is performed,
  * the output of the student's solution is written directly to the output.
  *
  * Events dispatched:
  *
  *  * cli.run.student-execute.pre
  *  * cli.run.student.executing
  *
  * @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)
 {
     $this->eventDispatcher->dispatch(new ExerciseRunnerEvent('cli.run.start', $this->exercise, $input));
     $success = true;
     foreach ($this->preserveOldArgFormat($this->exercise->getArgs()) as $i => $args) {
         /** @var CliExecuteEvent $event */
         $event = $this->eventDispatcher->dispatch(new CliExecuteEvent('cli.run.student-execute.pre', new ArrayObject($args)));
         $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($input->getArgument('program'), $args);
         $process->start();
         $this->eventDispatcher->dispatch(new CliExecuteEvent('cli.run.student.executing', $args, ['output' => $output]));
         $process->wait(function ($outputType, $outputBuffer) use($output) {
             $output->write($outputBuffer);
         });
         $output->emptyLine();
         if (!$process->isSuccessful()) {
             $success = false;
         }
         $output->lineBreak();
     }
     $this->eventDispatcher->dispatch(new ExerciseRunnerEvent('cli.run.finish', $this->exercise, $input));
     return $success;
 }
Example #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();
 }