当前位置: 首页>>代码示例>>PHP>>正文


PHP ArgvInput::getOptions方法代码示例

本文整理汇总了PHP中Symfony\Component\Console\Input\ArgvInput::getOptions方法的典型用法代码示例。如果您正苦于以下问题:PHP ArgvInput::getOptions方法的具体用法?PHP ArgvInput::getOptions怎么用?PHP ArgvInput::getOptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Console\Input\ArgvInput的用法示例。


在下文中一共展示了ArgvInput::getOptions方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getOptions

 /**
  * @return array
  */
 public function getOptions()
 {
     $options = parent::getOptions();
     foreach ($options as $key => $value) {
         $options[$key] = $this->removeEqualsSign($value);
         $options[$key] = $this->splitByComma($value);
     }
     return $options;
 }
开发者ID:nunodotferreira,项目名称:ApiGen,代码行数:12,代码来源:LiberalFormatArgvInput.php

示例2: testParser

 public function testParser()
 {
     $input = new ArgvInput(array('cli.php', 'foo'));
     $input->bind(new InputDefinition(array(new InputArgument('name'))));
     $this->assertEquals(array('name' => 'foo'), $input->getArguments(), '->parse() parses required arguments');
     $input->bind(new InputDefinition(array(new InputArgument('name'))));
     $this->assertEquals(array('name' => 'foo'), $input->getArguments(), '->parse() is stateless');
     $input = new ArgvInput(array('cli.php', '--foo'));
     $input->bind(new InputDefinition(array(new InputOption('foo'))));
     $this->assertEquals(array('foo' => true), $input->getOptions(), '->parse() parses long options without a value');
     $input = new ArgvInput(array('cli.php', '--foo=bar'));
     $input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_REQUIRED))));
     $this->assertEquals(array('foo' => 'bar'), $input->getOptions(), '->parse() parses long options with a required value (with a = separator)');
     $input = new ArgvInput(array('cli.php', '--foo', 'bar'));
     $input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_REQUIRED))));
     $this->assertEquals(array('foo' => 'bar'), $input->getOptions(), '->parse() parses long options with a required value (with a space separator)');
     try {
         $input = new ArgvInput(array('cli.php', '--foo'));
         $input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_REQUIRED))));
         $this->fail('->parse() throws a \\RuntimeException if no value is passed to an option when it is required');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\RuntimeException', $e, '->parse() throws a \\RuntimeException if no value is passed to an option when it is required');
         $this->assertEquals('The "--foo" option requires a value.', $e->getMessage(), '->parse() throws a \\RuntimeException if no value is passed to an option when it is required');
     }
     $input = new ArgvInput(array('cli.php', '-f'));
     $input->bind(new InputDefinition(array(new InputOption('foo', 'f'))));
     $this->assertEquals(array('foo' => true), $input->getOptions(), '->parse() parses short options without a value');
     $input = new ArgvInput(array('cli.php', '-fbar'));
     $input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_REQUIRED))));
     $this->assertEquals(array('foo' => 'bar'), $input->getOptions(), '->parse() parses short options with a required value (with no separator)');
     $input = new ArgvInput(array('cli.php', '-f', 'bar'));
     $input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_REQUIRED))));
     $this->assertEquals(array('foo' => 'bar'), $input->getOptions(), '->parse() parses short options with a required value (with a space separator)');
     $input = new ArgvInput(array('cli.php', '-f', ''));
     $input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL))));
     $this->assertEquals(array('foo' => ''), $input->getOptions(), '->parse() parses short options with an optional empty value');
     $input = new ArgvInput(array('cli.php', '-f', '', 'foo'));
     $input->bind(new InputDefinition(array(new InputArgument('name'), new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL))));
     $this->assertEquals(array('foo' => ''), $input->getOptions(), '->parse() parses short options with an optional empty value followed by an argument');
     $input = new ArgvInput(array('cli.php', '-f', '', '-b'));
     $input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL), new InputOption('bar', 'b'))));
     $this->assertEquals(array('foo' => '', 'bar' => true), $input->getOptions(), '->parse() parses short options with an optional empty value followed by an option');
     $input = new ArgvInput(array('cli.php', '-f', '-b', 'foo'));
     $input->bind(new InputDefinition(array(new InputArgument('name'), new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL), new InputOption('bar', 'b'))));
     $this->assertEquals(array('foo' => null, 'bar' => true), $input->getOptions(), '->parse() parses short options with an optional value which is not present');
     try {
         $input = new ArgvInput(array('cli.php', '-f'));
         $input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_REQUIRED))));
         $this->fail('->parse() throws a \\RuntimeException if no value is passed to an option when it is required');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\RuntimeException', $e, '->parse() throws a \\RuntimeException if no value is passed to an option when it is required');
         $this->assertEquals('The "--foo" option requires a value.', $e->getMessage(), '->parse() throws a \\RuntimeException if no value is passed to an option when it is required');
     }
     try {
         $input = new ArgvInput(array('cli.php', '-ffoo'));
         $input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_NONE))));
         $this->fail('->parse() throws a \\RuntimeException if a value is passed to an option which does not take one');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\RuntimeException', $e, '->parse() throws a \\RuntimeException if a value is passed to an option which does not take one');
         $this->assertEquals('The "-o" option does not exist.', $e->getMessage(), '->parse() throws a \\RuntimeException if a value is passed to an option which does not take one');
     }
     try {
         $input = new ArgvInput(array('cli.php', '--foo=bar'));
         $input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_NONE))));
         $this->fail('->parse() throws a \\RuntimeException if a value is passed to an option which does not take one');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\RuntimeException', $e, '->parse() throws a \\RuntimeException if a value is passed to an option which does not take one');
         $this->assertEquals('The "--foo" option does not accept a value.', $e->getMessage(), '->parse() throws a \\RuntimeException if a value is passed to an option which does not take one');
     }
     try {
         $input = new ArgvInput(array('cli.php', 'foo', 'bar'));
         $input->bind(new InputDefinition());
         $this->fail('->parse() throws a \\RuntimeException if too many arguments are passed');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\RuntimeException', $e, '->parse() throws a \\RuntimeException if too many arguments are passed');
         $this->assertEquals('Too many arguments.', $e->getMessage(), '->parse() throws a \\RuntimeException if too many arguments are passed');
     }
     try {
         $input = new ArgvInput(array('cli.php', '--foo'));
         $input->bind(new InputDefinition());
         $this->fail('->parse() throws a \\RuntimeException if an unknown long option is passed');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\RuntimeException', $e, '->parse() throws a \\RuntimeException if an unknown long option is passed');
         $this->assertEquals('The "--foo" option does not exist.', $e->getMessage(), '->parse() throws a \\RuntimeException if an unknown long option is passed');
     }
     try {
         $input = new ArgvInput(array('cli.php', '-f'));
         $input->bind(new InputDefinition());
         $this->fail('->parse() throws a \\RuntimeException if an unknown short option is passed');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\RuntimeException', $e, '->parse() throws a \\RuntimeException if an unknown short option is passed');
         $this->assertEquals('The "-f" option does not exist.', $e->getMessage(), '->parse() throws a \\RuntimeException if an unknown short option is passed');
     }
     $input = new ArgvInput(array('cli.php', '-fb'));
     $input->bind(new InputDefinition(array(new InputOption('foo', 'f'), new InputOption('bar', 'b'))));
     $this->assertEquals(array('foo' => true, 'bar' => true), $input->getOptions(), '->parse() parses short options when they are aggregated as a single one');
     $input = new ArgvInput(array('cli.php', '-fb', 'bar'));
     $input->bind(new InputDefinition(array(new InputOption('foo', 'f'), new InputOption('bar', 'b', InputOption::VALUE_REQUIRED))));
     $this->assertEquals(array('foo' => true, 'bar' => 'bar'), $input->getOptions(), '->parse() parses short options when they are aggregated as a single one and the last one has a required value');
     $input = new ArgvInput(array('cli.php', '-fb', 'bar'));
