Documentation

StringInput extends ArgvInput
in package

StringInput represents an input provided as a string.

Usage:

$input = new StringInput('foo --bar="foobar"');

Tags
author

Fabien Potencier fabien@symfony.com

Table of Contents

Constants

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

Properties

$arguments  : mixed
$definition  : mixed
$interactive  : mixed
$options  : mixed
$stream  : resource
$parsed  : array<string|int, mixed>
$tokens  : array<string|int, mixed>

Methods

__construct()  : mixed
__toString()  : string
Returns a stringified representation of the args passed to the command.
bind()  : void
Binds the current Input instance with the given arguments and options.
escapeToken()  : string
Escapes a token through escapeshellarg if it contains unsafe chars.
getArgument()  : mixed
Returns the argument value for a given argument name.
getArguments()  : array<string|int, string|bool|int|float|array<string|int, mixed>|null>
Returns all the given arguments merged with the default values.
getFirstArgument()  : string|null
Returns the first argument from the raw parameters (not parsed).
getOption()  : mixed
Returns the option value for a given option name.
getOptions()  : array<string|int, string|bool|int|float|array<string|int, mixed>|null>
Returns all the given options merged with the default values.
getParameterOption()  : mixed
Returns the value of a raw option (not parsed).
getStream()  : resource
Returns the input stream.
hasArgument()  : bool
Returns true if an InputArgument object exists by name or position.
hasOption()  : bool
Returns true if an InputOption object exists by name.
hasParameterOption()  : bool
Returns true if the raw parameters (not parsed) contain a value.
isInteractive()  : bool
Is this input means interactive?
setArgument()  : void
Sets an argument value by name.
setInteractive()  : void
Sets the input interactivity.
setOption()  : void
Sets an option value by name.
setStream()  : void
Sets the input stream to read from when interacting with the user.
validate()  : void
Validates the input.
parse()  : void
Processes command line arguments.
parseToken()  : bool
setTokens()  : void
addLongOption()  : void
Adds a long option value.
addShortOption()  : void
Adds a short option value.
parseArgument()  : void
Parses an argument.
parseLongOption()  : void
Parses a long option.
parseShortOption()  : void
Parses a short option.
parseShortOptionSet()  : void
Parses a short option set.
tokenize()  : array<string|int, mixed>
Tokenizes a string.

Constants

REGEX_QUOTED_STRING

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

REGEX_STRING

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

since Symfony 6.1

REGEX_UNQUOTED_STRING

public mixed REGEX_UNQUOTED_STRING = '([^\s\\\\]+?)'

Properties

$arguments

protected mixed $arguments = []

$definition

protected mixed $definition

$interactive

protected mixed $interactive = true

$options

protected mixed $options = []

$stream

protected resource $stream

$parsed

private array<string|int, mixed> $parsed

$tokens

private array<string|int, mixed> $tokens

Methods

__construct()

public __construct(string $input) : mixed
Parameters
$input : string

A string representing the parameters from the CLI

__toString()

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

public __toString() : string
Return values
string

escapeToken()

Escapes a token through escapeshellarg if it contains unsafe chars.

public escapeToken(string $token) : string
Parameters
$token : string
Return values
string

getArgument()

Returns the argument value for a given argument name.

public getArgument(string $name) : mixed
Parameters
$name : string

getArguments()

Returns all the given arguments merged with the default values.

public getArguments() : array<string|int, string|bool|int|float|array<string|int, mixed>|null>
Return values
array<string|int, string|bool|int|float|array<string|int, mixed>|null>

getFirstArgument()

Returns the first argument from the raw parameters (not parsed).

public getFirstArgument() : string|null
Return values
string|null

getOption()

Returns the option value for a given option name.

public getOption(string $name) : mixed
Parameters
$name : string

getOptions()

Returns all the given options merged with the default values.

public getOptions() : array<string|int, string|bool|int|float|array<string|int, mixed>|null>
Return values
array<string|int, string|bool|int|float|array<string|int, mixed>|null>

getParameterOption()

Returns the value of a raw option (not parsed).

public getParameterOption(string|array<string|int, mixed> $values[, string|bool|int|float|array<string|int, mixed>|null $default = false ][, bool $onlyParams = false ]) : mixed

This method is to be used to introspect the input parameters before they have been validated. It must be used carefully. Does not necessarily return the correct result for short options when multiple flags are combined in the same option.

Parameters
$values : string|array<string|int, mixed>

The value(s) to look for in the raw parameters (can be an array)

$default : string|bool|int|float|array<string|int, mixed>|null = false

The default value to return if no result is found

$onlyParams : bool = false

Only check real parameters, skip those following an end of options (--) signal

getStream()

Returns the input stream.

public getStream() : resource
Return values
resource

hasArgument()

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

public hasArgument(string $name) : bool
Parameters
$name : string
Return values
bool

hasOption()

Returns true if an InputOption object exists by name.

public hasOption(string $name) : bool
Parameters
$name : string
Return values
bool

hasParameterOption()

Returns true if the raw parameters (not parsed) contain a value.

public hasParameterOption(string|array<string|int, mixed> $values[, bool $onlyParams = false ]) : bool

This method is to be used to introspect the input parameters before they have been validated. It must be used carefully. Does not necessarily return the correct result for short options when multiple flags are combined in the same option.

Parameters
$values : string|array<string|int, mixed>

The values to look for in the raw parameters (can be an array)

$onlyParams : bool = false

Only check real parameters, skip those following an end of options (--) signal

Return values
bool

isInteractive()

Is this input means interactive?

public isInteractive() : bool
Return values
bool

setArgument()

Sets an argument value by name.

public setArgument(string $name, mixed $value) : void
Parameters
$name : string
$value : mixed

setInteractive()

Sets the input interactivity.

public setInteractive(bool $interactive) : void
Parameters
$interactive : bool

setOption()

Sets an option value by name.

public setOption(string $name, mixed $value) : void
Parameters
$name : string
$value : mixed

setStream()

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

public setStream(resource $stream) : void
Parameters
$stream : resource

validate()

Validates the input.

public validate() : void

parse()

Processes command line arguments.

protected parse() : void

parseToken()

protected parseToken(string $token, bool $parseOptions) : bool
Parameters
$token : string
$parseOptions : bool
Return values
bool

setTokens()

protected setTokens(array<string|int, mixed> $tokens) : void
Parameters
$tokens : array<string|int, mixed>

addLongOption()

Adds a long option value.

private addLongOption(string $name, mixed $value) : void
Parameters
$name : string
$value : mixed
Tags
throws
RuntimeException

When option given doesn't exist

addShortOption()

Adds a short option value.

private addShortOption(string $shortcut, mixed $value) : void
Parameters
$shortcut : string
$value : mixed
Tags
throws
RuntimeException

When option given doesn't exist

parseArgument()

Parses an argument.

private parseArgument(string $token) : void
Parameters
$token : string
Tags
throws
RuntimeException

When too many arguments are given

parseLongOption()

Parses a long option.

private parseLongOption(string $token) : void
Parameters
$token : string

parseShortOption()

Parses a short option.

private parseShortOption(string $token) : void
Parameters
$token : string

parseShortOptionSet()

Parses a short option set.

private parseShortOptionSet(string $name) : void
Parameters
$name : string
Tags
throws
RuntimeException

When option given doesn't exist

tokenize()

Tokenizes a string.

private tokenize(string $input) : array<string|int, mixed>
Parameters
$input : string
Tags
throws
InvalidArgumentException

When unable to parse input (should never happen)

Return values
array<string|int, mixed>

        
On this page

Search results