コード例 #1
0
ファイル: Process.php プロジェクト: victorhaggqvist/sphpdox
 /**
  * @see Symfony\Component\Console\Command.Command::configure()
  */
 protected function configure()
 {
     $definition = new InputDefinition();
     $definition->addArgument(new InputArgument('namespace', InputArgument::REQUIRED, 'The namespace to process'));
     $definition->addArgument(new InputArgument('path', InputArgument::REQUIRED, 'The path the namespace can be found in'));
     $definition->addOption(new InputOption('output', 'o', InputOption::VALUE_REQUIRED, 'The path to output the ReST files', 'build'));
     $definition->addOption(new InputOption('title', 't', InputOption::VALUE_REQUIRED, 'An alternate title for the top level namespace', null));
     $definition->addOption(new InputOption('exclude', 'x', InputOption::VALUE_REQUIRED, 'Semicolon separated namespaces to ignore', null));
     $definition->addOption(new InputOption('filters', 'f', InputOption::VALUE_REQUIRED, 'Semicolon separated filename filters to apply', null));
     $this->setName('process')->setDescription('Processes a directory of PHPDoc documented code into ReST')->setHelp('The process command works recursively on a directory of PHP code.')->setDefinition($definition);
 }
コード例 #2
0
 private function buildInputDefinition()
 {
     $inputDefinition = new InputDefinition();
     $inputDefinition->addArgument(new InputArgument('uno', InputArgument::REQUIRED));
     $inputDefinition->addOption(new InputOption('due', null, InputOption::VALUE_NONE));
     return $inputDefinition;
 }
コード例 #3
0
 /**
  * Get an InputDefinition formed by the arguments provided
  *
  * Effectively provides a passthrough for any input arguments provided
  *
  * @param  array  $args Arguments
  * @return InputDefinition
  */
 protected function getInputDefinition(array $args)
 {
     $definition = new InputDefinition();
     foreach ($args as $field => $value) {
         $definition->addArgument(new InputArgument($field));
     }
     return $definition;
 }
コード例 #4
0
ファイル: SystemCommandTest.php プロジェクト: PublicVar/cop1
 public function testConfigureSystemCommand()
 {
     $name = 'test_base_command';
     $description = 'test for base command creation';
     $keywords = 'base commands creation test';
     $arguments = array('username' => array('description' => 'linux username'));
     $options = 'options';
     $expectedArguments = new InputDefinition();
     $expectedArguments->addArgument(new InputArgument('username', InputArgument::REQUIRED, $arguments['username']['description']));
     $systemCommand = new SystemCommand($name, $description, $keywords, $arguments, $options);
     $this->assertEquals($expectedArguments, $systemCommand->getDefinition());
 }
コード例 #5
0
 /**
  * @inheritdoc
  */
 public static function run($request, $response, $args)
 {
     global $argv;
     $container = static::getApp()->getContainer();
     $pathResolver = $container['pathResolver'];
     $filesystem = new Filesystem();
     $creator = new MigrationCreator($filesystem);
     $definition = new InputDefinition();
     $definition->addArgument(new InputArgument('name', InputArgument::REQUIRED));
     $definition->addOption(new InputOption('table', 't', InputOption::VALUE_OPTIONAL));
     $input = new ArgvInput(array_slice($argv, 1), $definition);
     $output = new ConsoleOutput();
     $path = $pathResolver->getAlias('@db/migrations');
     $name = $input->getArgument('name');
     $table = $input->getOption('table');
     $file = pathinfo($creator->create($name, $path, $table), PATHINFO_FILENAME);
     \dump($file);
 }