//.........这里部分代码省略.........
开发者ID:ronaldlunaramos,项目名称:webstore,代码行数:101,代码来源:ArgvInputTest.php

示例3: testParser

 public function testParser()
 {
     $input = new ArgvInput(array('cli.php', 'foo'));
     $input->bind(new InputDefinition(array(new InputArgument('name'))));
     $this->assertEquals(array('name' => 'foo'), $input->getArguments(), '->parse() parses required arguments');
     $input->bind(new InputDefinition(array(new InputArgument('name'))));
     $this->assertEquals(array('name' => 'foo'), $input->getArguments(), '->parse() is stateless');
     $input = new ArgvInput(array('cli.php', '--foo'));
     $input->bind(new InputDefinition(array(new InputOption('foo'))));
     $this->assertEquals(array('foo' => true), $input->getOptions(), '->parse() parses long options without a value');
     $input = new ArgvInput(array('cli.php', '--foo=bar'));
     $input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_REQUIRED))));
     $this->assertEquals(array('foo' => 'bar'), $input->getOptions(), '->parse() parses long options with a required value (with a = separator)');
     $input = new ArgvInput(array('cli.php', '--foo', 'bar'));
     $input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_REQUIRED))));
     $this->assertEquals(array('foo' => 'bar'), $input->getOptions(), '->parse() parses long options with a required value (with a space separator)');
     try {
         $input = new ArgvInput(array('cli.php', '--foo'));
         $input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_REQUIRED))));
         $this->fail('->parse() throws a \\RuntimeException if no value is passed to an option when it is required');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\RuntimeException', $e, '->parse() throws a \\RuntimeException if no value is passed to an option when it is required');
         $this->assertEquals('The "--foo" option requires a value.', $e->getMessage(), '->parse() throws a \\RuntimeException if no value is passed to an option when it is required');
     }
     $input = new ArgvInput(array('cli.php', '-f'));
     $input->bind(new InputDefinition(array(new InputOption('foo', 'f'))));
     $this->assertEquals(array('foo' => true), $input->getOptions(), '->parse() parses short options without a value');
     $input = new ArgvInput(array('cli.php', '-fbar'));
     $input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_REQUIRED))));
     $this->assertEquals(array('foo' => 'bar'), $input->getOptions(), '->parse() parses short options with a required value (with no separator)');
     $input = new ArgvInput(array('cli.php', '-f', 'bar'));
     $input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_REQUIRED))));
     $this->assertEquals(array('foo' => 'bar'), $input->getOptions(), '->parse() parses short options with a required value (with a space separator)');
     $input = new ArgvInput(array('cli.php', '-f', '-b', 'foo'));
     $input->bind(new InputDefinition(array(new InputArgument('name'), new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL), new InputOption('bar', 'b'))));
     $this->assertEquals(array('foo' => null, 'bar' => true), $input->getOptions(), '->parse() parses short options with an optional value which is not present');
     try {
         $input = new ArgvInput(array('cli.php', '-f'));
         $input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_REQUIRED))));
         $this->fail('->parse() throws a \\RuntimeException if no value is passed to an option when it is required');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\RuntimeException', $e, '->parse() throws a \\RuntimeException if no value is passed to an option when it is required');
         $this->assertEquals('The "--foo" option requires a value.', $e->getMessage(), '->parse() throws a \\RuntimeException if no value is passed to an option when it is required');
     }
     try {
         $input = new ArgvInput(array('cli.php', '-ffoo'));
         $input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_NONE))));
         $this->fail('->parse() throws a \\RuntimeException if a value is passed to an option which does not take one');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\RuntimeException', $e, '->parse() throws a \\RuntimeException if a value is passed to an option which does not take one');
         $this->assertEquals('The "-o" option does not exist.', $e->getMessage(), '->parse() throws a \\RuntimeException if a value is passed to an option which does not take one');
     }
     try {
         $input = new ArgvInput(array('cli.php', 'foo', 'bar'));
         $input->bind(new InputDefinition());
         $this->fail('->parse() throws a \\RuntimeException if too many arguments are passed');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\RuntimeException', $e, '->parse() throws a \\RuntimeException if too many arguments are passed');
         $this->assertEquals('Too many arguments.', $e->getMessage(), '->parse() throws a \\RuntimeException if too many arguments are passed');
     }
     try {
         $input = new ArgvInput(array('cli.php', '--foo'));
         $input->bind(new InputDefinition());
         $this->fail('->parse() throws a \\RuntimeException if an unknown long option is passed');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\RuntimeException', $e, '->parse() throws a \\RuntimeException if an unknown long option is passed');
         $this->assertEquals('The "--foo" option does not exist.', $e->getMessage(), '->parse() throws a \\RuntimeException if an unknown long option is passed');
     }
     try {
         $input = new ArgvInput(array('cli.php', '-f'));
         $input->bind(new InputDefinition());
         $this->fail('->parse() throws a \\RuntimeException if an unknown short option is passed');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\RuntimeException', $e, '->parse() throws a \\RuntimeException if an unknown short option is passed');
         $this->assertEquals('The "-f" option does not exist.', $e->getMessage(), '->parse() throws a \\RuntimeException if an unknown short option is passed');
     }
     $input = new ArgvInput(array('cli.php', '-fb'));
     $input->bind(new InputDefinition(array(new InputOption('foo', 'f'), new InputOption('bar', 'b'))));
     $this->assertEquals(array('foo' => true, 'bar' => true), $input->getOptions(), '->parse() parses short options when they are aggregated as a single one');
     $input = new ArgvInput(array('cli.php', '-fb', 'bar'));
     $input->bind(new InputDefinition(array(new InputOption('foo', 'f'), new InputOption('bar', 'b', InputOption::VALUE_REQUIRED))));
     $this->assertEquals(array('foo' => true, 'bar' => 'bar'), $input->getOptions(), '->parse() parses short options when they are aggregated as a single one and the last one has a required value');
     $input = new ArgvInput(array('cli.php', '-fb', 'bar'));
     $input->bind(new InputDefinition(array(new InputOption('foo', 'f'), new InputOption('bar', 'b', InputOption::VALUE_OPTIONAL))));
     $this->assertEquals(array('foo' => true, 'bar' => 'bar'), $input->getOptions(), '->parse() parses short options when they are aggregated as a single one and the last one has an optional value');
     $input = new ArgvInput(array('cli.php', '-fbbar'));
     $input->bind(new InputDefinition(array(new InputOption('foo', 'f'), new InputOption('bar', 'b', InputOption::VALUE_OPTIONAL))));
     $this->assertEquals(array('foo' => true, 'bar' => 'bar'), $input->getOptions(), '->parse() parses short options when they are aggregated as a single one and the last one has an optional value with no separator');
     $input = new ArgvInput(array('cli.php', '-fbbar'));
     $input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL), new InputOption('bar', 'b', InputOption::VALUE_OPTIONAL))));
     $this->assertEquals(array('foo' => 'bbar', 'bar' => null), $input->getOptions(), '->parse() parses short options when they are aggregated as a single one and one of them takes a value');
     try {
         $input = new ArgvInput(array('cli.php', 'foo', 'bar', 'baz', 'bat'));
         $input->bind(new InputDefinition(array(new InputArgument('name', InputArgument::IS_ARRAY))));
         $this->assertEquals(array('name' => array('foo', 'bar', 'baz', 'bat')), $input->getArguments(), '->parse() parses array arguments');
     } catch (\RuntimeException $e) {
         $this->assertNotEquals('Too many arguments.', $e->getMessage(), '->parse() parses array arguments');
     }
 }
