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


PHP ArrayInput::setArgument方法代碼示例

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


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

示例1: testArguments

 public function testArguments()
 {
     $input = new ArrayInput(array('name' => 'foo'), new InputDefinition(array(new InputArgument('name'))));
     $this->assertEquals('foo', $input->getArgument('name'), '->getArgument() returns the value for the given argument');
     $input->setArgument('name', 'bar');
     $this->assertEquals('bar', $input->getArgument('name'), '->setArgument() sets the value for a given argument');
     $this->assertEquals(array('name' => 'bar'), $input->getArguments(), '->getArguments() returns all argument values');
     $input = new ArrayInput(array('name' => 'foo'), new InputDefinition(array(new InputArgument('name'), new InputArgument('bar', InputArgument::OPTIONAL, '', 'default'))));
     $this->assertEquals('default', $input->getArgument('bar'), '->getArgument() returns the default value for optional arguments');
     $this->assertEquals(array('name' => 'foo', 'bar' => 'default'), $input->getArguments(), '->getArguments() returns all argument values, even optional ones');
     try {
         $input->setArgument('foo', 'bar');
         $this->fail('->setArgument() throws a \\InvalidArgumentException if the argument does not exist');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->setOption() throws a \\InvalidArgumentException if the option does not exist');
         $this->assertEquals('The "foo" argument does not exist.', $e->getMessage());
     }
     try {
         $input->getArgument('foo');
         $this->fail('->getArgument() throws a \\InvalidArgumentException if the argument does not exist');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->setOption() throws a \\InvalidArgumentException if the option does not exist');
         $this->assertEquals('The "foo" argument does not exist.', $e->getMessage());
     }
 }
開發者ID:yamildiego,項目名稱:JY,代碼行數:25,代碼來源:InputTest.php

示例2: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $listCommand = new ListCommand($this->globalService, $this->userService, $this->userSession, $this->userManager);
     $listInput = new ArrayInput([], $listCommand->getDefinition());
     $listInput->setArgument('user_id', $input->getArgument('user_id'));
     $listInput->setOption('output', 'json_pretty');
     $listInput->setOption('show-password', true);
     $listInput->setOption('full', true);
     $listCommand->execute($listInput, $output);
 }
開發者ID:farukuzun,項目名稱:core-1,代碼行數:10,代碼來源:export.php

示例3: getInput

 protected function getInput(Command $command, array $arguments = [], array $options = [])
 {
     $input = new ArrayInput([]);
     $input->bind($command->getDefinition());
     foreach ($arguments as $key => $value) {
         $input->setArgument($key, $value);
     }
     foreach ($options as $key => $value) {
         $input->setOption($key, $value);
     }
     return $input;
 }
開發者ID:farukuzun,項目名稱:core-1,代碼行數:12,代碼來源:commandtest.php

示例4: filterByOriginalDefinition

 /**
  * @param InputInterface $input
  * @param $appDefinition
  * @return ArrayInput
  */
 public function filterByOriginalDefinition(InputInterface $input, $appDefinition)
 {
     $newDefinition = new InputDefinition();
     $newInput = new ArrayInput(array(), $newDefinition);
     foreach ($input->getArguments() as $name => $value) {
         if (!$appDefinition->hasArgument($name)) {
             $newDefinition->addArgument($this->getDefinition()->getArgument($name));
             if (!empty($value)) {
                 $newInput->setArgument($name, $value);
             }
         }
     }
     foreach ($input->getOptions() as $name => $value) {
         if (!$appDefinition->hasOption($name)) {
             $newDefinition->addOption($this->getDefinition()->getOption($name));
             if (!empty($value)) {
                 $newInput->setOption($name, $value);
             }
         }
     }
     return $newInput;
 }
開發者ID:Catapush,項目名稱:Idephix,代碼行數:27,代碼來源:CommandWrapper.php

示例5: testSetInvalidArgument

 /**
  * @expectedException        \InvalidArgumentException
  * @expectedExceptionMessage The "foo" argument does not exist.
  */
 public function testSetInvalidArgument()
 {
     $input = new ArrayInput(array('name' => 'foo'), new InputDefinition(array(new InputArgument('name'), new InputArgument('bar', InputArgument::OPTIONAL, '', 'default'))));
     $input->setArgument('foo', 'bar');
 }
開發者ID:TheTypoMaster,項目名稱:SPHERE-Framework,代碼行數:9,代碼來源:InputTest.php


注:本文中的Symfony\Component\Console\Input\ArrayInput::setArgument方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。