コード例 #6
0
ファイル: ConfigTest.php プロジェクト: netz98/n98-magerun
 /**
  * @test
  */
 public function configCommandAlias()
 {
     $config = new Config();
     $input = new ArgvInput();
     $actual = $config->checkConfigCommandAlias($input);
     $this->assertInstanceOf('Symfony\\Component\\Console\\Input\\InputInterface', $actual);
     $saved = $_SERVER['argv'];
     $config->setConfig(array('commands' => array('aliases' => array(array('list-help' => 'list --help')))));
     $definition = new InputDefinition();
     $definition->addArgument(new InputArgument('command'));
     $argv = array('/path/to/command', 'list-help');
     $_SERVER['argv'] = $argv;
     $input = new ArgvInput($argv, $definition);
     $this->assertSame('list-help', (string) $input);
     $actual = $config->checkConfigCommandAlias($input);
     $this->assertSame('list-help', $actual->getFirstArgument());
     $this->assertSame('list-help --help', (string) $actual);
     $_SERVER['argv'] = $saved;
     $command = new Command('list');
     $config->registerConfigCommandAlias($command);
     $this->assertSame(array('list-help'), $command->getAliases());
 }
コード例 #7
0
ファイル: CommandWrapper.php プロジェクト: Catapush/Idephix
 /**
  * @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;
 }
コード例 #8
0
ファイル: BaseCommand.php プロジェクト: bsa-git/silex-mvc
 /**
  * Set command options/arguments
  * 
  * @return array
  */
 public function setCommandConfig()
 {
     $name = $this->config_name;
     // Конфиг. имя команды (пр. "my_greet")
     $definition = new Input\InputDefinition();
     //---------------------------
     $config = $this->app['config']['commands'][$name];
     // Set command description
     if ($config['configure']['description']) {
         $this->setDescription($config['configure']['description']);
     }
     // Set arguments
     if ($config['arguments']) {
         $arguments = $config['arguments'];
         foreach ($arguments as $argument) {
             $mode = $this->_getArgumentMode($argument['mode']);
             $newArgument = new InputArgument($argument['name'], $mode, $argument['description'], $argument['default']);
             $definition->addArgument($newArgument);
         }
     }
     // Set options
     if (isset($config['options'])) {
         $options = $config['options'];
         foreach ($options as $option) {
             $mode = $this->_getOptionMode($option['mode']);
             $newOption = new InputOption($option['name'], $option['shortcut'], $mode, $option['description'], $option['default']);
             $definition->addOption($newOption);
         }
     }
     $this->setDefinition($definition);
 }
コード例 #9
0
 /**
  * Builds the Input Definition based upon Api Method Parameters.
  *
  * @param \ReflectionMethod $method
  * @param string            $token
  *
  * @return InputDefinition
  */
 private function buildDefinition(\ReflectionMethod $method, DocBlock $docBlock, $token = null)
 {
     $definition = new InputDefinition();
     foreach ($docBlock->getTags() as $tag) {
         if ($tag instanceof DocBlock\Tags\Param) {
             $tagsDescription[$tag->getVariableName()] = $tag->getDescription()->render();
         }
     }
     foreach ($method->getParameters() as $parameter) {
         if ($parameter->isDefaultValueAvailable()) {
             //option
             $definition->addOption(new InputOption($parameter->getName(), null, InputOption::VALUE_REQUIRED, $tagsDescription[$parameter->getName()], $parameter->isDefaultValueAvailable() ? $parameter->getDefaultValue() : null));
         } else {
             //argument
             $definition->addArgument(new InputArgument($parameter->getName(), InputArgument::REQUIRED, $tagsDescription[$parameter->getName()], null));
         }
     }
     $definition->addOption(new InputOption('token', null, InputOption::VALUE_REQUIRED, 'Auth token to use', $token));
     $definition->addOption(new InputOption('debug', null, InputOption::VALUE_NONE, 'Display raw response'));
     return $definition;
 }
コード例 #10
0
 public function testGetArgumentCount()
 {
     $this->initializeArguments();
     $definition = new InputDefinition();
     $definition->addArgument($this->foo2);
     $this->assertEquals(1, $definition->getArgumentCount(), '->getArgumentCount() returns the number of arguments');
     $definition->addArgument($this->foo);
     $this->assertEquals(2, $definition->getArgumentCount(), '->getArgumentCount() returns the number of arguments');
 }
