本文整理汇总了PHP中Symfony\Component\Console\Input\InputDefinition::getOptions方法的典型用法代码示例。如果您正苦于以下问题:PHP InputDefinition::getOptions方法的具体用法?PHP InputDefinition::getOptions怎么用?PHP InputDefinition::getOptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Console\Input\InputDefinition
的用法示例。
在下文中一共展示了InputDefinition::getOptions方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: describeInputDefinition
/**
* {@inheritdoc}
*/
protected function describeInputDefinition(InputDefinition $definition, array $options = array())
{
$nameWidth = 0;
foreach ($definition->getOptions() as $option) {
$nameLength = strlen($option->getName()) + 2;
if ($option->getShortcut()) {
$nameLength += strlen($option->getShortcut()) + 3;
}
$nameWidth = max($nameWidth, $nameLength);
}
foreach ($definition->getArguments() as $argument) {
$nameWidth = max($nameWidth, strlen($argument->getName()));
}
++$nameWidth;
if ($definition->getArguments()) {
$this->writeText('<comment>Arguments:</comment>', $options);
$this->writeText("\n");
foreach ($definition->getArguments() as $argument) {
$this->describeInputArgument($argument, array_merge($options, array('name_width' => $nameWidth)));
$this->writeText("\n");
}
}
if ($definition->getArguments() && $definition->getOptions()) {
$this->writeText("\n");
}
if ($definition->getOptions()) {
$this->writeText('<comment>Options:</comment>', $options);
$this->writeText("\n");
foreach ($definition->getOptions() as $option) {
$this->describeInputOption($option, array_merge($options, array('name_width' => $nameWidth)));
$this->writeText("\n");
}
}
}
示例2: describeInputDefinition
/**
* {@inheritdoc}
*/
protected function describeInputDefinition(InputDefinition $definition, array $options = array())
{
$totalWidth = $this->calculateTotalWidthForOptions($definition->getOptions());
foreach ($definition->getArguments() as $argument) {
$totalWidth = max($totalWidth, strlen($argument->getName()));
}
if ($definition->getArguments()) {
$this->writeText('<comment>Arguments:</comment>', $options);
$this->writeText("\n");
foreach ($definition->getArguments() as $argument) {
$this->describeInputArgument($argument, array_merge($options, array('total_width' => $totalWidth)));
$this->writeText("\n");
}
}
if ($definition->getArguments() && $definition->getOptions()) {
$this->writeText("\n");
}
if ($definition->getOptions()) {
$laterOptions = array();
$this->writeText('<comment>Options:</comment>', $options);
foreach ($definition->getOptions() as $option) {
if (strlen($option->getShortcut()) > 1) {
$laterOptions[] = $option;
continue;
}
$this->writeText("\n");
$this->describeInputOption($option, array_merge($options, array('total_width' => $totalWidth)));
}
foreach ($laterOptions as $option) {
$this->writeText("\n");
$this->describeInputOption($option, array_merge($options, array('total_width' => $totalWidth)));
}
}
}
示例3: startWorkers
/**
* Start workers, put master port, server name to run on, and options stuff.
*/
public function startWorkers()
{
// Get verbosity.
$verbosity = new VerbosityString($this->output);
// Get current deploy.php file.
$deployPhpFile = $this->input->getOption('file');
// User input.
$input = '';
// Get user arguments.
foreach ($this->userDefinition->getArguments() as $argument) {
$value = $this->input->getArgument($argument->getName());
if ($value) {
$input .= " {$value}";
}
}
// Get user options.
foreach ($this->userDefinition->getOptions() as $option) {
$value = $this->input->getOption($option->getName());
if ($value) {
$input .= " --{$option->getName()} {$value}";
}
}
foreach ($this->servers as $serverName => $server) {
$process = new Process("php " . DEPLOYER_BIN . (null === $deployPhpFile ? "" : " --file={$deployPhpFile}") . " worker " . " --master 127.0.0.1:{$this->port}" . " --server {$serverName}" . " {$input} " . " {$verbosity}" . " &");
$process->disableOutput();
$process->start();
}
}
示例4: init
/**
* @param InputDefinition $inputDefinition
* @param InputInterface $input
*/
public function init(InputDefinition $inputDefinition, InputInterface $input)
{
$options = new ProcessOptionCollection();
foreach ($inputDefinition->getOptions() as $optionName => $inputOption) {
$optionValue = $input->getOption($optionName);
if ($inputOption->getDefault() != $optionValue) {
switch (true) {
case in_array($optionName, $this->skipOptions):
$option = null;
break;
case $inputOption->isArray() && $optionName == 'out':
$option = new ProcessOptionOut($optionName, $optionValue);
break;
case $inputOption->isArray():
$option = new ProcessOptionArray($optionName, $optionValue);
break;
case $inputOption->isValueRequired():
case $inputOption->isValueOptional():
$option = new ProcessOptionScalar($optionName, $optionValue);
break;
default:
$option = new ProcessOption($optionName);
}
if ($option) {
$options->set($option);
}
}
}
$this->optionCollection = $options;
}
示例5: describeInputDefinition
/**
* {@inheritdoc}
*/
protected function describeInputDefinition(InputDefinition $definition, array $options = array())
{
$blocks = array();
if (count($definition->getArguments()) > 0) {
$blocks[] = '### Arguments:';
foreach ($definition->getArguments() as $argument) {
$blocks[] = $this->describeInputArgument($argument);
}
}
if (count($definition->getOptions()) > 0) {
$blocks[] = '### Options:';
foreach ($definition->getOptions() as $option) {
$blocks[] = $this->describeInputOption($option);
}
}
return implode("\n\n", $blocks);
}
示例6: describeInputDefinition
/**
* {@inheritdoc}
*/
protected function describeInputDefinition(InputDefinition $definition, array $options = array())
{
if ($showArguments = count($definition->getArguments()) > 0) {
$this->write('### Arguments:');
foreach ($definition->getArguments() as $argument) {
$this->write("\n\n");
$this->write($this->describeInputArgument($argument));
}
}
if (count($definition->getOptions()) > 0) {
if ($showArguments) {
$this->write("\n\n");
}
$this->write('### Options:');
foreach ($definition->getOptions() as $option) {
$this->write("\n\n");
$this->write($this->describeInputOption($option));
}
}
}
示例7: let
function let(CommandCollection $collection, Command $command1, Command $command2, InputDefinition $inputDefinition, InputDefinition $inputDefinition2, InputOption $inputOption, InputOption $inputOption2)
{
$inputDefinition->getOptions()->willReturn(['option1' => $inputOption, 'option2' => $inputOption2]);
$command1->getName()->willReturn('test:command');
$command1->getDefinition()->willReturn($inputDefinition);
$inputDefinition2->getOptions()->willReturn([]);
$command2->getName()->willReturn('other-command');
$command2->getDefinition()->willReturn($inputDefinition2);
$collection->getItems()->willReturn(['test:command' => $command1, 'other-command' => $command2]);
$this->beConstructedWith($collection);
}
示例8: describeInputDefinition
/**
* {@inheritdoc}
*/
protected function describeInputDefinition(InputDefinition $definition, array $options = array())
{
$inputArguments = array();
foreach ($definition->getArguments() as $name => $argument) {
$inputArguments[$name] = $this->describeInputArgument($argument, array('as_array' => true));
}
$inputOptions = array();
foreach ($definition->getOptions() as $name => $option) {
$inputOptions[$name] = $this->describeInputOption($option, array('as_array' => true));
}
return $this->output(array('arguments' => $inputArguments, 'options' => $inputOptions), $options);
}
示例9: getInputDefinitionData
private function getInputDefinitionData(InputDefinition $definition)
{
$inputArguments = array();
foreach ($definition->getArguments() as $name => $argument) {
$inputArguments[$name] = $this->getInputArgumentData($argument);
}
$inputOptions = array();
foreach ($definition->getOptions() as $name => $option) {
$inputOptions[$name] = $this->getInputOptionData($option);
}
return array('arguments' => $inputArguments, 'options' => $inputOptions);
}
示例10: getInputDefinitionDocument
/**
* @param InputDefinition $definition
*
* @return \DOMDocument
*/
public function getInputDefinitionDocument(InputDefinition $definition)
{
$dom = new \DOMDocument('1.0', 'UTF-8');
$dom->appendChild($definitionXML = $dom->createElement('definition'));
$definitionXML->appendChild($argumentsXML = $dom->createElement('arguments'));
foreach ($definition->getArguments() as $argument) {
$this->appendDocument($argumentsXML, $this->getInputArgumentDocument($argument));
}
$definitionXML->appendChild($optionsXML = $dom->createElement('options'));
foreach ($definition->getOptions() as $option) {
$this->appendDocument($optionsXML, $this->getInputOptionDocument($option));
}
return $dom;
}
示例11: resolveInputDefinition
/**
* @return array Values for given InputDefinition, optionally filtered
*/
public function resolveInputDefinition(InputDefinition $inputDefinition, array $filter = [])
{
$values = [];
$arguments = array_filter($inputDefinition->getArguments(), function (InputArgument $argument) use($filter) {
return !count($filter) || in_array($argument->getName(), $filter);
});
$options = array_filter($inputDefinition->getOptions(), function (InputOption $option) use($filter) {
return !count($filter) || in_array($option->getName(), $filter);
});
foreach ($arguments as $argument) {
$values[$argument->getName()] = $this->input->getArgument($argument->getName());
}
foreach ($options as $option) {
$values[$option->getName()] = $this->getOptionValue($option);
}
return $values;
}
示例12: startWorkers
/**
* Start workers, put master port, server name to run on, and options stuff.
*/
public function startWorkers()
{
$input = ['--master' => '127.0.0.1:' . $this->port, '--server' => ''];
// Get verbosity.
$verbosity = new VerbosityString($this->output);
// Get current deploy.php file.
$deployPhpFile = $this->input->getOption('file');
// Get user arguments.
foreach ($this->userDefinition->getArguments() as $argument) {
$input[$argument->getName()] = $this->input->getArgument($argument->getName());
}
// Get user options.
foreach ($this->userDefinition->getOptions() as $option) {
$input["--" . $option->getName()] = $this->input->getOption($option->getName());
}
foreach ($this->servers as $serverName => $server) {
$input['--server'] = $serverName;
$process = new Process("php " . DEPLOYER_BIN . (null === $deployPhpFile ? "" : " --file={$deployPhpFile}") . " worker " . new ArrayInput($input) . " {$verbosity}" . " &");
$process->disableOutput();
$process->run();
}
}
示例13: testAddOption
public function testAddOption()
{
$this->initializeOptions();
$definition = new InputDefinition();
$definition->addOption($this->foo);
$this->assertEquals(array('foo' => $this->foo), $definition->getOptions(), '->addOption() adds a InputOption object');
$definition->addOption($this->bar);
$this->assertEquals(array('foo' => $this->foo, 'bar' => $this->bar), $definition->getOptions(), '->addOption() adds a InputOption object');
}
示例14: testAddOption
public function testAddOption()
{
$this->initializeOptions();
$definition = new InputDefinition();
$definition->addOption($this->foo);
$this->assertEquals(array('foo' => $this->foo), $definition->getOptions(), '->addOption() adds a InputOption object');
$definition->addOption($this->bar);
$this->assertEquals(array('foo' => $this->foo, 'bar' => $this->bar), $definition->getOptions(), '->addOption() adds a InputOption object');
try {
$definition->addOption($this->foo2);
$this->fail('->addOption() throws a Exception if the another option is already registered with the same name');
} catch (\Exception $e) {
$this->assertInstanceOf('\\Exception', $e, '->addOption() throws a Exception if the another option is already registered with the same name');
$this->assertEquals('An option named "foo" already exist.', $e->getMessage());
}
try {
$definition->addOption($this->foo1);
$this->fail('->addOption() throws a Exception if the another option is already registered with the same shortcut');
} catch (\Exception $e) {
$this->assertInstanceOf('\\Exception', $e, '->addOption() throws a Exception if the another option is already registered with the same shortcut');
$this->assertEquals('An option with shortcut "f" already exist.', $e->getMessage());
}
}