Phing.php
\Phing
Entry point into Phing. This class handles the full lifecycle of a build -- from parsing & handling commandline arguments to assembling the project to shutting down and cleaning up in the end.
If you are invoking Phing from an external application, this is still the class to use. Your applicaiton can invoke the start() method, passing any commandline arguments or additional properties.
- Author
- Andreas Aderhold
- Author
- Hans Lellelid
- Version
- $Id: 1ad418f51ac07c9afaadf1c1f4befd5535f5b390 $
Constants
Properties

$capturedPhpErrors= 'array()'
Array of captured PHP errors
array()Details- Type
- n/a

\Properties
$definedProps= ''
Set of properties that are passed in from commandline or invoking code.
- Type
- \Properties

boolean
$isLogFileUsed= 'false'
falseDetails- Type
- boolean

$listeners= 'array()'
Names of classes to add as listeners to project
array()Details- Type
- n/a

$msgOutputLevel= 'Project::MSG_INFO'
Our current message output status. Follows Project::MSG_XXX
Project::MSG_INFODetails- Type
- n/a

array
$origIniSettings= 'array()'
Array to hold original ini settings that Phing changes (and needs to restore in restoreIni() method).
Struct of array(setting-name => setting-value)array()Details- Type
- array
- See
- \restoreIni()

$phpErrorCapture= 'false'
Whether to capture PHP errors to buffer.
falseDetails- Type
- n/a

$projectHelp= 'false'
Indicates we should only parse and display the project help information
falseDetails- Type
- n/a

$properties= 'array()'
System-wide static properties (moved from System)
array()Details- Type
- n/a
Methods

__import(
string $path, mixed $classpath
=
null
)
:
voidImport a PHP file
| Name | Type | Description |
|---|---|---|
| $path | string | Path to the PHP file |
| $classpath | mixed | String or object supporting __toString() |
| Exception | Description |
|---|---|
| \BuildException | - if cannot find the specified file |

_findBuildFile(
string $start, string $suffix
)
:
\PhingFileSearch parent directories for the build file.
Takes the given target as a suffix to append to each parent directory in search of a build file. Once the root of the file-system has been reached an exception is thrown.
| Name | Type | Description |
|---|---|---|
| $start | string | Start file path. |
| $suffix | string | Suffix filename to look for in parents. |
| Type | Description |
|---|---|
| \PhingFile | A handle to the build file |
| Exception | Description |
|---|---|
| \BuildException | Failed to locate a build file |

_getParentFile(
\PhingFile $file
)
:
\PhingFileHelper to get the parent file for a given file.
| Name | Type | Description |
|---|---|---|
| $file | \PhingFile |
| Type | Description |
|---|---|
| \PhingFile | Parent file or null if none |

_printTargets(
array $names, array $descriptions, string $heading, int $maxlen
)
:
voidWrites a formatted list of target names with an optional description.
| Name | Type | Description |
|---|---|---|
| $names | array | The names to be printed. Must not be |
| $descriptions | array | The associated target descriptions. May be |
| $heading | string | The heading to display. Should not be |
| $maxlen | int | The maximum length of the names of the targets. If descriptions are given, they are padded to this position so they line up (so long as the names really are shorter than this). |

addBuildListeners(
\Project $project
)
:
voidBind any registered build listeners to this project.
This means adding the logger and any build listeners that were specified with -listener arg.
| Name | Type | Description |
|---|---|---|
| $project | \Project |

addInputHandler(
\Project $project
)
:
voidCreates the InputHandler and adds it to the project.
| Name | Type | Description |
|---|---|---|
| $project | \Project | the project instance. |
| Exception | Description |
|---|---|
| \BuildException | if a specified InputHandler class could not be loaded. |

clearCapturedPhpErrors(
)
:
voidClears the captured errors without affecting the starting/stopping of the capture.

convertShorthand(
string $val
)
:
voidConverts shorthand notation values as returned by ini_get()
| Name | Type | Description |
|---|---|---|
| $val | string |
- See
- \http://www.php.net/ini_get

createLogger(
)
:
\BuildLoggerCreates the default build logger for sending build events to the log.
| Type | Description |
|---|---|
| \BuildLogger | The created Logger |

execute(
array $args
)
:
voidSetup/initialize Phing environment from commandline args.
| Name | Type | Description |
|---|---|---|
| $args | array | commandline args passed to phing shell. |

fire(
array $args
)
:
voidCommand line entry point. This method kicks off the building of a project object and executes a build using either a given target or the default target.
| Name | Type | Description |
|---|---|---|
| $args | array | Command line args. |

getCapturedPhpErrors(
)
:
arrayGets any PHP errors that were captured to buffer.
| Type | Description |
|---|---|
| array | array('message' => message, 'line' => line number, 'file' => file name, 'level' => error level) |

getCurrentProject(
)
:
\ProjectGets the current Project.
| Type | Description |
|---|---|
| \Project | Current Project or NULL if none is set yet/still. |

getDefinedProperty(
string $name
)
:
stringThis gets a property that was set via command line or otherwise passed into Phing.
"Defined" in this case means "externally defined". The reason this method exists is to provide a public means of accessing commandline properties for (e.g.) logger or listener scripts. E.g. to specify which logfile to use, PearLogger needs to be able to access the pear.log.name property.
| Name | Type | Description |
|---|---|---|
| $name | string |
| Type | Description |
|---|---|
| string | value of found property (or null, if none found). |

getErrorStream(
)
:
\OutputStreamGets the stream to use for error output.
| Type | Description |
|---|---|
| \OutputStream |

