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

Breadcrumb

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

function Parser::parseLongOption

@psalm-param list<string> $longOptions

Throws

AmbiguousOptionException

OptionDoesNotAllowArgumentException

RequiredOptionArgumentMissingException

UnknownOptionException

1 call to Parser::parseLongOption()
Parser::parse in vendor/sebastian/cli-parser/src/Parser.php
@psalm-param list<string> $argv @psalm-param list<string> $longOptions

File

vendor/sebastian/cli-parser/src/Parser.php, line 160

Class

Parser

Namespace

SebastianBergmann\CliParser

Code

private function parseLongOption(string $argument, array $longOptions, array &$options, array &$argv) : void {
    $count = count($longOptions);
    $list = explode('=', $argument);
    $option = $list[0];
    $optionArgument = null;
    if (count($list) > 1) {
        $optionArgument = $list[1];
    }
    $optionLength = strlen($option);
    foreach ($longOptions as $i => $longOption) {
        $opt_start = substr($longOption, 0, $optionLength);
        if ($opt_start !== $option) {
            continue;
        }
        $opt_rest = substr($longOption, $optionLength);
        if ($opt_rest !== '' && $i + 1 < $count && $option[0] !== '=' && str_starts_with($longOptions[$i + 1], $option)) {
            throw new AmbiguousOptionException('--' . $option);
        }
        if (str_ends_with($longOption, '=')) {
            if (!str_ends_with($longOption, '==') && !strlen((string) $optionArgument)) {
                if (false === ($optionArgument = current($argv))) {
                    throw new RequiredOptionArgumentMissingException('--' . $option);
                }
                next($argv);
            }
        }
        elseif ($optionArgument) {
            throw new OptionDoesNotAllowArgumentException('--' . $option);
        }
        $fullOption = '--' . preg_replace('/={1,2}$/', '', $longOption);
        $options[] = [
            $fullOption,
            $optionArgument,
        ];
        return;
    }
    throw new UnknownOptionException('--' . $option);
}

API Navigation

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