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


PHP ArrayInput::setOption方法代码示例

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


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

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

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

示例3: binds_and_renders

 /**
  * @test
  */
 public function binds_and_renders()
 {
     $this->input->setOption('test-option', 'test-option');
     $this->template->getName()->willReturn('test/foobar')->shouldBeCalled();
     $this->template->bind(['author' => 'cslucano'])->shouldBeCalled();
     $this->template->render()->willReturn('foo')->shouldBeCalled();
     $this->helper->registerTemplate($this->template->reveal());
     $res = $this->helper->bindAndRender(['author' => 'cslucano'], 'test', 'foobar');
     $this->assertEquals('foo', $res);
 }
开发者ID:mistymagich,项目名称:gush,代码行数:13,代码来源:TemplateHelperTest.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: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $mountId = $input->getArgument('mount_id');
     try {
         $mount = $this->globalService->getStorage($mountId);
     } catch (NotFoundException $e) {
         $output->writeln('<error>Mount with id "' . $mountId . ' not found, check "occ files_external:list" to get available mounts"</error>');
         return 404;
     }
     $noConfirm = $input->getOption('yes');
     if (!$noConfirm) {
         $listCommand = new ListCommand($this->globalService, $this->userService, $this->userSession, $this->userManager);
         $listInput = new ArrayInput([], $listCommand->getDefinition());
         $listInput->setOption('output', $input->getOption('output'));
         $listCommand->listMounts(null, [$mount], $listInput, $output);
         $questionHelper = $this->getHelper('question');
         $question = new ConfirmationQuestion('Delete this mount? [y/N] ', false);
         if (!$questionHelper->ask($input, $output, $question)) {
             return;
         }
     }
     $this->globalService->removeStorage($mountId);
 }
开发者ID:rchicoli,项目名称:owncloud-core,代码行数:23,代码来源:Delete.php

示例6: testSetInvalidOption

 /**
  * @expectedException        \InvalidArgumentException
  * @expectedExceptionMessage The "foo" option does not exist.
  */
 public function testSetInvalidOption()
 {
     $input = new ArrayInput(array('--name' => 'foo'), new InputDefinition(array(new InputOption('name'), new InputOption('bar', '', InputOption::VALUE_OPTIONAL, '', 'default'))));
     $input->setOption('foo', 'bar');
 }
开发者ID:TheTypoMaster,项目名称:SPHERE-Framework,代码行数:9,代码来源:InputTest.php

示例7: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $configHelper = $this->getHelper('configuration');
     /* @var $configHelper GlobalConfigurationHelper */
     $extractHelper = $this->getHelper('extract');
     /* @var $extractHelper ExtractHelper */
     if (!$input->getArgument('application')) {
         $appName = basename($input->getArgument('archive'));
         $input->setArgument('application', preg_replace('/\\.(zip|rar|(tar(\\.(gz|bz2|xz|Z))?))$/i', '', $appName));
     }
     $application = Application::create($configHelper->getConfiguration(), $input->getArgument('application'));
     if (!is_dir($application->getPath())) {
         FsUtil::mkdir($application->getPath(), true);
         $output->writeln(sprintf('Created directory <info>%s</info>', $application->getPath()), OutputInterface::VERBOSITY_VERY_VERBOSE);
     }
     NotEmptyException::assert($application->getPath());
     $appDir = $application->getPath();
     $configHelper->getConfiguration()->removeApplication($application->getName());
     // Clean up application again, so application:add further down does not complain.
     if (strpos($input->getArgument('archive'), '://') !== false) {
         // This is an url
         $outputFile = $extractHelper->downloadFile($input->getArgument('archive'), $output);
         $extractHelper->extractArchive($outputFile, $appDir, $output);
         $this->getApplication()->find('application:add')->run(new ArrayInput(['application' => $input->getArgument('application'), '--archive-url' => $input->getArgument('archive')]), $output);
     } else {
         $extractHelper->extractArchive($input->getArgument('archive'), $application->getPath(), $output);
         $this->getApplication()->find('application:add')->run(new ArrayInput(['application' => $input->getArgument('application')]), $output);
     }
     if ($input->getOption('override')) {
         $input1 = new ArrayInput(['application' => $input->getArgument('application'), 'config-file' => $input->getOption('override')]);
         if ($input->getOption('override-type')) {
             $input1->setOption('type', $input->getOption('override-type'));
         }
         $this->getApplication()->find('application:override')->run($input1, $output);
     }
     if (!$input->getOption('no-scripts')) {
         /*
          * Run post-extract script
          */
         return $this->getApplication()->find('application:execute')->run(new ArrayInput(['script' => 'post-extract', 'application' => $input->getArgument('application')]), $output);
     }
     return 0;
 }
开发者ID:vierbergenlars,项目名称:clic,代码行数:43,代码来源:ExtractCommand.php

示例8: showMount

 private function showMount($user, StorageConfig $mount, InputInterface $input, OutputInterface $output)
 {
     $listCommand = new ListCommand($this->globalService, $this->userService, $this->userSession, $this->userManager);
     $listInput = new ArrayInput([], $listCommand->getDefinition());
     $listInput->setOption('output', $input->getOption('output'));
     $listInput->setOption('show-password', true);
     $listCommand->listMounts($user, [$mount], $listInput, $output);
 }
开发者ID:rchicoli,项目名称:owncloud-core,代码行数:8,代码来源:Create.php

示例9: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $user = $input->getOption('user');
     $path = $input->getArgument('path');
     if ($path === '-') {
         $json = file_get_contents('php://stdin');
     } else {
         if (!file_exists($path)) {
             $output->writeln('<error>File not found: ' . $path . '</error>');
             return 1;
         }
         $json = file_get_contents($path);
     }
     if (!is_string($json) || strlen($json) < 2) {
         $output->writeln('<error>Error while reading json</error>');
         return 1;
     }
     $data = json_decode($json, true);
     if (!is_array($data)) {
         $output->writeln('<error>Error while parsing json</error>');
         return 1;
     }
     $isLegacy = isset($data['user']) || isset($data['group']);
     if ($isLegacy) {
         $this->importLegacyStorageService->setData($data);
         $mounts = $this->importLegacyStorageService->getAllStorages();
         foreach ($mounts as $mount) {
             if ($mount->getBackendOption('password') === false) {
                 $output->writeln('<error>Failed to decrypt password</error>');
                 return 1;
             }
         }
     } else {
         if (!isset($data[0])) {
             //normalize to an array of mounts
             $data = [$data];
         }
         $mounts = array_map([$this, 'parseData'], $data);
     }
     if ($user) {
         // ensure applicables are correct for personal mounts
         foreach ($mounts as $mount) {
             $mount->setApplicableGroups([]);
             $mount->setApplicableUsers([$user]);
         }
     }
     $storageService = $this->getStorageService($user);
     $existingMounts = $storageService->getAllStorages();
     foreach ($mounts as $mount) {
         foreach ($existingMounts as $existingMount) {
             if ($existingMount->getMountPoint() === $mount->getMountPoint() && $existingMount->getApplicableGroups() === $mount->getApplicableGroups() && $existingMount->getApplicableUsers() == $mount->getApplicableUsers() && $existingMount->getBackendOptions() == $mount->getBackendOptions()) {
                 $output->writeln("<error>Duplicate mount (" . $mount->getMountPoint() . ")</error>");
                 return 1;
             }
         }
     }
     if ($input->getOption('dry')) {
         if (count($mounts) === 0) {
             $output->writeln('<error>No mounts to be imported</error>');
             return 1;
         }
         $listCommand = new ListCommand($this->globalService, $this->userService, $this->userSession, $this->userManager);
         $listInput = new ArrayInput([], $listCommand->getDefinition());
         $listInput->setOption('output', $input->getOption('output'));
         $listInput->setOption('show-password', true);
         $listCommand->listMounts($user, $mounts, $listInput, $output);
     } else {
         foreach ($mounts as $mount) {
             $storageService->addStorage($mount);
         }
     }
     return 0;
 }
开发者ID:GitHubUser4234,项目名称:core,代码行数:73,代码来源:Import.php

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

示例11: testGetConfigurationFileDoesNotExist

 /**
  * @covers                   ::getConfiguration
  * @expectedException        InvalidArgumentException
  * @expectedExceptionMessage The configuration file "foo.bar" could not be found.
  */
 public function testGetConfigurationFileDoesNotExist()
 {
     $mock = $this->getMockBuilder('MaartenStaa\\PHPTA\\CLI\\Command')->setMethods(array('getFilesystem'))->getMock();
     $fs = $this->getMockBuilder('Illuminate\\Filesystem\\Filesystem')->setMethods(array('isFile'))->getMock();
     $mock->expects($this->once())->method('getFilesystem')->will($this->returnValue($fs));
     $fs->expects($this->once())->method('isFile')->with('foo.bar')->will($this->returnValue(false));
     $input = new ArrayInput(array());
     $input->bind($mock->getDefinition());
     $input->setOption('config', 'foo.bar');
     $output = new StreamOutput(fopen('php://memory', 'w', false));
     $mock->getConfiguration($input, $output);
 }
开发者ID:maartenstaa,项目名称:phpta,代码行数:17,代码来源:CommandTest.php

示例12: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $configHelper = $this->getHelper('configuration');
     /* @var $configHelper GlobalConfigurationHelper */
     $processHelper = $this->getHelper('process');
     /* @var $processHelper ProcessHelper */
     $questionHelper = $this->getHelper('question');
     /* @var $questionHelper QuestionHelper */
     if (!$input->getArgument('application')) {
         $input->setArgument('application', basename($input->getArgument('repository'), '.git'));
     }
     try {
         $repositoryConfiguration = $configHelper->getConfiguration()->getRepositoryConfiguration($input->getArgument('repository'));
     } catch (NoSuchRepositoryException $ex) {
         $repositoryConfiguration = null;
     }
     $repositoryParts = Util::parseRepositoryUrl($input->getArgument('repository'));
     if (!Util::isSshRepositoryUrl($repositoryParts)) {
         $input->setOption('no-deploy-key', true);
     }
     $application = Application::create($configHelper->getConfiguration(), $input->getArgument('application'));
     if (!is_dir($application->getPath())) {
         FsUtil::mkdir($application->getPath(), true);
         $output->writeln(sprintf('Created directory <info>%s</info>', $application->getPath()), OutputInterface::VERBOSITY_VERY_VERBOSE);
     }
     NotEmptyException::assert($application->getPath());
     if (!$repositoryConfiguration && !$input->getOption('no-deploy-key')) {
         $output->writeln('You do not have a deploy key configured for this repository.', OutputInterface::VERBOSITY_VERBOSE);
         $repositoryConfiguration = new RepositoryConfiguration();
         $repositoryConfiguration->setSshAlias(sha1($input->getArgument('repository')) . '-' . basename($input->getArgument('application')));
         /*
          * Generate a new deploy key, link it to the repository and print it.
          */
         $keyFile = $configHelper->getConfiguration()->getSshDirectory() . '/id_rsa-' . $repositoryConfiguration->getSshAlias();
         try {
             $this->getApplication()->find('repository:generate-key')->run(new ArrayInput(['key' => $keyFile, '--comment' => 'clic-deploy-key-' . $repositoryConfiguration->getSshAlias() . '@' . gethostname(), '--target-repository' => $input->getArgument('repository'), '--print-public-key' => true]), $output);
             $repositoryConfiguration = $configHelper->getConfiguration()->getRepositoryConfiguration($input->getArgument('repository'));
         } catch (FileExistsException $ex) {
             $repositoryConfiguration->setIdentityFile($ex->getFilename());
             $output->writeln(sprintf('Key <info>%s</info> already exists. Not generating a new one.', $ex->getFilename()));
         }
         /*
          * Ask to add it as a deploy key to the repo
          */
         $output->writeln('<comment>Please set the public key printed above as a deploy key for the repository</comment>');
         while (!$questionHelper->ask($input, $output, new ConfirmationQuestion('Is the deploy key uploaded?'))) {
         }
     }
     if ($repositoryConfiguration && !$input->getOption('no-deploy-key')) {
         /*
          * If there is a configuration now, save it
          */
         $configHelper->getConfiguration()->setRepositoryConfiguration($input->getArgument('repository'), $repositoryConfiguration);
         $configHelper->getConfiguration()->write();
     } else {
         $repositoryConfiguration = null;
     }
     /*
      * Run a git clone for the application
      */
     $gitClone = ProcessBuilder::create(['git', 'clone', Util::replaceRepositoryUrl($repositoryParts, $repositoryConfiguration), $application->getPath()])->setTimeout(null)->getProcess();
     $processHelper->mustRun($output, $gitClone, null, null, OutputInterface::VERBOSITY_NORMAL, OutputInterface::VERBOSITY_NORMAL);
     $configHelper->getConfiguration()->removeApplication($application->getName());
     // Clean up application again, so application:add further down does not complain.
     $this->getApplication()->find('application:add')->run(new ArrayInput(['application' => $input->getArgument('application'), '--remote' => $input->getArgument('repository')]), $output);
     if ($input->getOption('override')) {
         $input1 = new ArrayInput(['application' => $input->getArgument('application'), 'config-file' => $input->getOption('override')]);
         if ($input->getOption('override-type')) {
             $input1->setOption('type', $input->getOption('override-type'));
         }
         $this->getApplication()->find('application:override')->run($input1, $output);
     }
     if (!$input->getOption('no-scripts')) {
         /*
          * Run post-clone script
          */
         return $this->getApplication()->find('application:execute')->run(new ArrayInput(['script' => 'post-clone', 'application' => $input->getArgument('application')]), $output);
     }
     return 0;
 }
开发者ID:vierbergenlars,项目名称:clic,代码行数:80,代码来源:CloneCommand.php


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