本文整理汇总了PHP中Symfony\Component\Console\Input\InputDefinition::getArguments方法的典型用法代码示例。如果您正苦于以下问题:PHP InputDefinition::getArguments方法的具体用法?PHP InputDefinition::getArguments怎么用?PHP InputDefinition::getArguments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Console\Input\InputDefinition
的用法示例。
在下文中一共展示了InputDefinition::getArguments方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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)));
}
}
}
示例2: 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");
}
}
}
示例3: testAddArgument
public function testAddArgument()
{
$this->initializeArguments();
$definition = new InputDefinition();
$definition->addArgument($this->foo);
$this->assertEquals(array('foo' => $this->foo), $definition->getArguments(), '->addArgument() adds a InputArgument object');
$definition->addArgument($this->bar);
$this->assertEquals(array('foo' => $this->foo, 'bar' => $this->bar), $definition->getArguments(), '->addArgument() adds a InputArgument object');
}
示例4: 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();
}
}
示例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: testAddArgument
public function testAddArgument()
{
$this->initializeArguments();
$definition = new InputDefinition();
$definition->addArgument($this->foo);
$this->assertEquals(array('foo' => $this->foo), $definition->getArguments(), '->addArgument() adds a InputArgument object');
$definition->addArgument($this->bar);
$this->assertEquals(array('foo' => $this->foo, 'bar' => $this->bar), $definition->getArguments(), '->addArgument() adds a InputArgument object');
// arguments must have different names
try {
$definition->addArgument($this->foo1);
$this->fail('->addArgument() throws a Exception if another argument is already registered with the same name');
} catch (\Exception $e) {
$this->assertInstanceOf('\Exception', $e, '->addArgument() throws a Exception if another argument is already registered with the same name');
$this->assertEquals('An argument with name "foo" already exist.', $e->getMessage());
}
// cannot add a parameter after an array parameter
$definition->addArgument(new InputArgument('fooarray', InputArgument::IS_ARRAY));
try {
$definition->addArgument(new InputArgument('anotherbar'));
$this->fail('->addArgument() throws a Exception if there is an array parameter already registered');
} catch (\Exception $e) {
$this->assertInstanceOf('\Exception', $e, '->addArgument() throws a Exception if there is an array parameter already registered');
$this->assertEquals('Cannot add an argument after an array argument.', $e->getMessage());
}
// cannot add a required argument after an optional one
$definition = new InputDefinition();
$definition->addArgument($this->foo);
try {
$definition->addArgument($this->foo2);
$this->fail('->addArgument() throws an exception if you try to add a required argument after an optional one');
} catch (\Exception $e) {
$this->assertInstanceOf('\Exception', $e, '->addArgument() throws an exception if you try to add a required argument after an optional one');
$this->assertEquals('Cannot add a required argument after an optional one.', $e->getMessage());
}
}
示例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: describeInputDefinition
/**
* {@inheritdoc}
*/
protected function describeInputDefinition(InputDefinition $definition, array $options = array())
{
$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->describeInputArgument($argument, array('as_dom' => true)));
}
$definitionXML->appendChild($optionsXML = $dom->createElement('options'));
foreach ($definition->getOptions() as $option) {
$this->appendDocument($optionsXML, $this->describeInputOption($option, array('as_dom' => true)));
}
return $this->output($dom, $options);
}
示例12: 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;
}
示例13: 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();
}
}
示例14: getArguments
/**
* @param InputDefinition $definition
* @return array
*/
private function getArguments(InputDefinition $definition) : array
{
$arguments = [];
foreach ($definition->getArguments() as $argument) {
$mode = $this->getArgumentMode($argument);
$arguments[] = new Definition(InputArgument::class, [$argument->getName(), $mode, $argument->getDescription(), $argument->getDefault()]);
}
return $arguments;
}