Constants

REGEX_STRING

REGEX_STRING = '([^\s]+?)(?:\s|(?<!\\\\)"|(?<!\\\\)\'|$)'

REGEX_QUOTED_STRING

REGEX_QUOTED_STRING = '(?:"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\')'

Properties

$definition

$definition : 

Type

$stream

$stream : 

Type

$options

$options : 

Type

$arguments

$arguments : 

Type

$interactive

$interactive : 

Type

$tokens

$tokens : 

Type

$parsed

$parsed : 

Type

Methods

__construct()

__construct(string  $input) 

Parameters

string $input

A string representing the parameters from the CLI

getFirstArgument()

getFirstArgument() 

{@inheritdoc}

hasParameterOption()

hasParameterOption(  $values,   $onlyParams = false) 

{@inheritdoc}

Parameters

$values
$onlyParams

getParameterOption()

getParameterOption(  $values,   $default = false,   $onlyParams = false) 

{@inheritdoc}

Parameters

$values
$default
$onlyParams

__toString()

__toString() : string

Returns a stringified representation of the args passed to the command.

Returns

string

validate()

validate() 

Validates the input.

isInteractive()

isInteractive() : boolean

Is this input means interactive?

Returns

boolean

setInteractive()

setInteractive(boolean  $interactive) 

Sets the input interactivity.

Parameters

boolean $interactive

If the input should be interactive

getArguments()

getArguments() : array

Returns all the given arguments merged with the default values.

Returns

array

getArgument()

getArgument(string  $name) : string|array<mixed,string>|null

Returns the argument value for a given argument name.

Parameters

string $name

The argument name

Returns

string|array<mixed,string>|null —

The argument value

setArgument()

setArgument(string  $name, string|array<mixed,string>|null  $value) 

Sets an argument value by name.

Parameters

string $name

The argument name

string|array<mixed,string>|null $value

The argument value

hasArgument()

hasArgument(string|integer  $name) : boolean

Returns true if an InputArgument object exists by name or position.

Parameters

string|integer $name

The InputArgument name or position

Returns

boolean —

true if the InputArgument object exists, false otherwise

getOptions()

getOptions() : array

Returns all the given options merged with the default values.

Returns

array

getOption()

getOption(string  $name) : string|array<mixed,string>|boolean|null

Returns the option value for a given option name.

Parameters

string $name

The option name

Returns

string|array<mixed,string>|boolean|null —

The option value

setOption()

setOption(string  $name, string|array<mixed,string>|boolean|null  $value) 

Sets an option value by name.

Parameters

string $name

The option name

string|array<mixed,string>|boolean|null $value

The option value

hasOption()

hasOption(string  $name) : boolean

Returns true if an InputOption object exists by name.

Parameters

string $name

The InputOption name

Returns

boolean —

true if the InputOption object exists, false otherwise

escapeToken()

escapeToken(string  $token) : string

Escapes a token through escapeshellarg if it contains unsafe chars.

Parameters

string $token

Returns

string

setStream()

setStream(resource  $stream) 

Sets the input stream to read from when interacting with the user.

This is mainly useful for testing purpose.

Parameters

resource $stream

The input stream

getStream()

getStream() : resource|null

Returns the input stream.

Returns

resource|null

setTokens()

setTokens(array  $tokens) 

Parameters

array $tokens

parse()

parse() 

Processes command line arguments.

parseShortOption()

parseShortOption(string  $token) 

Parses a short option.

Parameters

string $token

The current token

parseShortOptionSet()

parseShortOptionSet(string  $name) 

Parses a short option set.

Parameters

string $name

The current token

Throws

\Symfony\Component\Console\Exception\RuntimeException

When option given doesn't exist

parseLongOption()

parseLongOption(string  $token) 

Parses a long option.

Parameters

string $token

The current token

parseArgument()

parseArgument(string  $token) 

Parses an argument.

Parameters

string $token

The current token

Throws

\Symfony\Component\Console\Exception\RuntimeException

When too many arguments are given

addShortOption()

addShortOption(string  $shortcut, mixed  $value) 

Adds a short option value.

Parameters

string $shortcut

The short option key

mixed $value

The value for the option

Throws

\Symfony\Component\Console\Exception\RuntimeException

When option given doesn't exist

addLongOption()

addLongOption(string  $name, mixed  $value) 

Adds a long option value.

Parameters

string $name

The long option key

mixed $value

The value for the option

Throws

\Symfony\Component\Console\Exception\RuntimeException

When option given doesn't exist

tokenize()

tokenize(string  $input) : array

Tokenizes a string.

Parameters

string $input

The input to tokenize

Throws

\Symfony\Component\Console\Exception\InvalidArgumentException

When unable to parse input (should never happen)

Returns

array —

An array of tokens