Documentation

ShellInput extends StringInput
in package

A StringInput subclass specialized for code arguments.

Table of Contents

REGEX_QUOTED_STRING  = '(?:"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)')'
REGEX_STRING  = '([^\s]+?)(?:\s|(?<!\\)"|(?<!\\)'|$)'
$arguments  : mixed
$definition  : mixed
$interactive  : mixed
$options  : mixed
$stream  : mixed
$hasCodeArgument  : mixed
$parsed  : mixed
$tokenPairs  : mixed
Unlike the parent implementation's tokens, this contains an array of token/rest pairs, so that code arguments can be handled while parsing.
$tokens  : mixed
__construct()  : mixed
Constructor.
__toString()  : string
Returns a stringified representation of the args passed to the command.
bind()  : mixed
{@inheritdoc}
escapeToken()  : string
Escapes a token through escapeshellarg if it contains unsafe chars.
getArgument()  : string|array<string|int, string>|null
Returns the argument value for a given argument name.
getArguments()  : array<string|int, mixed>
Returns all the given arguments merged with the default values.
getFirstArgument()  : mixed
{@inheritdoc}
getOption()  : string|array<string|int, string>|bool|null
Returns the option value for a given option name.
getOptions()  : array<string|int, mixed>
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
Same as parent, but with some bonus handling for code arguments.
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.
parseShellArgument()  : mixed
Parses an argument, with bonus handling for code arguments.
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|(?<!\\)"|(?<!\\)'|$)'

Properties

$arguments

protected mixed $arguments = []

$definition

protected mixed $definition

$interactive

protected mixed $interactive = true

$options

protected mixed $options = []

$stream

protected mixed $stream

$hasCodeArgument

private mixed $hasCodeArgument = false

$tokenPairs

Unlike the parent implementation's tokens, this contains an array of token/rest pairs, so that code arguments can be handled while parsing.

private mixed $tokenPairs

Methods

__construct()

Constructor.

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

An array of parameters from the CLI (in the argv format)

Return values
mixed

__toString()

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

public __toString() : string
Return values
string

bind()

{@inheritdoc}

public bind(InputDefinition $definition) : mixed
Parameters
$definition : InputDefinition
Tags
throws
InvalidArgumentException

if $definition has CodeArgument before the final argument position

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(mixed $name) : string|array<string|int, string>|null
Parameters
$name : mixed

The argument name

Return values
string|array<string|int, string>|null

The argument value

getArguments()

Returns all the given arguments merged with the default values.

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

getFirstArgument()

{@inheritdoc}

public getFirstArgument() : mixed
Return values
mixed

getOption()

Returns the option value for a given option name.

public getOption(mixed $name) : string|array<string|int, string>|bool|null
Parameters
$name : mixed

The option name

Return values
string|array<string|int, string>|bool|null

The option value

getOptions()

Returns all the given options merged with the default values.

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

getParameterOption()

{@inheritdoc}

public getParameterOption(mixed $values[, mixed $default = false ][, mixed $onlyParams = false ]) : mixed
Parameters
$values : mixed
$default : mixed = false
$onlyParams : mixed = 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(mixed $name) : bool
Parameters
$name : mixed

The InputArgument name or position

Return values
bool

true if the InputArgument object exists, false otherwise

hasOption()

Returns true if an InputOption object exists by name.

public hasOption(mixed $name) : bool
Parameters
$name : mixed

The InputOption name

Return values
bool

true if the InputOption object exists, false otherwise

hasParameterOption()

{@inheritdoc}

public hasParameterOption(mixed $values[, mixed $onlyParams = false ]) : mixed
Parameters
$values : mixed
$onlyParams : mixed = 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(mixed $name, mixed $value) : mixed
Parameters
$name : mixed

The argument name

$value : mixed

The argument value

Return values
mixed

setInteractive()

Sets the input interactivity.

public setInteractive(mixed $interactive) : mixed
Parameters
$interactive : mixed

If the input should be interactive

Return values
mixed

setOption()

Sets an option value by name.

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

The option name

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

Same as parent, but with some bonus handling for code arguments.

protected parse() : mixed
Return values
mixed

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

The long option key

$value : mixed

The value for the option

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

The short option key

$value : mixed

The value for the option

Tags
throws
RuntimeException

When option given doesn't exist

Return values
mixed

parseArgument()

Parses an argument.

private parseArgument(string $token) : mixed
Parameters
$token : string

The current token

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

The current token

Return values
mixed

parseShellArgument()

Parses an argument, with bonus handling for code arguments.

private parseShellArgument(string $token, string $rest) : mixed
Parameters
$token : string

The current token

$rest : string

The remaining unparsed input, including the current token

Tags
throws
RuntimeException

When too many arguments are given

Return values
mixed

parseShortOption()

Parses a short option.

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

The current token

Return values
mixed

parseShortOptionSet()

Parses a short option set.

private parseShortOptionSet(string $name) : mixed
Parameters
$name : string

The current token

Tags
throws
RuntimeException

When option given doesn't exist

Return values
mixed

tokenize()

Tokenizes a string.

private tokenize(string $input) : array<string|int, mixed>

The version of this on StringInput is good, but doesn't handle code arguments if they're at all complicated. This does :)

Parameters
$input : string

The input to tokenize

Tags
throws
InvalidArgumentException

When unable to parse input (should never happen)

Return values
array<string|int, mixed>

An array of token/rest pairs

Search results