當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ArgvInput::getArguments方法代碼示例

本文整理匯總了PHP中Symfony\Component\Console\Input\ArgvInput::getArguments方法的典型用法代碼示例。如果您正苦於以下問題:PHP ArgvInput::getArguments方法的具體用法?PHP ArgvInput::getArguments怎麽用?PHP ArgvInput::getArguments使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\Console\Input\ArgvInput的用法示例。


在下文中一共展示了ArgvInput::getArguments方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: 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

示例2: testParseEmptyStringArgument

 public function testParseEmptyStringArgument()
 {
     $input = new ArgvInput(array('cli.php', '-f', 'bar', ''));
     $input->bind(new InputDefinition(array(new InputArgument('empty'), new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL))));
     $this->assertEquals(array('empty' => ''), $input->getArguments(), '->parse() parses empty string arguments');
 }
開發者ID:nassafou,項目名稱:Filmotheque,代碼行數:6,代碼來源:ArgvInputTest.php

示例3: testParseSingleDashAsArgument

 public function testParseSingleDashAsArgument()
 {
     $input = new ArgvInput(array('cli.php', '-'));
     $input->bind(new InputDefinition(array(new InputArgument('file'))));
     $this->assertEquals(array('file' => '-'), $input->getArguments(), '->parse() parses single dash as an argument');
 }
開發者ID:ngitimfoyo,項目名稱:Nyari-AppPHP,代碼行數:6,代碼來源:ArgvInputTest.php

示例4: 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

示例5: 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::getArguments方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。