# classes/phing/types/Commandline.php

Commandline objects help handling command lines specifying processes to execute.

The class can be used to define a command line as nested elements or as a helper to define a command line by an application.

<

p> `<someelement>
<acommandline executable="/executable/to/run">
<argument value="argument 1" />
<argument line="argument_1 argument_2 argument_3" />
<argument value="argument 4" />
</acommandline>
</someelement>
` The element `someelement` must provide a method `createAcommandline` which returns an instance of this class.

author
  thomas.haas@softwired-inc.com
author
  Stefan Bodewig
package
  phing.types

## \Commandline
jump to top

Commandline objects help handling command lines specifying processes to execute.

The class can be used to define a command line as nested elements or as a helper to define a command line by an application.

<

p> `<someelement>
<acommandline executable="/executable/to/run">
<argument value="argument 1" />
<argument line="argument_1 argument_2 argument_3" />
<argument value="argument 4" />
</acommandline>
</someelement>
` The element `someelement` must provide a method `createAcommandline` which returns an instance of this class.

author
  thomas.haas@softwired-inc.com
author
  Stefan Bodewig
package
  phing.types

### Constants

`DISCLAIMER = 'The ' characters around the executable and arguments are not part of the command.'`

### Properties

`array $arguments= 'array'`

CommandlineArguments[]
Default value `array` Details

Type
  array

`string $executable= ''`

Full path (if not on %PATH% env var) to executable program.

Details

Type
  string

### Methods

`__construct( $to_process = null ) :`
Parameters

Name | Type | Description
--- | --- | ---
$to_process |  |

`__copy( ) :`
`__toString( ) :`
`addArguments( $line ) :`
Parameters

Name | Type | Description
--- | --- | ---
$line |  |

`clear( ) :`
Clear out the whole command line.
`clearArgs( ) :`
Clear out the arguments but leave the executable in place for another operation.
`createArgument( boolean $insertAtStart = false ) : \CommandlineArgument`
Creates an argument object and adds it to our list of args.

Each commandline object has at most one instance of the argument class.

Parameters

Name | Type | Description
--- | --- | ---
$insertAtStart | boolean | if true, the argument is inserted at the beginning of the list of args, otherwise it is appended.

Returns

Type | Description
--- | ---
\CommandlineArgument |

`createMarker( ) : \CommandlineMarker`
Return a marker.

This marker can be used to locate a position on the commandline - to insert something for example - when all parameters have been set.

Returns

Type | Description
--- | ---
\CommandlineMarker |

`describeArguments( \$args $args = null, \$offset $offset = 0 ) : string`
Returns a String that describes the arguments suitable for verbose output before a call to `Runtime.exec(String[])`
Parameters

Name | Type | Description
--- | --- | ---
$args | \$args | arguments to use (default is to use current class args)
$offset | \$offset | ignore entries before this index

Returns

Type | Description
--- | ---
string |

`describeCommand( array $args = null ) : string`
Returns a String that describes the command and arguments suitable for verbose output before a call to `Runtime.exec(String[])`.

This method assumes that the first entry in the array is the executable to run.

Parameters

Name | Type | Description
--- | --- | ---
$args | array | CommandlineArgument[] to use

Returns

Type | Description
--- | ---
string |

`getArguments( ) :`
Returns all arguments defined by `addLine`, `addValue` or the argument object.
`getCommandline( ) : array`
Returns the executable and all defined arguments.
Returns

Type | Description
--- | ---
array |

`getExecutable( ) :`
`quoteArgument( $argument ) :`
staticPut quotes around the given String if necessary.

If the argument doesn't include spaces or quotes, return it as is. If it contains double quotes, use single quotes - else surround the argument by double quotes.

Parameters

Name | Type | Description
--- | --- | ---
$argument |  |

Details

exception
  BuildException if the argument contains both, single and double quotes.

`setExecutable( $executable ) :`
Sets the executable to run.
Parameters

Name | Type | Description
--- | --- | ---
$executable |  |

`size( ) : int`
Returns

Type | Description
--- | ---
int |

`toString( $lines ) :`
staticQuotes the parts of the given array in way that makes them usable as command line arguments.
Parameters

Name | Type | Description
--- | --- | ---
$lines |  |

`translateCommandline( string $to_process ) : array`
static
Parameters

Name | Type | Description
--- | --- | ---
$to_process | string |

Returns

Type | Description
--- | ---
array |

## \CommandlineArgument
jump to top

"Inner" class used for nested xml command line definitions.

package
  phing.types

### Properties

`$outer= ''`
Details

Type

`$parts= 'array'`
Default value `array` Details

Type

### Methods

`__construct( $outer ) :`
Parameters

Name | Type | Description
--- | --- | ---
$outer |  |

`getParts( ) : array`
Returns the parts this Argument consists of.
Returns

Type | Description
--- | ---
array |

`setFile( \value $value ) :`
Sets a single commandline argument to the absolute filename of the given file.
Parameters

Name | Type | Description
--- | --- | ---
$value | \value | a single commandline argument.

`setLine( \line $line ) :`
Line to split into several commandline arguments.
Parameters

Name | Type | Description
--- | --- | ---
$line | \line | line to split into several commandline arguments

`setPath( \value $value ) :`
Sets a single commandline argument and treats it like a PATH - ensures the right separator for the local platform is used.
Parameters

Name | Type | Description
--- | --- | ---
$value | \value | a single commandline argument.

`setValue( string $value ) :`
Sets a single commandline argument.
Parameters

Name | Type | Description
--- | --- | ---
$value | string | a single commandline argument.

## \CommandlineMarker
jump to top

Class to keep track of the position of an Argument.

This class is there to support the srcfile and targetfile elements of <execon> and <transform> - don't know whether there might be additional use cases.

--SB

package
  phing.types

### Properties

`$outer= ''`
Details

Type

`$position= ''`
Details

Type

`$realPos= ''`
Details

Type

### Methods

`__construct( $outer, $position ) :`
Parameters

Name | Type | Description
--- | --- | ---
$outer |  |
$position |  |

`getPosition( ) :`
Return the number of arguments that preceeded this marker.

The name of the executable - if set - is counted as the very first argument.

Documentation was generated by DocBlox 0.13.1.