开发者ID:nickaggarwal,项目名称:sample-symfony2,代码行数:99,代码来源:ArgvInputTest.php

示例4: testParseOptionWithValueOptionalGivenEmptyAndOptionalArgument

 public function testParseOptionWithValueOptionalGivenEmptyAndOptionalArgument()
 {
     $input = new ArgvInput(array('cli.php', '--foo=', 'bar'));
     $input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL), new InputArgument('name', InputArgument::OPTIONAL))));
     $this->assertEquals(array('foo' => null), $input->getOptions(), '->parse() parses optional options with empty value as null');
     $this->assertEquals(array('name' => 'bar'), $input->getArguments(), '->parse() parses optional arguments');
     $input = new ArgvInput(array('cli.php', '--foo=0', 'bar'));
     $input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL), new InputArgument('name', InputArgument::OPTIONAL))));
     $this->assertEquals(array('foo' => '0'), $input->getOptions(), '->parse() parses optional options with empty value as null');
     $this->assertEquals(array('name' => 'bar'), $input->getArguments(), '->parse() parses optional arguments');
 }
开发者ID:heximcz,项目名称:routerboard-backup,代码行数:11,代码来源:ArgvInputTest.php


注:本文中的Symfony\Component\Console\Input\ArgvInput::getOptions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。