getTokens() public method

Returns the tokens of the console arguments.
public getTokens ( ) : string[]
return string[] The argument tokens.
コード例 #1
0
ファイル: ArgsInput.php プロジェクト: webmozart/console
 /**
  * {@inheritdoc}
  */
 public function getParameterOption($values, $default = false, $onlyParams = false)
 {
     $tokens = $this->rawArgs->getTokens();
     foreach ((array) $values as $value) {
         for (reset($tokens); null !== key($tokens); next($tokens)) {
             $token = current($tokens);
             if ($onlyParams && $token === '--') {
                 // end of options (--) signal reached, stop now
                 return $default;
             }
             // Long/short option with value in the next argument
             if ($token === $value) {
                 $next = next($tokens);
                 return $next && $next !== '--' ? $next : null;
             }
             // Long option with =
             if (0 === strpos($token, $value . '=')) {
                 return substr($token, strlen($value) + 1);
             }
             // Short option
             if (strlen($token) > 2 && '-' === $token[0] && '-' !== $token[1] && 0 === strpos($token, $value)) {
                 return substr($token, 2);
             }
         }
     }
     return $default;
 }
コード例 #2
0
ファイル: DefaultResolver.php プロジェクト: webmozart/console
 /**
  * {@inheritdoc}
  */
 public function resolveCommand(RawArgs $args, Application $application)
 {
     $tokens = $args->getTokens();
     $namedCommands = $application->getNamedCommands();
     $argumentsToTest = $this->getArgumentsToTest($tokens);
     $optionsToTest = $this->getOptionsToTest($tokens);
     // Try to find a command for the passed arguments and options.
     if ($result = $this->processArguments($args, $namedCommands, $argumentsToTest, $optionsToTest)) {
         return $this->createResolvedCommand($result);
     }
     // If arguments were passed, we did not find the matching command.
     if ($argumentsToTest) {
         throw CannotResolveCommandException::nameNotFound(reset($argumentsToTest), $namedCommands);
     }
     // If no arguments were passed, run the application's default command.
     if ($result = $this->processDefaultCommands($args, $application->getDefaultCommands())) {
         return $this->createResolvedCommand($result);
     }
     // No default command is configured.
     throw CannotResolveCommandException::noDefaultCommand();
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 public function parseArgs(RawArgs $args, ArgsFormat $format, $lenient = false)
 {
     $this->setTokens($args->getTokens());
     $formatAdapter = new ArgsFormatInputDefinition($format);
     try {
         $this->bind($formatAdapter);
     } catch (RuntimeException $e) {
         if (!$lenient) {
             throw new CannotParseArgsException($e->getMessage());
         }
     }
     // Prevent failing validation if not all command names are given
     $this->insertMissingCommandNames($formatAdapter, $lenient);
     try {
         $this->validate();
     } catch (RuntimeException $e) {
         if (!$lenient) {
             throw new CannotParseArgsException($e->getMessage());
         }
     }
     return $this->createArgs($format, $args);
 }