コード例 #11
0
 protected function bindSignature()
 {
     $signatureParts = new SignatureParts($this->signature);
     $signature = $signatureParts->getSignatureWithoutCommandName();
     list($name, $arguments, $options) = Parser::parse($signature);
     $this->name = $name;
     $inputDefinition = new InputDefinition();
     foreach ($arguments as $argument) {
         $inputDefinition->addArgument($argument);
     }
     foreach ($options as $option) {
         $inputDefinition->addOption($option);
     }
     $inputWithoutHandlerName = explode(' ', $this->request->text, 2)[1] ?? '';
     $this->input = new StringInput($inputWithoutHandlerName);
     $this->inputDefinition = $inputDefinition;
     try {
         $this->input->bind($inputDefinition);
     } catch (RuntimeException $exception) {
         return false;
     }
     return true;
 }
コード例 #12
0
<?php

require __DIR__ . '/vendor/autoload.php';
use Elastica\Client;
use Elastica\Document;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputOption;
$inputDefinition = new InputDefinition();
$inputDefinition->addArgument(new InputArgument('host', InputArgument::REQUIRED));
$inputDefinition->addArgument(new InputArgument('tree', InputArgument::REQUIRED));
$options = [['port', null, InputOption::VALUE_REQUIRED, '', 9200], ['index', null, InputOption::VALUE_REQUIRED, '', 'test'], ['type', null, InputOption::VALUE_REQUIRED, '', 'test'], ['treeLevels', null, InputOption::VALUE_REQUIRED, '', null], ['precision', null, InputOption::VALUE_REQUIRED, '', null], ['tab', null, InputOption::VALUE_NONE], ['bulk-size', null, InputOption::VALUE_REQUIRED, '', 10]];
foreach ($options as $option) {
    $inputDefinition->addOption(new InputOption($option[0], $option[1], $option[2], $option[3], $option[4]));
}
$argvInput = new ArgvInput($argv, $inputDefinition);
$main = function () use($argvInput) {
    $host = $argvInput->getArgument('host');
    $port = $argvInput->getOption('port');
    $indexName = $argvInput->getOption('index');
    $typeName = $argvInput->getOption('type');
    $treeLevels = $argvInput->getOption('treeLevels');
    $precision = $argvInput->getOption('precision');
    $tree = $argvInput->getArgument('tree');
    $bulkSize = $argvInput->getOption('bulk-size');
    $tab = $argvInput->getOption('tab');
    if (!in_array($tree, ['quadtree', 'geohash'])) {
        throw new \Exception(sprintf('Supported tree types are quadtree and geohash, "%s" given.', $tree));
    }
    if (!isset($treeLevels) && !isset($precision)) {
コード例 #13
0
ファイル: Job.php プロジェクト: netresearch/kite
 /**
  * Add the retrieved options and arguments to a definition
  *
  * @return InputDefinition
  */
 public function getDefinition()
 {
     if (!$this->initialized) {
         $this->initialize();
     }
     $definition = new InputDefinition();
     foreach ($this->definitions as $from => $info) {
         $config = $info['config'];
         $required = array_key_exists('required', $config) && $config['required'];
         if ($info['type'] === 'option') {
             $mode = array_key_exists('mode', $config) ? $config['mode'] : InputOption::VALUE_OPTIONAL;
             if ($required) {
                 $mode |= InputOption::VALUE_REQUIRED;
             }
             if (in_array('array', explode('|', $config['type']), true)) {
                 $mode |= InputOption::VALUE_IS_ARRAY;
             }
             if (preg_match('/(^|\\|)bool(ean)?($|\\|)/', $config['type'])) {
                 if (strpos($config['type'], '|')) {
                     $mode |= InputOption::VALUE_NONE;
                 } else {
                     $mode = InputOption::VALUE_NONE;
                 }
             }
             $definition->addOption(new InputOption($from, array_key_exists('shortcut', $config) ? $config['shortcut'] : null, $mode, $config['label'], array_key_exists('default', $config) ? $config['default'] : null));
         } else {
             $mode = array_key_exists('mode', $config) ? $config['mode'] : InputArgument::OPTIONAL;
             if ($required) {
                 $mode |= InputArgument::REQUIRED;
             }
             if (in_array('array', explode('|', $config['type']), true)) {
                 $mode |= InputArgument::IS_ARRAY;
             }
             $definition->addArgument(new InputArgument($from, $mode, $config['label'], array_key_exists('default', $config) ? $config['default'] : null));
         }
     }
     return $definition;
 }
コード例 #14
0
 /**
  * builds the Input Definition based upon Api Method Parameters.
  *
  * @param \ReflectionMethod $method
  * @param string            $token
  *
  * @return InputDefinition
  */
 private function buildDefinition(\ReflectionMethod $method, $token = null)
 {
     $definition = new InputDefinition();
     foreach ($method->getParameters() as $parameter) {
         if ($parameter->isDefaultValueAvailable()) {
             //option
             $definition->addOption(new InputOption($parameter->getName(), null, InputOption::VALUE_REQUIRED, null, $parameter->isDefaultValueAvailable() ? $parameter->getDefaultValue() : null));
         } else {
             //argument
             $definition->addArgument(new InputArgument($parameter->getName(), InputArgument::REQUIRED, null, null));
         }
     }
     $definition->addOption(new InputOption('token', null, InputOption::VALUE_REQUIRED, 'the auth token to use', $token));
     $definition->addOption(new InputOption('debug', null, InputOption::VALUE_NONE, 'display raw response'));
     return $definition;
 }
コード例 #15
0
 /**
  * Adds an argument.
  *
  * @param string $name        The argument name
  * @param int    $mode        The argument mode: InputArgument::REQUIRED or InputArgument::OPTIONAL
  * @param string $description A description text
  * @param mixed  $default     The default value (for InputArgument::OPTIONAL mode only)
  *
  * @return Command The current instance
  */
 public function addArgument($name, $mode = null, $description = '', $default = null)
 {
     $this->definition->addArgument(new InputArgument($name, $mode, $description, $default));
     return $this;
 }
コード例 #16
0
ファイル: Command.php プロジェクト: rmlasseter/silex-cli
 /**
  * {@inheritdoc}
  */
 protected function configure()
 {
     $definition = new InputDefinition();
     foreach ($this->argnames as $argname) {
         if (isset($this->callbackParams[$argname])) {
             $param = $this->callbackParams[$argname];
             if (!$param->getClass()) {
                 $mode = 0;
                 if ($param->isOptional()) {
                     $mode |= InputArgument::OPTIONAL;
                 } else {
                     $mode |= InputArgument::REQUIRED;
                 }
                 if ($param->isArray()) {
                     $mode |= InputArgument::IS_ARRAY;
                 }
                 $description = '';
                 $default = null;
                 if ($param->isDefaultValueAvailable()) {
                     $default = $param->getDefaultValue();
                 }
                 $definition->addArgument(new InputArgument($argname, $mode, $description, $default));
             }
         }
     }
     foreach ($this->optnames as $optname) {
         if (isset($this->callbackParams[$optname])) {
             if (!$param->getClass()) {
                 $shortcut = null;
                 $mode = 0;
                 $description = '';
                 $default = $param->getDefaultValue();
                 if (is_bool($default)) {
                     $mode |= InputOption::VALUE_NONE;
                 } else {
                     $mode |= InputOption::VALUE_REQUIRED;
                     if ($param->isArray()) {
                         $mode |= InputOption::VALUE_IS_ARRAY;
                     }
                 }
                 $definition->addOption(new InputOption($optname, $shortcut, $mode, $description, $default));
             }
         }
     }
     $this->setDefinition($definition);
 }