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

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

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

Properties

Propertypublicarray  $arguments= 'array'

CommandlineArguments[]
Default valuearrayDetails
Type
array
Propertypublicstring  $executable= ''

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

Details
Type
string

Methods

methodpublic  __construct(  $to_process = null ) :
Parameters
Name Type Description
$to_process
methodpublic  __copy( ) :
methodpublic  __toString( ) :
methodpublic  addArguments(  $line ) :
Parameters
Name Type Description
$line
methodpublic  clear( ) :
Clear out the whole command line.
methodpublic  clearArgs( ) :
Clear out the arguments but leave the executable in place for another operation.
methodpublic  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
methodpublic  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
methodprotected  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
methodpublic  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
methodpublic  getArguments( ) :
Returns all arguments defined by addLine, addValue or the argument object.
methodpublic  getCommandline( ) : array
Returns the executable and all defined arguments.
Returns
Type Description
array
methodpublic  getExecutable( ) :
methodpublic  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.
methodpublic  setExecutable(  $executable ) :
Sets the executable to run.
Parameters
Name Type Description
$executable
methodpublic  size( ) : int
Returns
Type Description
int
methodpublic  toString(  $lines ) :
staticQuotes the parts of the given array in way that makes them usable as command line arguments.
Parameters
Name Type Description
$lines
methodpublic  translateCommandline( string $to_process ) : array
static
Parameters
Name Type Description
$to_process string
Returns
Type Description
array

\CommandlineArgument

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

package
phing.types

Properties

Propertyprivate  $outer= ''
Details
Type
Propertyprivate  $parts= 'array'
Default valuearrayDetails
Type

Methods

methodpublic  __construct(  $outer ) :
Parameters
Name Type Description
$outer
methodpublic  getParts( ) : array
Returns the parts this Argument consists of.
Returns
Type Description
array
methodpublic  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.
methodpublic  setLine( \line $line ) :
Line to split into several commandline arguments.
Parameters
Name Type Description
$line \line line to split into several commandline arguments
methodpublic  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.
methodpublic  setValue( string $value ) :
Sets a single commandline argument.
Parameters
Name Type Description
$value string a single commandline argument.

\CommandlineMarker

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

Propertyprivate  $outer= ''
Details
Type
Propertyprivate  $position= ''
Details
Type
Propertyprivate  $realPos= ''
Details
Type

Methods

methodpublic  __construct(  $outer,  $position ) :
Parameters
Name Type Description
$outer
$position
methodpublic  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.