# 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

Package: phing\types

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

### 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 ) : void`

Parameters

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

`__copy( ) : void`

`__toString( ) : void`

`addArguments( $line ) : void`

Parameters

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

`clear( ) : void`

Clear out the whole command line.

`clearArgs( ) : void`

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( ) : void`

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( ) : void`

`quoteArgument( $argument ) : void`
static

Put 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 ) : void`

Sets the executable to run.

Parameters

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

`size( ) : int`

Returns

Type | Description
--- | ---
int | Number of components in current commandline.

`toString( $lines ) : void`
static

Quotes 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

Package: phing\types

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

### Properties

`$outer= ''`
Details

Type
  n/a

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

Type
  n/a

### Methods

`__construct( $outer ) : void`

Parameters

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

`getParts( ) : array`

Returns the parts this Argument consists of.

Returns

Type | Description
--- | ---
array | string[]

`setFile( \value $value ) : void`

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 ) : void`

Line to split into several commandline arguments.

Parameters

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

`setPath( \value $value ) : void`

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 ) : void`

Sets a single commandline argument.

Parameters

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

## \CommandlineMarker
jump to top

Package: phing\types

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

### Properties

`$outer= ''`
Details

Type
  n/a

`$position= ''`
Details

Type
  n/a

`$realPos= '-1'`
Default value`-1` Details

Type
  n/a

### Methods

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

Parameters

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

`getPosition( ) : void`

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.17.1.