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


PHP ArrayInput::getOptions方法代码示例

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


在下文中一共展示了ArrayInput::getOptions方法的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());
     }
 }
开发者ID:yamildiego,项目名称:JY,代码行数:25,代码来源:InputTest.php

示例2: updateCommandDefinition

 private function updateCommandDefinition(Command $command, OutputInterface $output)
 {
     $eventDispatcher = $this->getApplication()->getDispatcher();
     $input = new ArrayInput(['command' => $command->getName()]);
     $event = new ConsoleCommandEvent($command, $input, $output);
     $eventDispatcher->dispatch(GushEvents::DECORATE_DEFINITION, $event);
     $command->getSynopsis(true);
     $command->getSynopsis(false);
     $command->mergeApplicationDefinition();
     try {
         $input->bind($command->getDefinition());
     } catch (\Exception $e) {
         $output->writeln('<error>Something went wrong: </error>' . $e->getMessage());
         return;
     }
     $eventDispatcher->dispatch(GushEvents::INITIALIZE, $event);
     // The options were set on the input but now we need to set them on the Command definition
     if ($options = $input->getOptions()) {
         foreach ($options as $name => $value) {
             $option = $command->getDefinition()->getOption($name);
             if ($option->acceptValue()) {
                 $option->setDefault($value);
             }
         }
     }
 }
开发者ID:mistymagich,项目名称:gush,代码行数:26,代码来源:HelpCommand.php

示例3: 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');
 }
开发者ID:TheTypoMaster,项目名称:SPHERE-Framework,代码行数:11,代码来源:InputTest.php

示例4: testParse

 public function testParse()
 {
     $input = new ArrayInput(array('name' => 'foo'), new InputDefinition(array(new InputArgument('name'))));
     $this->assertEquals(array('name' => 'foo'), $input->getArguments(), '->parse() parses required arguments');
     try {
         $input = new ArrayInput(array('foo' => 'foo'), new InputDefinition(array(new InputArgument('name'))));
         $this->fail('->parse() throws an \\InvalidArgumentException exception if an invalid argument is passed');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->parse() throws an \\InvalidArgumentException exception if an invalid argument is passed');
         $this->assertEquals('The "foo" argument does not exist.', $e->getMessage(), '->parse() throws an \\InvalidArgumentException exception if an invalid argument is passed');
     }
     $input = new ArrayInput(array('--foo' => 'bar'), new InputDefinition(array(new InputOption('foo'))));
     $this->assertEquals(array('foo' => 'bar'), $input->getOptions(), '->parse() parses long options');
     $input = new ArrayInput(array('--foo' => 'bar'), new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL, '', 'default'))));
     $this->assertEquals(array('foo' => 'bar'), $input->getOptions(), '->parse() parses long options with a default value');
     $input = new ArrayInput(array('--foo' => null), new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL, '', 'default'))));
     $this->assertEquals(array('foo' => 'default'), $input->getOptions(), '->parse() parses long options with a default value');
     try {
         $input = new ArrayInput(array('--foo' => null), new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_REQUIRED))));
         $this->fail('->parse() throws an \\InvalidArgumentException exception if a required option is passed without a value');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->parse() throws an \\InvalidArgumentException exception if a required option is passed without a value');
         $this->assertEquals('The "--foo" option requires a value.', $e->getMessage(), '->parse() throws an \\InvalidArgumentException exception if a required option is passed without a value');
     }
     try {
         $input = new ArrayInput(array('--foo' => 'foo'), new InputDefinition());
         $this->fail('->parse() throws an \\InvalidArgumentException exception if an invalid option is passed');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->parse() throws an \\InvalidArgumentException exception if an invalid option is passed');
         $this->assertEquals('The "--foo" option does not exist.', $e->getMessage(), '->parse() throws an \\InvalidArgumentException exception if an invalid option is passed');
     }
     $input = new ArrayInput(array('-f' => 'bar'), new InputDefinition(array(new InputOption('foo', 'f'))));
     $this->assertEquals(array('foo' => 'bar'), $input->getOptions(), '->parse() parses short options');
     try {
         $input = new ArrayInput(array('-o' => 'foo'), new InputDefinition());
         $this->fail('->parse() throws an \\InvalidArgumentException exception if an invalid option is passed');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->parse() throws an \\InvalidArgumentException exception if an invalid option is passed');
         $this->assertEquals('The "-o" option does not exist.', $e->getMessage(), '->parse() throws an \\InvalidArgumentException exception if an invalid option is passed');
     }
 }
开发者ID:rooster,项目名称:symfony,代码行数:41,代码来源:ArrayInputTest.php

示例5: testParseOptions

 /**
  * @dataProvider provideOptions
  */
 public function testParseOptions($input, $options, $expectedOptions, $message)
 {
     $input = new ArrayInput($input, new InputDefinition($options));
     $this->assertEquals($expectedOptions, $input->getOptions(), $message);
 }
开发者ID:EnmanuelCode,项目名称:backend-laravel,代码行数:8,代码来源:ArrayInputTest.php


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