本文整理汇总了PHP中Illuminate\Console\Command::ask方法的典型用法代码示例。如果您正苦于以下问题:PHP Command::ask方法的具体用法?PHP Command::ask怎么用?PHP Command::ask使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Console\Command
的用法示例。
在下文中一共展示了Command::ask方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* Run the list of enquires about the configurations
*
* @return array
*/
public function run()
{
foreach ($this->fields as $configuration => $value) {
$this->configurations[$configuration] = $this->origin->ask($value['question'], $value['default']);
}
return $this->configurations;
}
示例2: loginQuestions
/**
* Questions used for login
* @return void
*/
protected function loginQuestions()
{
$login = $this->command->ask('What is the username or email of the user?');
$password = $this->command->secret('What is the password of the user? (hidden)');
$this->login = $login;
$this->password = $password;
}
示例3: handle
/**
* Handle the command.
*/
public function handle()
{
$this->data->put('DB_DRIVER', $this->command->askWithCompletion('What database driver would you like to use? [mysql, pgsql, sqlite, sqlsrv]', ['mysql', 'pgsql', 'sqlite', 'sqlsrv'], env('DB_DRIVER', 'mysql')));
$this->data->put('DB_HOST', $this->command->ask('What is the hostname of your database?', env('DB_HOST', 'localhost')));
$this->data->put('DB_DATABASE', $this->command->ask('What is the name of your database?', env('DB_DATABASE')));
$this->data->put('DB_USERNAME', $this->command->ask('Enter the username for your database connection', env('DB_USERNAME', 'root')));
$this->data->put('DB_PASSWORD', $this->command->ask('Enter the password for your database connection', env('DB_PASSWORD')));
}
示例4: handle
/**
* Handle the command.
*/
public function handle()
{
$this->data->put('ADMIN_USERNAME', $this->command->ask('Enter the desired username for the admin user', env('ADMIN_USERNAME', 'admin')));
$this->data->put('ADMIN_EMAIL', $this->command->ask('Enter the desired email for the admin user', env('ADMIN_EMAIL')));
// Validate email.
if (!filter_var($this->data->get('ADMIN_EMAIL'), FILTER_VALIDATE_EMAIL)) {
$this->command->error('You must provide a valid email for the admin.');
exit;
}
$this->data->put('ADMIN_PASSWORD', $this->command->ask('Enter the desired password for the admin user', env('ADMIN_PASSWORD')));
}
示例5: getInputFromConsole
private function getInputFromConsole()
{
$this->commandInfo('Specify fields for the model (skip id & timestamp fields, we will add it automatically)');
$this->commandInfo('Enter "exit" to finish');
$this->addPrimaryKey();
while (true) {
$fieldInputStr = $this->commandObj->ask('Field: (field_name:field_database_type)', '');
if (empty($fieldInputStr) || $fieldInputStr == false || $fieldInputStr == 'exit') {
break;
}
if (!GeneratorFieldsInputUtil::validateFieldInput($fieldInputStr)) {
$this->commandError('Invalid Input. Try again');
continue;
}
if ($this->commandType == self::$COMMAND_TYPE_SCAFFOLD or $this->commandType == self::$COMMAND_TYPE_API_SCAFFOLD) {
$htmlType = $this->commandObj->ask('Enter field html input type (text): ', 'text');
} else {
$htmlType = '';
}
$validations = $this->commandObj->ask('Enter validations: ', false);
$searchable = $this->commandObj->ask('Is Searchable (y/N): ', false);
$validations = $validations == false ? '' : $validations;
if ($searchable) {
$searchable = strtolower($searchable) == 'y' ? true : false;
}
$this->inputFields[] = GeneratorFieldsInputUtil::processFieldInput($fieldInputStr, $htmlType, $validations, ['searchable' => $searchable]);
}
$this->addTimestamps();
}
示例6: askForModelAndFields
/**
* Prompt user for model and properties and return result
*
* @return string
*/
private function askForModelAndFields()
{
$modelAndFields = $this->command->ask('Add model with its relations and fields or type "q" to quit (type info for examples) ');
if ($modelAndFields == "info") {
$this->showInformation();
$modelAndFields = $this->command->ask('Now your turn: ');
}
return $modelAndFields;
}
示例7: askForEmail
/**
* @return string
*/
private function askForEmail()
{
do {
$email = $this->command->ask('Enter your email address');
if ($email == '') {
$this->command->error('Email is required');
}
} while (!$email);
return $email;
}
示例8: renderCommandField
public function renderCommandField(Command $command)
{
while (true) {
$input = $command->ask($this->getConsoleLabel(), $this->get('default', null));
$validator = $this->getValidator($input);
if ($validator->passes()) {
return $input;
} else {
$command->error($validator->errors()->first());
}
}
}
示例9: pick_from_list
/**
* Present a list of choices to user, return choice
* @param Command $command The command requesting input
* @param array $choices List of choices
* @param int $default Default choice (1-array size), -1 to abort
* @param string $abort String to tag on end for aborting selection
* @return int -1 if abort selected, otherwise one greater than $choice index
* (in other words, choosing $choice[0] returns 1)
* @throws InvalidArgumentException If argument is invalid
*/
function pick_from_list(Command $command, $title, array $choices, $default = 0, $abort = null)
{
if ($abort) {
$choices[] = $abort;
}
$numChoices = count($choices);
if (!$numChoices) {
throw new \InvalidArgumentException("Must have at least one choice");
}
if ($default == -1 && empty($abort)) {
throw new \InvalidArgumentException('Cannot use default=-1 without $abort option');
}
if (!between($default, -1, $numChoices)) {
throw new \InvalidArgumentException("Invalid value, default={$default}");
}
$question = "Please enter a number between 1-{$numChoices}";
if ($default > 0) {
$question .= " (default is {$default})";
} elseif ($default < 0) {
$question .= " (enter to abort)";
$default = $numChoices;
}
$question .= ':';
while (1) {
$command->line('');
$command->info($title);
$command->line('');
for ($i = 0; $i < $numChoices; $i++) {
$command->line($i + 1 . ". " . $choices[$i]);
}
$command->line('');
$answer = $command->ask($question);
if ($answer == '') {
$answer = $default;
}
if (between($answer, 1, $numChoices)) {
if ($abort and $answer == $numChoices) {
$answer = -1;
}
return (int) $answer;
}
// Output wrong choice
$command->line('');
$formatter = $command->getHelperSet()->get('formatter');
$block = $formatter->formatBlock('Invalid entry!', 'error', true);
$command->line($block);
}
}
示例10: execWithOutput
public function execWithOutput(string $cmd, Command $console)
{
// Setup the file descriptors
$descriptors = [0 => ['pipe', 'w'], 1 => ['pipe', 'w'], 2 => ['pipe', 'w']];
// Start the script
$proc = proc_open($cmd, $descriptors, $pipes);
// Read the stdin
$stdin = stream_get_contents($pipes[0]);
fclose($pipes[0]);
// Read the stdout
$stdout = stream_get_contents($pipes[1]);
fclose($pipes[1]);
// Read the stderr
$stderr = stream_get_contents($pipes[2]);
fclose($pipes[2]);
// Close the script and get the return code
$return_code = proc_close($proc);
if ($stdin) {
$console->line($stdin);
}
if ($stdout) {
$console->line($stdout);
}
if ($stderr) {
$console->line($stderr);
}
if (strpos($stdout, 'continue?')) {
$console->error('A confirmation has been asked during the shell command execution.');
$console->error('Please manually execute the command "' . $cmd . '" to treat that particular case.');
return exit;
}
if ($return_code) {
$console->error('Error exit code : ' . $return_code);
if (!$console->ask('Do you want continue the script execution ? [Y/n]', true)) {
return exit;
}
}
}
示例11: recursiveCopy
/**
* Copia recurssivamente os arquivos e diretorios de um array de paths
*
* @param array $errors
* @param bool $copyAll
* @param array $rollback
* @param Command $command
* @param array $paths
*/
public static function recursiveCopy(array &$errors, &$copyAll, array &$rollback, Command $command, array $paths)
{
//loop em todos os diretorios de destino
foreach ($paths as $key => $value) {
if (!is_dir($value)) {
//Se o diretorio não existir
//Cria o diretorio que não existe
if (mkdir($value)) {
//Cria registro no rollback dizendo uma pasta foi criada
$rollback[Strings::ROLLBACK_DIR_CREATED_TAG][] = $value;
}
}
}
//Loop em todas as pastas
foreach ($paths as $key => $value) {
if (empty($errors)) {
//Se os comandos anteriores rodarem com sucesso
//Copia lista de arquivos no diretorio para variavel arquivos
$arquivos = scandir($key);
//Loop em todos os arquivos do modulo
for ($i = Constants::FIRST_FILE; $i < count($arquivos); $i++) {
if (empty($errors)) {
if (!is_dir($key . $arquivos[$i])) {
//Se os comandos anteriores rodarem com sucesso e o arquivo não for uma pasta
$explodedFileName = explode(Strings::PATH_SEPARATOR, $value . $arquivos[$i]);
$filename = $explodedFileName[count($explodedFileName) - 1];
//Verifica se o arquivo existe
if (!file_exists($value . $arquivos[$i])) {
//Cria registro no rollback dizendo que o arquivo foi copiado
$rollback[Strings::ROLLBACK_MODULE_ORDINARY_FILE_COPY_TAG][EscapeHelper::encode($value . $arquivos[$i])] = Strings::EMPTY_STRING;
//verifica se a copia ocorreu com sucesso
if (copy($key . $arquivos[$i], $value . $arquivos[$i]) == false) {
//Printa msg de erro
$errors[] = Strings::ordinaryFileCopyError($value . $arquivos[$i]);
}
} else {
if (strtoupper($filename) != strtoupper(Strings::GIT_KEEP_FILE_NAME)) {
//Caso ja exista um arquivo com o mesmo nome no diretorio de destino
//Inicializa variavel que vai receber resposta do usuario dizendo o que fazer
// com o conflito
$answer = Strings::EMPTY_STRING;
//Enquanto o usuario não devolver uma resposta valida
while ($copyAll != true && $answer != Strings::SHORT_YES && $answer != Strings::SHORT_NO && $answer != Strings::SHORT_ALL && $answer != Strings::SHORT_CANCEL) {
//Faz pergunta para o usuario de como proceder
$answer = $command->ask(Strings::replaceOrdinaryFiles($value . $arquivos[$i]), false);
}
//Se a resposta for sim, ou all
if (strtolower($answer) == Strings::SHORT_YES || strtolower($answer) == Strings::SHORT_ALL || $copyAll == true) {
//se a resposta for all
if (strtolower($answer) == Strings::SHORT_ALL) {
//seta variavel all para true
$copyAll = true;
}
//Faz backup do arquivo que será substituido
$rollback[Strings::ROLLBACK_MODULE_ORDINARY_FILE_COPY_TAG][EscapeHelper::encode($value . $arquivos[$i])] = EscapeHelper::encode(file_get_contents($value . $arquivos[$i]));
//verifica se a substituição ocorreu com sucesso
if (copy($key . $arquivos[$i], $value . $arquivos[$i]) == false) {
//Se houver erro ao copiar arquivo
//Printa msg de erro
$errors[] = Strings::ordinaryFileReplaceError($value . $arquivos[$i]);
}
} else {
if (strtolower($answer) == Strings::SHORT_CANCEL) {
//se a resposta foi cancelar
//Printa msg de erro
$errors[] = Strings::userRequestedAbort();
//break the file loop
break 2;
}
}
}
}
} else {
$newPath = [$key . $arquivos[$i] . "/" => $value . $arquivos[$i] . "/"];
self::recursiveCopy($errors, $copyAll, $rollback, $command, $newPath);
}
}
}
}
}
}
示例12: handle
/**
* Handle the command.
*/
public function handle()
{
$this->data->put('APPLICATION_NAME', $this->command->ask('Enter the name of your application', env('APPLICATION_NAME', 'Default')));
$this->data->put('APPLICATION_REFERENCE', $this->command->ask('Enter the reference slug for your application', env('APPLICATION_REFERENCE', 'default')));
$this->data->put('APPLICATION_DOMAIN', $this->command->ask('Enter the primary domain for your application', env('APPLICATION_DOMAIN', 'localhost')));
}
示例13: makeMigrationsCopies
/**
* Copia arquivos convencionais do modulo (qualquer coisa exceto migrations) para as respectivas pastas
*
* @param string $moduleType
* @param string $moduleName
* @param string $copyAll
* @param array $rollback
* @param Command $command
* @param bool $allowReplace
* @return array|bool
*/
public static function makeMigrationsCopies($moduleType, $moduleName, &$copyAll, array &$rollback, Command $command, $allowReplace = true)
{
$errors = [];
//Inicia o Rollback de arquivos copiados
$rollback[Strings::ROLLBACK_MODULE_MIGRATION_FILE_TAG] = array();
//Inicia o Rollback de arquivos deletados
$rollback[Strings::ROLLBACK_MODULE_MIGRATION_DELETED_FILE_TAG] = array();
//Copia lista de arquivos no diretorio de migrations para variavel arquivos
$arquivos = scandir(PathHelper::getModuleMigrationsPath($moduleType, $moduleName));
//Loop em todos os arquivos do modulo
for ($i = Constants::FIRST_FILE; $i < count($arquivos); $i++) {
//Quebra as palavras da migration dentro de um array
$explodedModuleMigrationName = explode(Strings::MIGRATIONS_WORD_SEPARATOR, $arquivos[$i]);
//Pega remove a parte do nome referente ao timestamp
$SimplifiedModuleMigrationName = implode(Strings::MIGRATIONS_WORD_SEPARATOR, array_slice($explodedModuleMigrationName, Constants::MIGRATION_FILE_NAME_ARRAY_START));
//Flag que indica se o arquivo existe
$migrationPos = false;
//Pega migrations do projeto
$migrationFiles = scandir(PathHelper::getLaravelMigrationsPath());
foreach ($migrationFiles as $migrationIndex => $migrationFile) {
//Quebra as palavras da migration dentro de um array
$explodedMigrationFileName = explode(Strings::MIGRATIONS_WORD_SEPARATOR, $migrationFile);
//Pega remove a parte do nome referente ao timestamp
$SimplifiedMigratioFileName = implode(Strings::MIGRATIONS_WORD_SEPARATOR, array_slice($explodedMigrationFileName, Constants::MIGRATION_FILE_NAME_ARRAY_START));
//Verifica se a migration já existe
if ($SimplifiedMigratioFileName == $SimplifiedModuleMigrationName) {
//marca o arquivo de migration existente migration
$migrationPos = $migrationIndex;
//quebra o loop
break;
}
}
$explodedFileName = explode(Strings::PATH_SEPARATOR, PathHelper::getModuleMigrationsPath($moduleType, $moduleName) . $arquivos[$i]);
$filename = $explodedFileName[count($explodedFileName) - 1];
if (strtoupper($filename) != strtoupper(Strings::GIT_KEEP_FILE_NAME)) {
if ($migrationPos == false) {
//Se o arquivo não existir
$migrationCounter = Configs::getConfig(PathHelper::getModuleGeneralConfig(), Strings::CONFIG_MIGRATIONS_COUNTER);
Configs::setConfig(PathHelper::getModuleGeneralConfig(), Strings::CONFIG_MIGRATIONS_COUNTER, $migrationCounter + 1);
if (copy(PathHelper::getModuleMigrationsPath($moduleType, $moduleName) . $arquivos[$i], PathHelper::getLaravelMigrationsPath() . Strings::timestampPadding($migrationCounter) . Strings::MIGRATIONS_WORD_SEPARATOR . $SimplifiedModuleMigrationName) == false) {
$errors[] = Strings::migrationsFileCopyError($arquivos[$i]);
}
//Sinaliza o no arquivo copiado
$rollback[Strings::ROLLBACK_MODULE_MIGRATION_FILE_TAG][] = EscapeHelper::encode(PathHelper::getLaravelMigrationsPath() . Strings::timestampPadding($migrationCounter) . Strings::MIGRATIONS_WORD_SEPARATOR . $SimplifiedModuleMigrationName);
} else {
//Se o arquivo ja existir
if ($allowReplace) {
//Inicializa variavel que vai receber resposta do usuario dizendo o que fazer
// com o conflito
$answer = Strings::EMPTY_STRING;
//Enquanto o usuario não devolver uma resposta valida
while ($copyAll != true && $answer != Strings::SHORT_YES && $answer != Strings::SHORT_NO && $answer != Strings::SHORT_ALL && $answer != Strings::SHORT_CANCEL) {
//Faz pergunta para o usuario de como proceder
$answer = $command->ask(Strings::replaceMigrationFiles($arquivos[$i]), false);
}
//Se a resposta for sim, ou all
if (strtolower($answer) == Strings::SHORT_YES || strtolower($answer) == Strings::SHORT_ALL || $copyAll == true) {
//se a resposta for all
if (strtolower($answer) == Strings::SHORT_ALL) {
//seta variavel all para true
$copyAll = true;
}
//Captura o numero da migration
$migrationCounter = Configs::getConfig(PathHelper::getModuleGeneralConfig(), Strings::CONFIG_MIGRATIONS_COUNTER);
//Atualiza o contador de migrations
Configs::setConfig(PathHelper::getModuleGeneralConfig(), Strings::CONFIG_MIGRATIONS_COUNTER, $migrationCounter + 1);
//Sinaliza o no arquivo copiado
$rollback[Strings::ROLLBACK_MODULE_MIGRATION_FILE_TAG][] = EscapeHelper::encode(PathHelper::getModuleMigrationsPath($moduleType, $moduleName) . Strings::timestampPadding($migrationCounter) . Strings::MIGRATIONS_WORD_SEPARATOR . $SimplifiedModuleMigrationName);
//Faz backup do arquivo que será substituido
$rollback[Strings::ROLLBACK_MODULE_MIGRATION_DELETED_FILE_TAG][EscapeHelper::encode(PathHelper::getLaravelMigrationsPath() . $migrationFiles[$migrationPos])] = EscapeHelper::encode(file_get_contents(PathHelper::getLaravelMigrationsPath() . $migrationFiles[$migrationPos]));
//Deletar o arquivo antigo
if (unlink(PathHelper::getLaravelMigrationsPath() . $migrationFiles[$migrationPos]) == false) {
$errors[] = Strings::migrationsFileDeleteError($arquivos[$i]);
}
//verifica se a substituição ocorreu com sucesso
if (copy(PathHelper::getModuleMigrationsPath($moduleType, $moduleName) . $arquivos[$i], Strings::timestampPadding($migrationCounter) . Strings::MIGRATIONS_WORD_SEPARATOR . $SimplifiedModuleMigrationName) == false) {
$errors[] = Strings::migrationsFileCopyError($arquivos[$i]);
}
} else {
if (strtolower($answer) == Strings::SHORT_CANCEL) {
//se a resposta foi cancelar
//Printa msg de erro
$errors[] = Strings::userRequestedAbort();
//break the file loop
break;
}
}
}
}
//.........这里部分代码省略.........
示例14: askDatabasePassword
/**
* @param
*
* @return string
*/
protected function askDatabasePassword()
{
$databasePassword = $this->command->ask('Enter your database password (type "<none>" for no password)', 'secret');
return $databasePassword === '<none>' ? '' : $databasePassword;
}