TYPO3  7.6
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
ArgvInput Class Reference
Inheritance diagram for ArgvInput:
Input InputInterface StringInput

Public Member Functions

 __construct (array $argv=null, InputDefinition $definition=null)
 
 getFirstArgument ()
 
 hasParameterOption ($values)
 
 getParameterOption ($values, $default=false)
 
 __toString ()
 
- Public Member Functions inherited from Input
 __construct (InputDefinition $definition=null)
 
 bind (InputDefinition $definition)
 
 validate ()
 
 isInteractive ()
 
 setInteractive ($interactive)
 
 getArguments ()
 
 getArgument ($name)
 
 setArgument ($name, $value)
 
 hasArgument ($name)
 
 getOptions ()
 
 getOption ($name)
 
 setOption ($name, $value)
 
 hasOption ($name)
 
 escapeToken ($token)
 

Protected Member Functions

 setTokens (array $tokens)
 
 parse ()
 
- Protected Member Functions inherited from Input
 parse ()
 

Private Member Functions

 parseShortOption ($token)
 
 parseShortOptionSet ($name)
 
 parseLongOption ($token)
 
 parseArgument ($token)
 
 addShortOption ($shortcut, $value)
 
 addLongOption ($name, $value)
 

Private Attributes

 $tokens
 
 $parsed
 

Additional Inherited Members

- Protected Attributes inherited from Input
 $definition
 
 $options = array()
 
 $arguments = array()
 
 $interactive = true
 

Detailed Description

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.

Author
Fabien Potencier fabie.nosp@m.n@sy.nosp@m.mfony.nosp@m..com
See Also
http://www.gnu.org/software/libc/manual/html_node/Argument-Syntax.html
http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap12.html#tag_12_02

Definition at line 41 of file ArgvInput.php.

Constructor & Destructor Documentation

__construct ( array  $argv = null,
InputDefinition  $definition = null 
)

Constructor.

Parameters
array$argvAn array of parameters from the CLI (in the argv format)
InputDefinition$definitionA InputDefinition instance

Definition at line 54 of file ArgvInput.php.

References Input\$definition.

Member Function Documentation

__toString ( )

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

Returns
string

Definition at line 336 of file ArgvInput.php.

References ArgvInput\$tokens.

addLongOption (   $name,
  $value 
)
private

Adds a long option value.

Parameters
string$nameThe long option key
mixed$valueThe value for the option
Exceptions
\RuntimeExceptionWhen option given doesn't exist

Definition at line 210 of file ArgvInput.php.

References elseif.

Referenced by ArgvInput\addShortOption(), ArgvInput\parseLongOption(), and ArgvInput\parseShortOptionSet().

addShortOption (   $shortcut,
  $value 
)
private

Adds a short option value.

Parameters
string$shortcutThe short option key
mixed$valueThe value for the option
Exceptions
\RuntimeExceptionWhen option given doesn't exist

Definition at line 193 of file ArgvInput.php.

References ArgvInput\addLongOption().

Referenced by ArgvInput\parseShortOption().

getFirstArgument ( )

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

Returns
string The value of the first argument or null otherwise

Implements InputInterface.

Definition at line 262 of file ArgvInput.php.

getParameterOption (   $values,
  $default = false 
)

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$valuesThe value(s) to look for in the raw parameters (can be an array)
mixed$defaultThe default value to return if no result is found
Returns
mixed The option value

Implements InputInterface.

Definition at line 309 of file ArgvInput.php.

References ArgvInput\$tokens.

hasParameterOption (   $values)

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$valuesThe value(s) to look for in the raw parameters (can be an array)
Returns
bool true if the value is contained in the raw parameters

Implements InputInterface.

Definition at line 283 of file ArgvInput.php.

parse ( )
protected

Processes command line arguments.

Definition at line 76 of file ArgvInput.php.

References ArgvInput\$tokens, elseif, ArgvInput\parseArgument(), ArgvInput\parseLongOption(), and ArgvInput\parseShortOption().

parseArgument (   $token)
private

Parses an argument.

Parameters
string$tokenThe current token
Exceptions
\RuntimeExceptionWhen too many arguments are given

Definition at line 165 of file ArgvInput.php.

References elseif.

Referenced by ArgvInput\parse().

parseLongOption (   $token)
private

Parses a long option.

Parameters
string$tokenThe current token

Definition at line 147 of file ArgvInput.php.

References ArgvInput\addLongOption().

Referenced by ArgvInput\parse().

parseShortOption (   $token)
private

Parses a short option.

Parameters
string$tokenThe current token.

Definition at line 100 of file ArgvInput.php.

References ArgvInput\addShortOption(), and ArgvInput\parseShortOptionSet().

Referenced by ArgvInput\parse().

parseShortOptionSet (   $name)
private

Parses a short option set.

Parameters
string$nameThe current token
Exceptions
\RuntimeExceptionWhen option given doesn't exist

Definition at line 123 of file ArgvInput.php.

References ArgvInput\addLongOption().

Referenced by ArgvInput\parseShortOption().

setTokens ( array  $tokens)
protected

Definition at line 68 of file ArgvInput.php.

References ArgvInput\$tokens.

Referenced by StringInput\__construct().

Member Data Documentation

$parsed
private

Definition at line 44 of file ArgvInput.php.

$tokens
private