本文整理汇总了PHP中Symfony\Component\Console\Input\InputInterface::setOption方法的典型用法代码示例。如果您正苦于以下问题:PHP InputInterface::setOption方法的具体用法?PHP InputInterface::setOption怎么用?PHP InputInterface::setOption使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Console\Input\InputInterface
的用法示例。
在下文中一共展示了InputInterface::setOption方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: interact
/**
* {@inheritdoc}
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
$io = new ConsoleIO($input, $output);
$this->welcomeMessage($io);
$title = $io->askAndValidate('Post title', function ($answer) {
return Validators::validatePostTitle($answer);
}, false, $input->getOption('title'));
$input->setOption('title', $title);
$layout = $io->ask('Post layout', $input->getOption('layout'));
$input->setOption('layout', $layout);
$defaultDate = $input->getOption('date');
if (empty($defaultDate) === true) {
$defaultDate = $this->getDateFormated();
}
$date = $io->ask('Post date', $defaultDate);
$input->setOption('date', $date);
if ($io->askConfirmation('Do you want to use tags?', empty($input->getOption('tags')) === false)) {
$tags = $io->ask('Comma separated list of post tags', $input->getOption('tags'));
$input->setOption('tags', $tags);
}
if ($io->askConfirmation('Do you want to use categories?', empty($input->getOption('categories')) === false)) {
$categories = $io->ask('Comma separated list of post categories', $input->getOption('categories'));
$input->setOption('categories', $categories);
}
}
示例2: interact
/**
* {@inheritdoc}
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
$dialog = $this->getDialogHelper();
// --module option
$module = $input->getOption('module');
if (!$module) {
// @see Drupal\Console\Command\ModuleTrait::moduleQuestion
$module = $this->moduleQuestion($output, $dialog);
}
$input->setOption('module', $module);
// --command
$name = $input->getOption('name');
if (!$name) {
$name = $dialog->ask($output, $dialog->getQuestion($this->trans('commands.generate.command.questions.name'), $module . ':default'), $module . ':default');
}
$input->setOption('name', $name);
// --class-name option
$class = $input->getOption('class');
if (!$class) {
$class = $dialog->askAndValidate($output, $dialog->getQuestion($this->trans('commands.generate.command.questions.class'), 'DefaultCommand'), function ($class) {
return $this->getValidator()->validateCommandName($class);
}, false, 'DefaultCommand', null);
$input->setOption('class', $class);
}
// --container option
$containerAware = $input->getOption('container-aware');
if (!$containerAware && $dialog->askConfirmation($output, $dialog->getQuestion($this->trans('commands.generate.command.questions.container-aware'), 'yes', '?'), true)) {
$containerAware = true;
}
$input->setOption('container-aware', $containerAware);
}
示例3: interact
protected function interact(InputInterface $input, OutputInterface $output)
{
$dialog = $this->getDialogHelper();
// --module option
$module = $input->getOption('module');
if (!$module) {
// @see Drupal\Console\Command\ModuleTrait::moduleQuestion
$module = $this->moduleQuestion($output, $dialog);
}
$input->setOption('module', $module);
// --class-name option
$class_name = $input->getOption('class-name');
if (!$class_name) {
$class_name = $dialog->ask($output, $dialog->getQuestion($this->trans('commands.generate.plugin.type.annotation.options.class-name'), 'ExamplePlugin'), 'ExamplePlugin');
}
$input->setOption('class-name', $class_name);
$default_machine_name = $this->getStringUtils()->camelCaseToUnderscore($class_name);
// --machine-name option
$machine_name = $input->getOption('machine-name');
if (!$machine_name) {
$machine_name = $dialog->ask($output, $dialog->getQuestion($this->trans('commands.generate.plugin.type.annotation.options.machine-name'), $default_machine_name), $default_machine_name);
}
$input->setOption('machine-name', $machine_name);
$default_label = $this->getStringUtils()->camelCaseToHuman($class_name);
// --label option
$label = $input->getOption('label');
if (!$label) {
$label = $dialog->ask($output, $dialog->getQuestion($this->trans('commands.generate.plugin.type.annotation.options.label'), $default_label), $default_label);
}
$input->setOption('label', $label);
}
示例4: interact
/**
* {@inheritdoc}
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
$output = new DrupalStyle($input, $output);
// --module option
$module = $input->getOption('module');
if (!$module) {
// @see Drupal\Console\Command\ModuleTrait::moduleQuestion
$module = $this->moduleQuestion($output);
$input->setOption('module', $module);
}
// view-id argument
$viewId = $input->getArgument('view-id');
if (!$viewId) {
$entityManager = $this->getEntityManager();
$views = $entityManager->getStorage('view')->loadMultiple();
$viewList = [];
foreach ($views as $view) {
$viewList[$view->get('id')] = $view->get('label');
}
$viewId = $output->choiceNoList($this->trans('commands.views.export.questions.view'), $viewList);
$input->setArgument('view-id', $viewId);
}
$optionalConfig = $input->getOption('optional-config');
if (!$optionalConfig) {
$optionalConfig = $output->confirm($this->trans('commands.config.export.view.questions.optional-config'), true);
$input->setOption('optional-config', $optionalConfig);
}
$includeModuleDependencies = $input->getOption('include-module-dependencies');
if (!$includeModuleDependencies) {
$includeModuleDependencies = $output->confirm($this->trans('commands.config.export.view.questions.include-module-dependencies'), true);
$input->setOption('include-module-dependencies', $includeModuleDependencies);
}
}
示例5: interact
/**
* {@inheritdoc}
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
// --module option
$module = $input->getOption('module');
if (!$module) {
// @see Drupal\Console\Command\ModuleTrait::moduleQuestion
$module = $this->moduleQuestion($output);
$input->setOption('module', $module);
}
// --name
$name = $input->getOption('name');
if (!$name) {
$name = $io->ask($this->trans('commands.generate.command.questions.name'), sprintf('%s:default', $module));
$input->setOption('name', $name);
}
// --class option
$class = $input->getOption('class');
if (!$class) {
$class = $io->ask($this->trans('commands.generate.command.questions.class'), 'DefaultCommand', function ($class) {
return $this->getValidator()->validateCommandName($class);
});
$input->setOption('class', $class);
}
// --container-aware option
$containerAware = $input->getOption('container-aware');
if (!$containerAware) {
$io->confirm($this->trans('commands.generate.command.questions.container-aware'), true);
}
$input->setOption('container-aware', $containerAware);
}
示例6: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$configOptions = [];
$connection = $input->getArgument('connection');
if (false === strpos($connection, ':')) {
//treat it as connection name
$configOptions['propel']['reverse']['connection'] = $connection;
if (!$input->getOption('database-name')) {
$input->setOption('database-name', $connection);
}
} else {
//probably a dsn
$configOptions += $this->connectionToProperties('reverseconnection=' . $connection, 'reverse');
$configOptions['propel']['reverse']['parserClass'] = sprintf('\\Propel\\Generator\\Reverse\\%sSchemaParser', ucfirst($configOptions['propel']['database']['connections']['reverseconnection']['adapter']));
if (!$input->getOption('database-name')) {
$input->setOption('database-name', self::DEFAULT_DATABASE_NAME);
}
}
$generatorConfig = $this->getGeneratorConfig($configOptions, $input);
$this->createDirectory($input->getOption('output-dir'));
$manager = new ReverseManager(new XmlDumper());
$manager->setGeneratorConfig($generatorConfig);
$manager->setLoggerClosure(function ($message) use($input, $output) {
if ($input->getOption('verbose')) {
$output->writeln($message);
}
});
$manager->setWorkingDirectory($input->getOption('output-dir'));
$manager->setDatabaseName($input->getOption('database-name'));
$manager->setSchemaName($input->getOption('schema-name'));
if (true === $manager->reverse()) {
$output->writeln('<info>Schema reverse engineering finished.</info>');
}
}
示例7: interact
protected function interact(InputInterface $input, OutputInterface $output)
{
$dialog = $this->getDialogHelper();
// --module option
$module = $input->getOption('module');
if (!$module) {
// @see Drupal\AppConsole\Command\Helper\ModuleTrait::moduleQuestion
$module = $this->moduleQuestion($output, $dialog);
}
$input->setOption('module', $module);
// --class-name option
$class_name = $input->getOption('class-name');
if (!$class_name) {
$class_name = $dialog->ask($output, $dialog->getQuestion($this->trans('commands.generate.plugin.type.yaml.options.class-name'), 'ExamplePlugin'), 'ExamplePlugin');
}
$input->setOption('class-name', $class_name);
$default_plugin_name = $this->getStringUtils()->camelCaseToUnderscore($class_name);
// --plugin-name option
$plugin_name = $input->getOption('plugin-name');
if (!$plugin_name) {
$plugin_name = $dialog->ask($output, $dialog->getQuestion($this->trans('commands.generate.plugin.type.yaml.options.plugin-name'), $default_plugin_name), $default_plugin_name);
}
$input->setOption('plugin-name', $plugin_name);
$default_file_name = strtr($plugin_name, '_-', '..');
// --plugin-file-name option
$plugin_file_name = $input->getOption('plugin-file-name');
if (!$plugin_file_name) {
$plugin_file_name = $dialog->ask($output, $dialog->getQuestion($this->trans('commands.generate.plugin.type.yaml.options.plugin-file-name'), $default_file_name), $default_file_name);
}
$input->setOption('plugin-file-name', $plugin_file_name);
}
示例8: interact
/**
* {@inheritdoc}
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$contentTypes = $input->getArgument('content-types');
if (!$contentTypes) {
$bundles = $this->getDrupalApi()->getBundles();
$contentTypes = $io->choice($this->trans('commands.create.nodes.questions.content-type'), array_values($bundles), null, true);
$contentTypes = array_map(function ($contentType) use($bundles) {
return array_search($contentType, $bundles);
}, $contentTypes);
$input->setArgument('content-types', $contentTypes);
}
$limit = $input->getOption('limit');
if (!$limit) {
$limit = $io->ask($this->trans('commands.create.nodes.questions.limit'), 25);
$input->setOption('limit', $limit);
}
$titleWords = $input->getOption('title-words');
if (!$titleWords) {
$titleWords = $io->ask($this->trans('commands.create.nodes.questions.title-words'), 5);
$input->setOption('title-words', $titleWords);
}
$timeRange = $input->getOption('time-range');
if (!$timeRange) {
$timeRanges = $this->getTimeRange();
$timeRange = $io->choice($this->trans('commands.create.nodes.questions.time-range'), array_values($timeRanges));
$input->setOption('time-range', array_search($timeRange, $timeRanges));
}
}
示例9: interact
/**
* {@inheritdoc}
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
$dialog = $this->getDialogHelper();
$utils = $this->getStringUtils();
// --module option
$module = $input->getOption('module');
if (!$module) {
// @see Drupal\AppConsole\Command\Helper\ModuleTrait::moduleQuestion
$module = $this->moduleQuestion($output, $dialog);
}
$input->setOption('module', $module);
// --entity-class option
$entity_class = $input->getOption('entity-class');
if (!$entity_class) {
$entity_class = 'DefaultEntity';
$entity_class = $dialog->askAndValidate($output, $dialog->getQuestion($this->trans('commands.generate.entity.questions.entity-class'), $entity_class), function ($entity_class) {
return $this->validateSpaces($entity_class);
}, false, $entity_class, null);
}
$input->setOption('entity-class', $entity_class);
$machine_name = $utils->camelCaseToMachineName($entity_class);
// --entity-name option
$entity_name = $input->getOption('entity-name');
if (!$entity_name) {
$entity_name = $dialog->askAndValidate($output, $dialog->getQuestion($this->trans('commands.generate.entity.questions.entity-name'), $machine_name), function ($machine_name) {
return $this->validateMachineName($machine_name);
}, false, $machine_name, null);
}
$input->setOption('entity-name', $entity_name);
}
示例10: applyComposerParams
/**
* Applies parameters that are defined in the extra section of composer.json.
*
* If the Input object already has a value for the argument or parameter then the value in composer is ignored.
*
* @param Command $command
* @param InputInterface $input
*
* @return $this
* @throws MysqlVersionControlException
*/
public function applyComposerParams(Command $command, InputInterface $input)
{
$params = $this->getComposerParams($input->getArgument("env"));
$definition = $command->getDefinition();
foreach ($this->filterComposerParams($params, $definition) as $param => $value) {
if (0 === strpos($param, "--")) {
// option
$option = substr($param, 2);
$Option = $definition->getOption($option);
if (!$Option->acceptValue() && false === $input->getOption($option)) {
$input->setOption($option, null);
} elseif ($Option->acceptValue() && $Option->getDefault() === $input->getOption($option)) {
if ($Option->isArray()) {
$input->setOption($option, is_array($value) ? $value : [$value]);
} elseif (is_array($value)) {
throw new MysqlVersionControlException("The '{$option}' option does not accept arrays. Check your composer.json");
} else {
$input->setOption($option, $value);
}
}
} else {
// argument
$argument = $definition->getArgument($param);
if ($argument->getDefault() === $input->getArgument($param)) {
$input->setArgument($param, $value);
}
}
}
return $this;
}
示例11: interact
public function interact(InputInterface $input, OutputInterface $output)
{
$questionHelper = $this->getQuestionHelper();
$questionHelper->writeSection($output, 'Welcome to the Symfony2 controller generator');
// namespace
$output->writeln(array('', 'Every page, and even sections of a page, are rendered by a <comment>controller</comment>.', 'This command helps you generate them easily.', '', 'First, you need to give the controller name you want to generate.', 'You must use the shortcut notation like <comment>AcmeBlogBundle:Post</comment>', ''));
$bundleNames = array_keys($this->getContainer()->get('kernel')->getBundles());
while (true) {
$controller = $questionHelper->askAndValidate($output, $questionHelper->getQuestion('Controller name', $input->getOption('controller')), array('Oliorga\\GeneratorBundle\\Command\\Validators', 'validateControllerName'), false, $input->getOption('controller'), $bundleNames);
list($bundle, $controller) = $this->parseShortcutNotation($controller);
try {
$b = $this->getContainer()->get('kernel')->getBundle($bundle);
if (!file_exists($b->getPath() . '/Controller/' . $controller . 'Controller.php')) {
break;
}
$output->writeln(sprintf('<bg=red>Controller "%s:%s" already exists.</>', $bundle, $controller));
} catch (\Exception $e) {
$output->writeln(sprintf('<bg=red>Bundle "%s" does not exist.</>', $bundle));
}
}
$input->setOption('controller', $bundle . ':' . $controller);
// routing format
$routeFormat = 'annotation';
$input->setOption('route-format', $routeFormat);
// templating format
$templateFormat = 'twig';
$input->setOption('template-format', $templateFormat);
// actions
$input->setOption('actions', $this->addActions($input, $output, $questionHelper));
// summary
$output->writeln(array('', $this->getHelper('formatter')->formatBlock('Summary before generation', 'bg=blue;fg-white', true), '', sprintf('You are going to generate a "<info>%s:%s</info>" controller', $bundle, $controller), sprintf('using the "<info>%s</info>" format for the routing and the "<info>%s</info>" format', $routeFormat, $templateFormat), 'for templating'));
}
示例12: interact
/**
* {@inheritdoc}
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$commandKey = str_replace(':', '.', $this->commandName);
$utils = $this->getStringHelper();
// --module option
$module = $input->getOption('module');
if (!$module) {
// @see Drupal\Console\Command\ModuleTrait::moduleQuestion
$module = $this->moduleQuestion($io);
$input->setOption('module', $module);
}
// --entity-class option
$entityClass = $input->getOption('entity-class');
if (!$entityClass) {
$entityClass = $io->ask($this->trans('commands.' . $commandKey . '.questions.entity-class'), 'DefaultEntity', function ($entityClass) {
return $this->validateSpaces($entityClass);
});
$input->setOption('entity-class', $entityClass);
}
// --entity-name option
$entityName = $input->getOption('entity-name');
if (!$entityName) {
$entityName = $io->ask($this->trans('commands.' . $commandKey . '.questions.entity-name'), $utils->camelCaseToMachineName($entityClass), function ($entityName) {
return $this->validateMachineName($entityName);
});
$input->setOption('entity-name', $entityName);
}
// --label option
$label = $input->getOption('label');
if (!$label) {
$label = $io->ask($this->trans('commands.' . $commandKey . '.questions.label'), $utils->camelCaseToHuman($entityClass));
$input->setOption('label', $label);
}
}
示例13: interact
protected function interact(InputInterface $input, OutputInterface $output)
{
$output = new DrupalStyle($input, $output);
// --module option
$module = $input->getOption('module');
if (!$module) {
// @see Drupal\Console\Command\ModuleTrait::moduleQuestion
$module = $this->moduleQuestion($output);
$input->setOption('module', $module);
}
// --class option
$class_name = $input->getOption('class');
if (!$class_name) {
$class_name = $output->ask($this->trans('commands.generate.plugin.views.field.questions.class'), 'CustomViewsField');
}
$input->setOption('class', $class_name);
// --title option
$title = $input->getOption('title');
if (!$title) {
$title = $output->ask($this->trans('commands.generate.plugin.views.field.questions.title'), $this->getStringHelper()->camelCaseToHuman($class_name));
$input->setOption('title', $title);
}
// --description option
$description = $input->getOption('description');
if (!$description) {
$description = $output->ask($this->trans('commands.generate.plugin.views.field.questions.description'), $this->trans('commands.generate.plugin.views.field.questions.description_default'));
$input->setOption('description', $description);
}
}
示例14: interact
protected function interact(InputInterface $input, OutputInterface $output)
{
$dialog = $this->getDialogHelper();
$dialog->writeSection($output, 'Welcome to the Symfony2 admin generator');
$output->writeln('<comment>Create controllers for a generator module</comment>');
$generator = $dialog->askAndValidate($output, $dialog->getQuestion('Generator to use (doctrine, doctrine_odm, propel)', $input->getOption('generator')), function ($generator) {
if (!in_array($generator, array('doctrine', 'doctrine_odm', 'propel'))) {
throw new \RuntimeException('Generator to use have to be doctrine, doctrine_odm or propel');
}
return $generator;
}, false, $input->getOption('generator'));
$input->setOption('generator', $generator);
$namespace = $dialog->askAndValidate($output, $dialog->getQuestion('Bundle namespace', $input->getOption('namespace')), array('Sensio\\Bundle\\GeneratorBundle\\Command\\Validators', 'validateBundleNamespace'), false, $input->getOption('namespace'));
$input->setOption('namespace', $namespace);
// bundle name
$bundle = $input->getOption('bundle-name') ?: strtr($namespace, array('\\Bundle\\' => '', '\\' => ''));
$output->writeln(array('', 'In your code, a bundle is often referenced by its name. It can be the', 'concatenation of all namespace parts but it\'s really up to you to come', 'up with a unique name (a good practice is to start with the vendor name).', 'Based on the namespace, we suggest <comment>' . $bundle . '</comment>.', ''));
$bundle = $dialog->askAndValidate($output, $dialog->getQuestion('Bundle name', $bundle), array('Sensio\\Bundle\\GeneratorBundle\\Command\\Validators', 'validateBundleName'), false, $bundle);
$input->setOption('bundle-name', $bundle);
// target dir
$dir = $input->getOption('dir') ?: dirname($this->getContainer()->getParameter('kernel.root_dir')) . '/src';
$output->writeln(array('', 'The bundle can be generated anywhere. The suggested default directory uses', 'the standard conventions.', ''));
$dir = $dialog->askAndValidate($output, $dialog->getQuestion('Target directory', $dir), function ($dir) use($bundle, $namespace) {
return Validators::validateTargetDir($dir, $bundle, $namespace);
}, false, $dir);
$input->setOption('dir', $dir);
// prefix
$prefix = $dialog->askAndValidate($output, $dialog->getQuestion('Prefix of yaml', $input->getOption('prefix')), function ($prefix) {
if (!preg_match('/([a-z]+)/i', $prefix)) {
throw new \RuntimeException('Prefix have to be a simple word');
}
return $prefix;
}, false, $input->getOption('prefix'));
$input->setOption('prefix', $prefix);
}
示例15: interact
protected function interact(InputInterface $input, OutputInterface $output)
{
$dialog = $this->getDialogHelper();
$moduleHandler = $this->getModuleHandler();
// --module option
$module = $input->getOption('module');
if (!$module) {
// @see Drupal\Console\Command\ModuleTrait::moduleQuestion
$module = $this->moduleQuestion($output, $dialog);
}
$input->setOption('module', $module);
// --class-name option
$form_id = $input->getOption('form-id');
if (!$form_id) {
$forms = [];
if ($moduleHandler->moduleExists('webprofiler')) {
$output->writeln('[-] <info>' . $this->trans('commands.generate.form.alter.messages.loading-forms') . '</info>');
$forms = $this->getWebprofilerForms();
}
$form_id = $dialog->askAndValidate($output, $dialog->getQuestion($this->trans('commands.generate.form.alter.options.form-id'), current(array_keys($forms))), function ($form) {
return $form;
}, false, '', array_combine(array_keys($forms), array_keys($forms)));
}
$input->setOption('form-id', $form_id);
$output->writeln($this->trans('commands.generate.form.alter.messages.inputs'));
// @see Drupal\Console\Command\FormTrait::formQuestion
$form = $this->formQuestion($output, $dialog);
$input->setOption('inputs', $form);
}