Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ArgvInput.php

function ArgvInput::getFirstArgument

Overrides InputInterface::getFirstArgument

1 call to ArgvInput::getFirstArgument()
ArgvInput::getRawTokens in vendor/symfony/console/Input/ArgvInput.php
Returns un-parsed and not validated tokens.

File

vendor/symfony/console/Input/ArgvInput.php, line 272

Class

ArgvInput
ArgvInput represents an input coming from the CLI arguments.

Namespace

Symfony\Component\Console\Input

Code

public function getFirstArgument() : ?string {
    $isOption = false;
    foreach ($this->tokens as $i => $token) {
        if ($token && '-' === $token[0]) {
            if (str_contains($token, '=') || !isset($this->tokens[$i + 1])) {
                continue;
            }
            // If it's a long option, consider that everything after "--" is the option name.
            // Otherwise, use the last char (if it's a short option set, only the last one can take a value with space separator)
            $name = '-' === $token[1] ? substr($token, 2) : substr($token, -1);
            if (!isset($this->options[$name]) && !$this->definition
                ->hasShortcut($name)) {
                // noop
            }
            elseif ((isset($this->options[$name]) || isset($this->options[$name = $this->definition
                ->shortcutToName($name)])) && $this->tokens[$i + 1] === $this->options[$name]) {
                $isOption = true;
            }
            continue;
        }
        if ($isOption) {
            $isOption = false;
            continue;
        }
        return $token;
    }
    return null;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal