SymfonyComponentConsoleInputArgvInput

ArgvInput represents an input coming from the CLI arguments.

Usage:

$input = new ArgvInput();

By default, the $_SERVER['argv'] array is used for the input values.

This can be overridden by explicitly passing the input values in the constructor:

$input = new ArgvInput($_SERVER['argv']);

If you pass it yourself, don't forget that the first element of the array is the name of the running application.

When passing an argument to the constructor, be sure that it respects the same rules as the argv one. It's almost always better to use the StringInput when you want to provide your own input.

File
vendorSymfonyComponentConsoleInputArgvInput.php
Package
Default
Class hierarchy
SymfonyComponentConsoleInputArgvInput
See also

Tags

author

Fabien Potencier fabien@symfony.com

api

Properties

$definition

$definition : 

Type

Inherited from
SymfonyComponentConsoleInputInput

Tags

None found

$options

$options : 

Type

Inherited from
SymfonyComponentConsoleInputInput

Tags

None found

$arguments

$arguments : 

Type

Inherited from
SymfonyComponentConsoleInputInput

Tags

None found

$interactive

$interactive : 

Type

Inherited from
SymfonyComponentConsoleInputInput

Tags

None found

$tokens

$tokens : 

Type

Tags

None found

$parsed

$parsed : 

Type

Tags

None found

Methods

__construct()

__construct(array  $argv = null, \Symfony\Component\Console\Input\InputDefinition  $definition = null) 

Constructor.

Parameters

array $argv

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

SymfonyComponentConsoleInputInputDefinition $definition

A InputDefinition instance

Tags

api

bind()

bind(\Symfony\Component\Console\Input\InputDefinition  $definition) 

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

Parameters

SymfonyComponentConsoleInputInputDefinition $definition

A InputDefinition instance

Inherited from
SymfonyComponentConsoleInputInput

Tags

None found

validate()

validate() 

Validates the input.

Throws an exception when not enough arguments are given.

Throws

RuntimeException

When not enough arguments are given

Inherited from
SymfonyComponentConsoleInputInput

Tags

None found

isInteractive()

isInteractive() : Boolean

Checks if the input is interactive.

Returns

Boolean —

Returns true if the input is interactive

Inherited from
SymfonyComponentConsoleInputInput

Tags

None found

setInteractive()

setInteractive(Boolean  $interactive) 

Sets the input interactivity.

Parameters

Boolean $interactive

If the input should be interactive

Inherited from
SymfonyComponentConsoleInputInput

Tags

None found

getArguments()

getArguments() : array

Returns the argument values.

Returns

array —

An array of argument values

Inherited from
SymfonyComponentConsoleInputInput

Tags

None found

getArgument()

getArgument(string  $name) : mixed

Returns the argument value for a given argument name.

Parameters

string $name

The argument name

Throws

InvalidArgumentException

When argument given doesn't exist

Returns

mixed —

The argument value

Inherited from
SymfonyComponentConsoleInputInput

Tags

None found

setArgument()

setArgument(string  $name, string  $value) 

Sets an argument value by name.

Parameters

string $name

The argument name

string $value

The argument value

Throws

InvalidArgumentException

When argument given doesn't exist

Inherited from
SymfonyComponentConsoleInputInput

Tags

None found

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

Inherited from
SymfonyComponentConsoleInputInput

Tags

None found

getOptions()

getOptions() : array

Returns the options values.

Returns

array —

An array of option values

Inherited from
SymfonyComponentConsoleInputInput

Tags

None found

getOption()

getOption(string  $name) : mixed

Returns the option value for a given option name.

Parameters

string $name

The option name

Throws

InvalidArgumentException

When option given doesn't exist

Returns

mixed —

The option value

Inherited from
SymfonyComponentConsoleInputInput

Tags

None found

setOption()

setOption(string  $name, string  $value) 

Sets an option value by name.

Parameters

string $name

The option name

string $value

The option value

Throws

InvalidArgumentException

When option given doesn't exist

Inherited from
SymfonyComponentConsoleInputInput

Tags

None found

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

Inherited from
SymfonyComponentConsoleInputInput

Tags

None found

getFirstArgument()

getFirstArgument() : string

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

Returns

string —

The value of the first argument or null otherwise

Tags

None found

hasParameterOption()

hasParameterOption(string|array  $values) : Boolean

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

This method is to be used to introspect the input parameters before they have been validated. It must be used carefully.

Parameters

string|array $values

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

Returns

Boolean —

true if the value is contained in the raw parameters

Tags

None found

getParameterOption()

getParameterOption(string|array  $values, mixed  $default = false) : mixed

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

This method is to be used to introspect the input parameters before they have been validated. It must be used carefully.

Parameters

string|array $values

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

mixed $default

The default value to return if no result is found

Returns

mixed —

The option value

Tags

None found

parse()

parse() 

Processes command line arguments.

Tags

None found

setTokens()

setTokens(array  $tokens) 

Parameters

array $tokens

Tags

None found

parseShortOption()

parseShortOption(string  $token) 

Parses a short option.

Parameters

string $token

The current token.

Tags

None found

parseShortOptionSet()

parseShortOptionSet(string  $name) 

Parses a short option set.

Parameters

string $name

The current token

Throws

RuntimeException

When option given doesn't exist

Tags

None found

parseLongOption()

parseLongOption(string  $token) 

Parses a long option.

Parameters

string $token

The current token

Tags

None found

parseArgument()

parseArgument(string  $token) 

Parses an argument.

Parameters

string $token

The current token

Throws

RuntimeException

When too many arguments are given

Tags

None found

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

RuntimeException

When option given doesn't exist

Tags

None found

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

RuntimeException

When option given doesn't exist

Tags

None found