本文整理汇总了PHP中Symfony\Component\Console\Input\ArrayInput::getOption方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayInput::getOption方法的具体用法?PHP ArrayInput::getOption怎么用?PHP ArrayInput::getOption使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Console\Input\ArrayInput
的用法示例。
在下文中一共展示了ArrayInput::getOption方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testOptions
public function testOptions()
{
$input = new ArrayInput(array('--name' => 'foo'), new InputDefinition(array(new InputOption('name'))));
$this->assertEquals('foo', $input->getOption('name'), '->getOption() returns the value for the given option');
$input->setOption('name', 'bar');
$this->assertEquals('bar', $input->getOption('name'), '->setOption() sets the value for a given option');
$this->assertEquals(array('name' => 'bar'), $input->getOptions(), '->getOptions() returns all option values');
$input = new ArrayInput(array('--name' => 'foo'), new InputDefinition(array(new InputOption('name'), new InputOption('bar', '', InputOption::VALUE_OPTIONAL, '', 'default'))));
$this->assertEquals('default', $input->getOption('bar'), '->getOption() returns the default value for optional options');
$this->assertEquals(array('name' => 'foo', 'bar' => 'default'), $input->getOptions(), '->getOptions() returns all option values, even optional ones');
try {
$input->setOption('foo', 'bar');
$this->fail('->setOption() throws a \\InvalidArgumentException if the option does not exist');
} catch (\Exception $e) {
$this->assertInstanceOf('\\InvalidArgumentException', $e, '->setOption() throws a \\InvalidArgumentException if the option does not exist');
$this->assertEquals('The "foo" option does not exist.', $e->getMessage());
}
try {
$input->getOption('foo');
$this->fail('->getOption() throws a \\InvalidArgumentException if the option does not exist');
} catch (\Exception $e) {
$this->assertInstanceOf('\\InvalidArgumentException', $e, '->setOption() throws a \\InvalidArgumentException if the option does not exist');
$this->assertEquals('The "foo" option does not exist.', $e->getMessage());
}
}
示例2: execute
/**
* Initialize the command and determine which path to take
*
* @param InputInterface $input
* @param OutputInterface $output
* @internal param $ Symfony\Component\Console\Input\InputInterface
* @internal param $ Symfony\Component\Console\Output\OutputInterface
* @return void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
parent::execute($input, $output);
switch ($this->input->getArgument('key')) {
case 'folder':
$this->newFolder();
break;
case 'site':
$this->newSite();
break;
case 'database':
$this->newDatabase();
break;
case 'variable':
$this->newVariable();
break;
case 'list':
$this->listKeys();
break;
default:
$helpCommand = $this->getApplication()->find('config:new');
$input = new ArrayInput(['key' => 'list', '--file' => $input->getOption('file')]);
$helpCommand->run($input, $output);
break;
}
}
示例3: testGetInvalidOption
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage The "foo" option does not exist.
*/
public function testGetInvalidOption()
{
$input = new ArrayInput(array('--name' => 'foo'), new InputDefinition(array(new InputOption('name'), new InputOption('bar', '', InputOption::VALUE_OPTIONAL, '', 'default'))));
$input->getOption('foo');
}
示例4: executeCommand
/**
* @param ScheduledCommand $scheduledCommand
* @param OutputInterface $output
* @param InputInterface $input
*/
private function executeCommand(ScheduledCommand $scheduledCommand, OutputInterface $output, InputInterface $input)
{
$scheduledCommand = $this->em->merge($scheduledCommand);
$scheduledCommand->setLastExecution(new \DateTime());
$scheduledCommand->setLocked(true);
$this->em->flush();
try {
$command = $this->getApplication()->find($scheduledCommand->getCommand());
} catch (\InvalidArgumentException $e) {
$scheduledCommand->setLastReturnCode(-1);
$output->writeln('<error>Cannot find ' . $scheduledCommand->getCommand() . '</error>');
return;
}
$input = new ArrayInput(array_merge(array('command' => $scheduledCommand->getCommand(), '--env' => $input->getOption('env')), $scheduledCommand->getArguments(true)));
// Use a StreamOutput or NullOutput to redirect write() and writeln() in a log file
if (false === $this->logPath && "" != $scheduledCommand->getLogFile()) {
$logOutput = new NullOutput();
} else {
$logOutput = new StreamOutput(fopen($this->logPath . $scheduledCommand->getLogFile(), 'a', false), $this->commandsVerbosity);
}
// Execute command and get return code
try {
$output->writeln('<info>Execute</info> : <comment>' . $scheduledCommand->getCommand() . ' ' . $scheduledCommand->getArguments() . '</comment>');
$result = $command->run($input, $logOutput);
} catch (\Exception $e) {
$logOutput->writeln($e->getMessage());
$logOutput->writeln($e->getTraceAsString());
$result = -1;
}
if (false === $this->em->isOpen()) {
$output->writeln('<comment>Entity manager closed by the last command.</comment>');
$this->em = $this->em->create($this->em->getConnection(), $this->em->getConfiguration());
}
$scheduledCommand = $this->em->merge($scheduledCommand);
$scheduledCommand->setLastReturnCode($result);
$scheduledCommand->setLocked(false);
$scheduledCommand->setExecuteImmediately(false);
$this->em->flush();
/*
* This clear() is necessary to avoid conflict between commands and to be sure that none entity are managed
* before entering in a new command
*/
$this->em->clear();
unset($command);
gc_collect_cycles();
}
示例5: install
/**
* @param OutputInterface $output
*
* @return int 0 on success
*/
protected function install(OutputInterface $output)
{
$io = $this->getIO();
$composer = $this->getComposer(true, false);
$composer->getDownloadManager()->setOutputProgress(true);
$input = new ArrayInput([], (new InstallCommand())->getDefinition());
$commandEvent = new CommandEvent(PluginEvents::COMMAND, 'install', $input, $output);
$composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
$install = Installer::create($io, $composer);
$preferSource = false;
$preferDist = false;
$config = $composer->getConfig();
switch ($config->get('preferred-install')) {
case 'source':
$preferSource = true;
break;
case 'dist':
$preferDist = true;
break;
case 'auto':
default:
// noop
break;
}
$install->setDryRun(false)->setVerbose(false)->setPreferSource($preferSource)->setPreferDist($preferDist)->setDevMode(true)->setDumpAutoloader(true)->setRunScripts(!$input->getOption('no-scripts'))->setOptimizeAutoloader(false)->setClassMapAuthoritative(false)->setIgnorePlatformRequirements(false);
return $install->run();
}