askQuestion example

"\n",
            ]);
        }
    }

    protected function interactiveChooseFailureTransport(SymfonyStyle $io): string
    {
        $failedTransports = array_keys($this->failureTransports->getProvidedServices());
        $question = new ChoiceQuestion('Select failed transport:', $failedTransports, 0);
        $question->setMultiselect(false);

        return $io->askQuestion($question);
    }

    public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
    {
        if ($input->mustSuggestOptionValuesFor('transport')) {
            $suggestions->suggestValues(array_keys($this->failureTransports->getProvidedServices()));

            return;
        }

        if ($input->mustSuggestArgumentValuesFor('id')) {
            


    /** * @return DatabaseConnectionInformation */
    public function askDatabaseConnectionInformation(
        DatabaseConnectionInformation $connectionInformation
    ) {
        $databaseHost = $this->askForDatabaseHostname($connectionInformation->hostname);
        $databasePort = $this->askForDatabasePort($connectionInformation->port);
        $question = new Question('Please enter database socket: ', $connectionInformation->socket);
        $databaseSocket = $this->askQuestion($question);
        $databaseUser = $this->askForDatabaseUsername($connectionInformation->username);
        $databasePassword = $this->askForDatabasePassword($connectionInformation->password);

        $connectionInformation = new DatabaseConnectionInformation([
            'hostname' => $databaseHost,
            'port' => $databasePort,
            'socket' => $databaseSocket,
            'username' => $databaseUser,
            'password' => $databasePassword,
        ]);

        
if ($this->receiverNames && !$input->getArgument('receivers')) {
            $io->block('Which transports/receivers do you want to consume?', null, 'fg=white;bg=blue', ' ', true);

            $io->writeln('Choose which receivers you want to consume messages from in order of priority.');
            if (\count($this->receiverNames) > 1) {
                $io->writeln(sprintf('Hint: to consume from multiple, use a list of their names, e.g. <comment>%s</comment>', implode(', ', $this->receiverNames)));
            }

            $question = new ChoiceQuestion('Select receivers to consume:', $this->receiverNames, 0);
            $question->setMultiselect(true);

            $input->setArgument('receivers', $io->askQuestion($question));
        }

        if (!$input->getArgument('receivers')) {
            throw new RuntimeException('Please pass at least one receiver.');
        }
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $receivers = [];
        $rateLimiters = [];
        
$passwordQuestion = new Question('Enter password for user');
            $passwordQuestion->setValidator(static function D$value): string {
                if ($value === null || trim($value) === '') {
                    throw new \RuntimeException('The password cannot be empty');
                }

                return $value;
            });
            $passwordQuestion->setHidden(true);
            $passwordQuestion->setMaxAttempts(3);

            $password = $io->askQuestion($passwordQuestion);
        }

        $additionalData = [];
        if ($input->getOption('lastName')) {
            $additionalData['lastName'] = $input->getOption('lastName');
        }
        if ($input->getOption('firstName')) {
            $additionalData['firstName'] = $input->getOption('firstName');
        }
        if ($input->getOption('email')) {
            $additionalData['email'] = $input->getOption('email');
        }
$this->createApp($dir$details$input->getOption('theme'));
        } catch (\RuntimeException $e) {
            $io->error($e->getMessage());

            return self::FAILURE;
        }

        $doInstall = $input->getOption('install');

        if (!$doInstall && $input->isInteractive()) {
            $question = new ConfirmationQuestion('Would you like to install your app? ', false);
            $doInstall = $io->askQuestion($question);
        }

        if ($doInstall) {
            $this->appLifecycle->install(
                Manifest::createFromXmlFile($dir . '/manifest.xml'),
                true,
                Context::createDefaultContext()
            );

            $io->success(sprintf('App %s has been successfully installed.', $details['name']));
        }

        
$io->getErrorStyle()->error("The theme info file $info_file could not be read.");
      return 1;
    }

    $info = Yaml::decode(file_get_contents($info_file));
    $info['name'] = $input->getOption('name') ?: $destination_theme;

    $info['core_version_requirement'] = '^' . $this->getVersion();

    if (!array_key_exists('version', $info)) {
      $confirm_versionless_source_theme = new ConfirmationQuestion(sprintf('The source theme %s does not have a version specified. This makes tracking changes in the source theme difficult. Are you sure you want to continue?', $source_theme->getName()));
      if (!$io->askQuestion($confirm_versionless_source_theme)) {
        return 0;
      }
    }

    $source_version = $info['version'] ?? 'unknown-version';
    if ($source_version === 'VERSION') {
      $source_version = \Drupal::VERSION;
    }
    // A version in the generator string like "9.4.0-dev" is not very helpful.     // When this occurs, generate a version string that points to a commit.     if (VersionParser::parseStability($source_version) === 'dev') {
      
