本文整理匯總了PHP中Symfony\Component\Console\Output\OutputInterface::ask方法的典型用法代碼示例。如果您正苦於以下問題:PHP OutputInterface::ask方法的具體用法?PHP OutputInterface::ask怎麽用?PHP OutputInterface::ask使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\Console\Output\OutputInterface
的用法示例。
在下文中一共展示了OutputInterface::ask方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: interact
/**
* {@inheritdoc}
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
// --base_class option.
// @todo Turn this into a choice() option.
$base_class = $input->getOption('base_class');
if (empty($base_class)) {
$base_class = $output->ask($this->trans('commands.generate.metatag.group.questions.base_class'), 'GroupBase');
}
$input->setOption('base_class', $base_class);
// --module option.
$module = $input->getOption('module');
if (empty($module)) {
// @see Drupal\AppConsole\Command\Helper\ModuleTrait::moduleQuestion
$module = $this->moduleQuestion($output);
}
$input->setOption('module', $module);
// --label option.
$label = $input->getOption('label');
if (empty($label)) {
$label = $output->ask($this->trans('commands.generate.metatag.group.questions.label'));
}
$input->setOption('label', $label);
// --description option.
$description = $input->getOption('description');
if (empty($description)) {
$description = $output->ask($this->trans('commands.generate.metatag.group.questions.description'));
}
$input->setOption('description', $description);
// --plugin-id option.
$plugin_id = $input->getOption('plugin-id');
if (empty($plugin_id)) {
$plugin_id = $output->ask($this->trans('commands.generate.metatag.group.questions.plugin_id'));
}
$input->setOption('plugin-id', $plugin_id);
// --class-name option.
$class_name = $input->getOption('class-name');
if (empty($class_name)) {
$class_name = $output->ask($this->trans('commands.generate.metatag.group.questions.class_name'));
}
$input->setOption('class-name', $class_name);
// --weight option.
// @todo Automatically get the next integer value based upon the current
// group.
$weight = $input->getOption('weight');
if (is_null($weight)) {
$weight = $output->ask($this->trans('commands.generate.metatag.group.questions.weight'), 0);
}
$input->setOption('weight', $weight);
}
示例2: interact
/**
* {@inheritdoc}
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$validator_filename = function ($value) use($io) {
if (!strlen(trim($value)) || !is_file($value)) {
$io->error($this->trans('commands.common.errors.invalid-file-path'));
return false;
}
return $value;
};
// --yaml-left option
$yaml_left = $input->getArgument('yaml-left');
if (!$yaml_left) {
while (true) {
$yaml_left = $output->ask($this->trans('commands.yaml.diff.questions.yaml-left'), null, $validator_filename);
if ($yaml_left) {
break;
}
}
$input->setArgument('yaml-left', $yaml_left);
}
// --yaml-right option
$yaml_right = $input->getArgument('yaml-right');
if (!$yaml_right) {
while (true) {
$yaml_right = $output->ask($this->trans('commands.yaml.diff.questions.yaml-right'), null, $validator_filename);
if ($yaml_right) {
break;
}
}
$input->setArgument('yaml-right', $yaml_right);
}
}
示例3: interact
/**
* {@inheritdoc}
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$stringUtils = $this->getStringHelper();
$validators = $this->getValidator();
try {
// A profile is technically also a module, so we can use the same
// validator to check the name.
$profile = $input->getOption('profile') ? $this->validateModuleName($input->getOption('profile')) : null;
} catch (\Exception $error) {
$io->error($error->getMessage());
return;
}
if (!$profile) {
$profile = $io->ask($this->trans('commands.generate.profile.questions.profile'), '', function ($profile) use($validators) {
return $validators->validateModuleName($profile);
});
$input->setOption('profile', $profile);
}
try {
$machine_name = $input->getOption('machine-name') ? $this->validateModule($input->getOption('machine-name')) : null;
} catch (\Exception $error) {
$io->error($error->getMessage());
return;
}
if (!$machine_name) {
$machine_name = $io->ask($this->trans('commands.generate.profile.questions.machine-name'), $stringUtils->createMachineName($profile), function ($machine_name) use($validators) {
return $validators->validateMachineName($machine_name);
});
$input->setOption('machine-name', $machine_name);
}
$description = $input->getOption('description');
if (!$description) {
$description = $io->ask($this->trans('commands.generate.profile.questions.description'), 'My Useful Profile');
$input->setOption('description', $description);
}
$core = $input->getOption('core');
if (!$core) {
$core = $io->ask($this->trans('commands.generate.profile.questions.core'), '8.x');
$input->setOption('core', $core);
}
$dependencies = $input->getOption('dependencies');
if (!$dependencies) {
if ($io->confirm($this->trans('commands.generate.profile.questions.dependencies'), true)) {
$dependencies = $output->ask($this->trans('commands.generate.profile.options.dependencies'), '');
}
$input->setOption('dependencies', $dependencies);
}
$distribution = $input->getOption('distribution');
if (!$distribution) {
if ($io->confirm($this->trans('commands.generate.profile.questions.distribution'), false)) {
$distribution = $output->ask($this->trans('commands.generate.profile.options.distribution'), 'My Kick-ass Distribution');
$input->setOption('distribution', $distribution);
}
}
}
示例4: ask
/**
* Kullanıcıya soru sorar
*
* @param string $question
* @param string $default
* @return string
*/
public function ask($question, $default = null)
{
return $this->output->ask($question, $default);
}
示例5: interact
/**
* {@inheritdoc}
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
$boolean_options = ['FALSE', 'TRUE'];
// ToDo: Take this from typed data, so it can be extended?
$type_options = ['integer', 'string', 'label', 'uri', 'image'];
// --base_class option.
// @todo Turn this into a choice() option.
$base_class = $input->getOption('base_class');
if (empty($base_class)) {
$base_class = $output->ask($this->trans('commands.generate.metatag.tag.questions.base_class'), 'MetaNameBase');
}
$input->setOption('base_class', $base_class);
// --module option.
$module = $input->getOption('module');
if (empty($module)) {
// @see Drupal\AppConsole\Command\Helper\ModuleTrait::moduleQuestion
$module = $this->moduleQuestion($output);
}
$input->setOption('module', $module);
// --name option.
// @todo Add validation.
$name = $input->getOption('name');
if (empty($name)) {
$name = $output->ask($this->trans('commands.generate.metatag.tag.questions.name'));
}
$input->setOption('name', $name);
// --label option.
$label = $input->getOption('label');
if (empty($label)) {
$label = $output->ask($this->trans('commands.generate.metatag.tag.questions.label'), $name);
}
$input->setOption('label', $label);
// --description option.
$description = $input->getOption('description');
if (empty($description)) {
$description = $output->ask($this->trans('commands.generate.metatag.tag.questions.description'));
}
$input->setOption('description', $description);
// --plugin-id option.
$plugin_id = $input->getOption('plugin-id');
if (empty($plugin_id)) {
$plugin_id = $this->nameToPluginId($name);
$plugin_id = $output->ask($this->trans('commands.generate.metatag.tag.questions.plugin_id'), $plugin_id);
}
$input->setOption('plugin-id', $plugin_id);
// --class-name option.
$class_name = $input->getOption('class-name');
if (empty($class_name)) {
$class_name = $this->nameToClassName($name);
$class_name = $output->ask($this->trans('commands.generate.metatag.tag.questions.class_name'), $class_name);
}
$input->setOption('class-name', $class_name);
// --group option.
$group = $input->getOption('group');
if (empty($group)) {
$groups = $this->getGroups();
$group = $output->choice($this->trans('commands.generate.metatag.tag.questions.group'), $groups);
}
$input->setOption('group', $group);
// --weight option.
// @todo Automatically get the next integer value based upon the current
// group.
$weight = $input->getOption('weight');
if (is_null($weight)) {
$weight = $output->ask($this->trans('commands.generate.metatag.tag.questions.weight'), 0);
}
$input->setOption('weight', $weight);
// --type option.
// @todo Turn this into an option.
$type = $input->getOption('type');
if (is_null($type)) {
$type = $output->choice($this->trans('commands.generate.metatag.tag.questions.type'), $type_options, 0);
}
$input->setOption('type', $type);
// --multiple option.
$multiple = $input->getOption('multiple');
if (is_null($multiple)) {
$multiple = $output->choice($this->trans('commands.generate.metatag.tag.questions.multiple'), $boolean_options, 0);
}
$input->setOption('multiple', $multiple);
}