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

REGEX_QUOTED_STRING  = '(?:"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)')'
REGEX_STRING  = '([^\s]+?)(?:\s|(?<!\\)"|(?<!\\)'|$)'
REGEX_UNQUOTED_STRING  = '([^\s\\]+?)'
$arguments  : mixed
$definition  : mixed
$interactive  : mixed
$options  : mixed
$stream  : mixed
$parsed  : mixed
$tokens  : mixed
__construct()  : mixed
__toString()  : string
Returns a stringified representation of the args passed to the command.
bind()  : mixed
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|null>
Returns all the given arguments merged with the default values.
getFirstArgument()  : mixed
{@inheritdoc}
getOption()  : mixed
Returns the option value for a given option name.
getOptions()  : array<string|int, string|bool|int|float|array|null>
Returns all the given options merged with the default values.
getParameterOption()  : mixed
{@inheritdoc}
getStream()  : resource|null
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()  : mixed
{@inheritdoc}
isInteractive()  : bool
Is this input means interactive?
setArgument()  : mixed
Sets an argument value by name.
setInteractive()  : mixed
Sets the input interactivity.
setOption()  : mixed
Sets an option value by name.
setStream()  : mixed
Sets the input stream to read from when interacting with the user.
validate()  : mixed
Validates the input.
parse()  : mixed
Processes command line arguments.
parseToken()  : bool
setTokens()  : mixed
addLongOption()  : mixed
Adds a long option value.
addShortOption()  : mixed
Adds a short option value.
parseArgument()  : mixed
Parses an argument.
parseLongOption()  : mixed
Parses a long option.
parseShortOption()  : mixed
Parses a short option.
parseShortOptionSet()  : mixed
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|(?<!\\)"|(?<!\\)'|$)'

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 mixed $stream

Methods

__construct()

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

A string representing the parameters from the CLI

Return values
mixed

__toString()

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

public __toString() : string
Return values
string

bind()

Binds the current Input instance with the given arguments and options.

public bind(InputDefinition $definition) : mixed
Parameters
$definition : InputDefinition
Return values
mixed

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
Return values
mixed

getArguments()

Returns all the given arguments merged with the default values.

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

getFirstArgument()

{@inheritdoc}

public getFirstArgument() : mixed
Return values
mixed

getOption()

Returns the option value for a given option name.

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

getOptions()

Returns all the given options merged with the default values.

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

getParameterOption()

{@inheritdoc}

public getParameterOption(mixed $values[, mixed $default = false ][, bool $onlyParams = false ]) : mixed
Parameters
$values : mixed
$default : mixed = false
$onlyParams : bool = false
Return values
mixed

getStream()

Returns the input stream.

public getStream() : resource|null
Return values
resource|null

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()

{@inheritdoc}

public hasParameterOption(mixed $values[, bool $onlyParams = false ]) : mixed
Parameters
$values : mixed
$onlyParams : bool = false
Return values
mixed

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) : mixed
Parameters
$name : string
$value : mixed

The argument value

Return values
mixed

setInteractive()

Sets the input interactivity.

public setInteractive(bool $interactive) : mixed
Parameters
$interactive : bool
Return values
mixed

setOption()

Sets an option value by name.

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

The option value

Return values
mixed

setStream()

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

public setStream(mixed $stream) : mixed
Parameters
$stream : mixed

The input stream

Return values
mixed

validate()

Validates the input.

public validate() : mixed
Return values
mixed

parse()

Processes command line arguments.

protected abstract parse() : mixed
Return values
mixed

parseToken()

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

setTokens()

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

addLongOption()

Adds a long option value.

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

When option given doesn't exist

Return values
mixed

addShortOption()

Adds a short option value.

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

When option given doesn't exist

Return values
mixed

parseArgument()

Parses an argument.

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

When too many arguments are given

Return values
mixed

parseLongOption()

Parses a long option.

private parseLongOption(string $token) : mixed
Parameters
$token : string
Return values
mixed

parseShortOption()

Parses a short option.

private parseShortOption(string $token) : mixed
Parameters
$token : string
Return values
mixed

parseShortOptionSet()

Parses a short option set.

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

When option given doesn't exist

Return values
mixed

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>

Search results