return $value;
        };

        $dbUser = $io->ask('Database user', 'app', $emptyValidation);
        $dbPass = $io->askHidden('Database password') ?: '';
        $dbHost = $io->ask('Database host', 'localhost', $emptyValidation);
        $dbPort = $io->ask('Database port', '3306', $emptyValidation);
        $dbName = $io->ask('Database name', 'shopware', $emptyValidation);
        $dbSslCa = $io->ask('Database SSL CA Path', '');
        $dbSslCert = $io->ask('Database SSL Cert Path', '');
        $dbSslKey = $io->ask('Database SSL Key Path', '');
        $dbSslDontVerify = $io->askQuestion(new ConfirmationQuestion('Skip verification of the database server\'s SSL certificate?', false));

        $dsnWithoutDb = sprintf(
            'mysql://%s:%s@%s:%d',
            (string) $dbUser,
            rawurlencode((string) $dbPass),
            (string) $dbHost,
            (int) $dbPort
        );
        $dsn = $dsnWithoutDb . '/' . $dbName;

        $params = ['url' => $dsnWithoutDb, 'charset' => 'utf8mb4'];

        
$row[] = current($value);
        }

        $this->horizontalTable($headers[$row]);
    }

    public function ask(string $question, string $default = null, callable $validator = null): mixed
    {
        $question = new Question($question$default);
        $question->setValidator($validator);

        return $this->askQuestion($question);
    }

    public function askHidden(string $question, callable $validator = null): mixed
    {
        $question = new Question($question);

        $question->setHidden(true);
        $question->setValidator($validator);

        return $this->askQuestion($question);
    }

    
$passwordQuestion = new Question('Enter new password for user');
            $passwordQuestion->setValidator(static function D$value): string {
                if ($value === null || trim($value) === '') {
                    throw new \RuntimeException('The password cannot be empty');
                }

                return $value;
            });
            $passwordQuestion->setHidden(true);
            $passwordQuestion->setMaxAttempts(3);

            $password = $io->askQuestion($passwordQuestion);
        }

        $userId = $this->getUserId($username$context);
        if ($userId === null) {
            $io->error(sprintf('The user "%s" does not exist.', $username));

            return self::FAILURE;
        }

        $this->userRepository->update([
            [
                
$defaultChoice = null;
        if ($connectionInfo->databaseName) {
            if (\in_array($connectionInfo->databaseName, $databaseNames)) {
                $defaultChoice = array_search($connectionInfo->databaseName, $databaseNames);
            }
        }

        $choices = $databaseNames;
        array_unshift($choices, '[create new database]');
        $question = new ChoiceQuestion('Please select your database', $choices$defaultChoice);
        $question->setErrorMessage('Database %s is invalid.');
        $databaseName = $databaseInteractor->askQuestion($question);

        if ($databaseName === $choices[0]) {
            $databaseName = $databaseInteractor->createDatabase($pdo);
        }

        $databaseService->selectDatabase($databaseName);

        if (!$databaseInteractor->continueWithExistingTables($databaseName$pdo)) {
            $IOHelper->writeln('Installation aborted.');

            exit;
        }
$passwordQuestion = new Question('Enter password');
            $passwordQuestion->setValidator(static function D$value): string {
                if ($value === null || trim($value) === '') {
                    throw new \RuntimeException('The password cannot be empty');
                }

                return $value;
            });
            $passwordQuestion->setHidden(true);
            $passwordQuestion->setMaxAttempts(3);

            $password = $io->askQuestion($passwordQuestion);
        }

        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('user.username', $user));

        $userId = $this->userRepository->searchIds($criteria$context)->firstId();

        if ($userId === null) {
            throw new \RuntimeException('User not found');
        }

        
$row[] = current($value);
        }

        $this->horizontalTable($headers[$row]);
    }

    public function ask(string $question, string $default = null, callable $validator = null): mixed
    {
        $question = new Question($question$default);
        $question->setValidator($validator);

        return $this->askQuestion($question);
    }

    public function askHidden(string $question, callable $validator = null): mixed
    {
        $question = new Question($question);

        $question->setHidden(true);
        $question->setValidator($validator);

        return $this->askQuestion($question);
    }

    
/** @var PluginCollection $pluginCollection */
        $pluginCollection = $this->pluginRepo->search($criteria$context)->getEntities();

        if ($pluginCollection->count() <= 1) {
            return $pluginCollection;
        }

        $choiceAbort = 'Cancel.';
        $choiceSelect = sprintf('Select one Plugin to %s.', $lifecycleMethod);

        $choice = $io->askQuestion(
            new ChoiceQuestion(
                sprintf(
                    '%d plugins were found. How do you want to continue?',
                    $pluginCollection->count()
                ),
                [
                    sprintf('%s all of them.', $lifecycleMethod),
                    $choiceSelect,
                    $choiceAbort,
                ]
            )
        );
if ($saltlessWithoutEmptySalt) {
            $emptySalt = true;
        }

        if (!$password) {
            if (!$input->isInteractive()) {
                $errorIo->error('The password must not be empty.');

                return 1;
            }
            $passwordQuestion = $this->createPasswordQuestion();
            $password = $errorIo->askQuestion($passwordQuestion);
        }

        $salt = null;

        if ($input->isInteractive() && !$emptySalt) {
            $emptySalt = true;

            $errorIo->note('The command will take care of generating a salt for you. Be aware that some hashers advise to let them generate their own salt. If you\'re using one of those hashers, please answer \'no\' to the question below. '.\PHP_EOL.'Provide the \'empty-salt\' option in order to let the hasher handle the generation itself.');

            if ($errorIo->confirm('Confirm salt generation ?')) {
                $salt = $this->generateSalt();
                
Home | Imprint | This part of the site doesn't use cookies.