getMsgOutputLevel(
)
:
intMaking output level a static property so that this property can be accessed by other parts of the system, enabling us to display more information -- e.g. backtraces -- for "debug" level.
| Type | Description |
|---|---|
| int |

getOutputStream(
)
:
\OutputStreamGets the stream to use for standard (non-error) output.
| Type | Description |
|---|---|
| \OutputStream |

getPhingVersion(
)
:
stringGets the current Phing version based on VERSION.TXT file.
| Type | Description |
|---|---|
| string |
| Exception | Description |
|---|---|
| \BuildException | - if unable to find version file. |

getProperty(
$propName
)
:
stringReturns property value for a System property.
System properties are "global" properties like application.startdir, and user.dir. Many of these correspond to similar properties in Java or Ant.
| Name | Type | Description |
|---|---|---|
| $propName |
| Type | Description |
|---|---|
| string | Value of found property (or null, if none found). |

getResourcePath(
$path
)
:
stringLooks on include path for specified file.
| Name | Type | Description |
|---|---|---|
| $path |
| Type | Description |
|---|---|
| string | File found (null if no file found). |

halt(
)
:
voidHalts the system.
- Deprecated
- This method is deprecated and is no longer called by Phing internally. Any normal shutdown routines are handled by the shutdown() method.
- See
- \shutdown()

handleLogfile(
)
:
voidClose logfiles, if we have been writing to them.
- Since
- Phing 2.3.0

handlePhpError(
$level, $message, $file, $line
)
:
voidError handler for PHP errors encountered during the build.
This uses the logging for the currently configured project.
| Name | Type | Description |
|---|---|---|
| $level | ||
| $message | ||
| $file | ||
| $line |

import(
string $dotPath, mixed $classpath
=
null
)
:
stringImport a dot-path notation class path.
| Name | Type | Description |
|---|---|---|
| $dotPath | string | |
| $classpath | mixed | String or object supporting __toString() |
| Type | Description |
|---|---|
| string | The unqualified classname (which can be instantiated). |
| Exception | Description |
|---|---|
| \BuildException | - if cannot find the specified file |

initializeOutputStreams(
)
:
voidSets the stdout and stderr streams if they are not already set.

log(
string $message, int $priority
=
Project::MSG_INFO
)
:
voidA static convenience method to send a log to the current (last-setup) Project.
If there is no currently-configured Project, then this will do nothing.
| Name | Type | Description |
|---|---|---|
| $message | string | |
| $priority | int | Project::MSG_INFO, etc. |

printDescription(
$project
)
:
voidPrint the project description, if any
| Name | Type | Description |
|---|---|---|
| $project |

printMessage(
\Exception $t
)
:
voidPrints the message of the Exception if it's not null.
| Name | Type | Description |
|---|---|---|
| $t | \Exception |

printTargets(
$project
)
:
voidPrint out a list of all targets in the current buildfile
| Name | Type | Description |
|---|---|---|
| $project |

restoreIni(
)
:
voidRestores [most] PHP INI values to their pre-Phing state.
Currently the following settings are not restored: - max_execution_time (because getting current time limit is not possible) - memory_limit (which may have been increased by Phing)

setCurrentProject(
\Project $p
)
:
voidSets the current Project
| Name | Type | Description |
|---|---|---|
| $p | \Project |

setDefinedProperty(
string $name, $value
)
:
stringThis sets a property that was set via command line or otherwise passed into Phing.
| Name | Type | Description |
|---|---|---|
| $name | string | |
| $value |
| Type | Description |
|---|---|
| string | value of found property (or null, if none found). |

setErrorStream(
\OutputStream $stream
)
:
voidSets the stream to use for error output.
| Name | Type | Description |
|---|---|---|
| $stream | \OutputStream | The stream to use for error output. |

setIncludePaths(
)
:
voidSets the include path to PHP_CLASSPATH constant (if this has been defined).
| Exception | Description |
|---|---|
| \ConfigurationException | - if the include_path could not be set (for some bizarre reason) |

setOutputStream(
\OutputStream $stream
)
:
voidSets the stream to use for standard (non-error) output.
| Name | Type | Description |
|---|---|---|
| $stream | \OutputStream | The stream to use for standard output. |

setProperty(
$propName, $propValue
)
:
void| Name | Type | Description |
|---|---|---|
| $propName | ||
| $propValue |

setSystemConstants(
)
:
voidSet System constants which can be retrieved by calling Phing::getProperty($propName).

start(
array $args, array $additionalUserProperties
=
null
)
:
voidEntry point allowing for more options from other front ends.
This method encapsulates the complete build lifecycle.
| Name | Type | Description |
|---|---|---|
| $args | array | The commandline args passed to phing shell script. |
| $additionalUserProperties | array | Any additional properties to be passed to Phing (alternative front-end might implement this). These additional properties will be available using the getDefinedProperty() method and will be added to the project's "user" properties |
| Exception | Description |
|---|---|
| \Exception | - if there is an error during build |
- See
- \execute()
- See
- \runBuild()

startPhpErrorCapture(
)
:
voidBegins capturing PHP errors to a buffer.
While errors are being captured, they are not logged.

startup(
)
:
voidStart up Phing.
Sets up the Phing environment but does not initiate the build process.
| Exception | Description |
|---|---|
| \Exception | - If the Phing environment cannot be initialized. |

stopPhpErrorCapture(
)
:
voidStops capturing PHP errors to a buffer.
The errors will once again be logged after calling this method.