/** * Prompts the user to answer a question * * @param IQuestion $question The question to ask * @param IResponse $response The response to write output to * @return mixed The user's answer to the question * @throws RuntimeException Thrown if we failed to get the user's answer */ public function ask(IQuestion $question, IResponse $response) { $response->write("<question>{$question->getText()}</question>"); if ($question instanceof MultipleChoice) { /** @var MultipleChoice $question */ $response->writeln(""); $choicesAreAssociative = $question->choicesAreAssociative(); $choiceTexts = []; foreach ($question->getChoices() as $key => $choice) { if (!$choicesAreAssociative) { // Make the choice 1-indexed $key += 1; } $choiceTexts[] = [$key . ")", $choice]; } $response->writeln($this->paddingFormatter->format($choiceTexts, function ($row) { return " {$row[0]} {$row[1]}"; })); $response->write($question->getAnswerLineString()); } $answer = fgets($this->inputStream, 4096); if ($answer === false) { throw new RuntimeException("Failed to get answer"); } $answer = trim($answer); if (mb_strlen($answer) == 0) { $answer = $question->getDefaultAnswer(); } return $question->formatAnswer($answer); }
/** * @inheritdoc */ protected function doExecute(IResponse $response) { // Compile the template $compiledTemplate = self::$template; $compiledTemplate = str_replace("{{version}}", $this->applicationVersion, $compiledTemplate); $response->writeln($compiledTemplate); }
/** * @inheritdoc */ protected function doExecute(IResponse $response) { $key = $this->strings->generateRandomString(32); $environmentConfigPath = $this->paths["config"] . "/environment/.env.app.php"; if (!$this->optionIsSet("show") && file_exists($environmentConfigPath)) { $contents = file_get_contents($environmentConfigPath); $newContents = preg_replace("/\"ENCRYPTION_KEY\",\\s*\"[^\"]*\"/U", '"ENCRYPTION_KEY", "' . $key . '"', $contents); file_put_contents($environmentConfigPath, $newContents); } $response->writeln("Generated key: <info>{$key}</info>"); }
/** * @inheritdoc */ protected function doExecute(IResponse $response) { $fullyQualifiedClassName = $this->composer->getFullyQualifiedClassName($this->getArgumentValue("class"), $this->getDefaultNamespace($this->composer->getRootNamespace())); $path = $this->composer->getClassPath($fullyQualifiedClassName); if ($this->fileSystem->exists($path)) { $response->writeln("<error>File already exists</error>"); return StatusCodes::ERROR; } $this->makeDirectories($path); $compiledTemplate = $this->compile($this->fileSystem->read($this->getFileTemplatePath()), $fullyQualifiedClassName); $this->fileSystem->write($path, $compiledTemplate); $response->writeln("<success>File was created</success>"); return StatusCodes::OK; }
/** * @inheritdoc */ protected function doExecute(IResponse $response) { if ($this->command === null) { $response->writeln("<comment>Pass in the name of the command you'd like help with</comment>"); } else { $descriptionText = "No description"; $helpText = ""; if ($this->command->getDescription() != "") { $descriptionText = $this->command->getDescription(); } if ($this->command->getHelpText() != "") { $helpText = PHP_EOL . "<comment>Help:</comment>" . PHP_EOL . " " . $this->command->getHelpText(); } // Compile the template $compiledTemplate = self::$template; $compiledTemplate = str_replace("{{command}}", $this->commandFormatter->format($this->command), $compiledTemplate); $compiledTemplate = str_replace("{{description}}", $descriptionText, $compiledTemplate); $compiledTemplate = str_replace("{{name}}", $this->command->getName(), $compiledTemplate); $compiledTemplate = str_replace("{{arguments}}", $this->getArgumentText(), $compiledTemplate); $compiledTemplate = str_replace("{{options}}", $this->getOptionText(), $compiledTemplate); $compiledTemplate = str_replace("{{helpText}}", $helpText, $compiledTemplate); $response->writeln($compiledTemplate); } }
/** * @inheritdoc */ protected function doExecute(IResponse $response) { $this->viewCache->flush(); $response->writeln("<success>View cache flushed</success>"); }
/** * @inheritdoc */ protected function doExecute(IResponse $response) { $response->write($this->executable->update()); $this->commandCollection->call("composer:dump-autoload", $response); }
/** * Flushes the view cache * * @param IResponse $response The response to write to */ private function flushViewCache(IResponse $response) { $this->viewCache->flush(); $response->writeln("<info>View cache flushed</info>"); }
/** * @inheritdoc */ protected function doExecute(IResponse $response) { $response->writeln("<info>{$this->environment->getName()}</info>"); }
/** * @inheritdoc */ protected function doExecute(IResponse $response) { $response->write($this->executable->dumpAutoload("-o")); }