Phing.php

Show: inherited
Table of Contents

\Phing

Package: 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

Constant  DEFAULT_BUILD_FILENAME = "build.xml"

The default build file name

Properties

Propertyprivate  $buildFile= 'null'

PhingFile that we are using for configuration

Default valuenullDetails
Type
n/a
Propertyprivate  $capturedPhpErrors= 'array()'
static

Array of captured PHP errors

Default valuearray()Details
Type
n/a
Propertyprivate  $currentProject= ''
static

The current Project

Details
Type
n/a
Propertyprivate\Properties  $definedProps= ''
static

Set of properties that are passed in from commandline or invoking code.

Details
Type
\Properties
Propertyprivate\OutputStream  $err= ''
static

Stream for error output.
Details
Type
\OutputStream
Propertyprivate  $importPaths= ''
static

Used by utility function getResourcePath()

Details
Type
n/a
Propertyprivate  $inputHandlerClassname= ''

The class to handle input (can be only one).

Details
Type
n/a
Propertyprivateboolean  $isLogFileUsed= 'false'
static

Whether we are using a logfile.
Default valuefalseDetails
Type
boolean
Propertyprivate  $listeners= 'array()'

Names of classes to add as listeners to project

Default valuearray()Details
Type
n/a
Propertyprivate  $loggerClassname= 'null'
Default valuenullDetails
Type
n/a
Propertyprivate  $msgOutputLevel= 'Project::MSG_INFO'
static

Our current message output status. Follows Project::MSG_XXX

Default valueProject::MSG_INFODetails
Type
n/a
Propertyprivatearray  $origIniSettings= 'array()'
static

Array to hold original ini settings that Phing changes (and needs to restore in restoreIni() method).

Struct of array(setting-name => setting-value)
Default valuearray()Details
Type
array
See
\restoreIni()  
Propertyprivate\OUtputStream  $out= ''
static

Stream for standard output.
Details
Type
\OUtputStream
Propertyprivate  $phpErrorCapture= 'false'
static

Whether to capture PHP errors to buffer.

Default valuefalseDetails
Type
n/a
Propertyprivate  $projectHelp= 'false'

Indicates we should only parse and display the project help information

Default valuefalseDetails
Type
n/a
Propertyprivate  $properties= 'array()'
static

System-wide static properties (moved from System)

Default valuearray()Details
Type
n/a
Propertyprivate  $readyToRun= 'false'

Indicates if this phing should be run

Default valuefalseDetails
Type
n/a
Propertyprivate  $targets= 'array()'

The build targets

Default valuearray()Details
Type
n/a
Propertyprivate  $timer= ''
static

Static system timer.

Details
Type
n/a

Methods

methodpublic__import( string $path, mixed $classpath = null ) : void
static

Import a PHP file

Parameters
Name Type Description
$path string

Path to the PHP file

$classpath mixed

String or object supporting __toString()

Throws
Exception Description
\BuildException - if cannot find the specified file
methodprivate_findBuildFile( string $start, string $suffix ) : \PhingFile

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

Parameters
Name Type Description
$start string

Start file path.

$suffix string

Suffix filename to look for in parents.

Returns
Type Description
\PhingFile A handle to the build file
Throws
Exception Description
\BuildException Failed to locate a build file
methodprivate_getParentFile( \PhingFile $file ) : \PhingFile

Helper to get the parent file for a given file.

Parameters
Name Type Description
$file \PhingFile
Returns
Type Description
\PhingFile Parent file or null if none
methodprivate_printTargets( array $names, array $descriptions, string $heading, int $maxlen ) : void

Writes a formatted list of target names with an optional description.

Parameters
Name Type Description
$names array

The names to be printed. Must not be null.

$descriptions array

The associated target descriptions. May be null, in which case no descriptions are displayed. If non-null, this should have as many elements as names.

$heading string

The heading to display. Should not be null.

$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).

methodprivateaddBuildListeners( \Project $project ) : void

Bind any registered build listeners to this project.

This means adding the logger and any build listeners that were specified with -listener arg.

Parameters
Name Type Description
$project \Project
methodprivateaddInputHandler( \Project $project ) : void

Creates the InputHandler and adds it to the project.

Parameters
Name Type Description
$project \Project

the project instance.

Throws
Exception Description
\BuildException if a specified InputHandler class could not be loaded.
methodpublicclearCapturedPhpErrors( ) : void
static

Clears the captured errors without affecting the starting/stopping of the capture.

methodprivatecomparePhingVersion(  $version ) : void

Parameters
Name Type Description
$version
methodprivateconvertShorthand( string $val ) : void
static

Converts shorthand notation values as returned by ini_get()

Parameters
Name Type Description
$val string
Details
See
\http://www.php.net/ini_get  
methodprivatecreateLogger( ) : \BuildLogger

Creates the default build logger for sending build events to the log.

Returns
Type Description
\BuildLogger The created Logger
methodpubliccurrentTimeMillis( ) : void
static

methodpublicexecute( array $args ) : void

Setup/initialize Phing environment from commandline args.

Parameters
Name Type Description
$args array

commandline args passed to phing shell.

methodpublicfire( array $args ) : void
static

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

Parameters
Name Type Description
$args array

Command line args.

methodpublicgetCapturedPhpErrors( ) : array
static

Gets any PHP errors that were captured to buffer.

Returns
Type Description
array array('message' => message, 'line' => line number, 'file' => file name, 'level' => error level)
methodpublicgetCurrentProject( ) : \Project
static

Gets the current Project.

Returns
Type Description
\Project Current Project or NULL if none is set yet/still.
methodpublicgetDefinedProperty( string $name ) : string
static

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

Parameters
Name Type Description
$name string
Returns
Type Description
string value of found property (or null, if none found).
methodpublicgetErrorStream( ) : \OutputStream
static

Gets the stream to use for error output.

Returns
Type Description
\OutputStream
methodpublicgetMsgOutputLevel( ) : int
static

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

Returns
Type Description
int
methodpublicgetOutputStream( ) : \OutputStream
static

Gets the stream to use for standard (non-error) output.

Returns
Type Description
\OutputStream
methodpublicgetPhingVersion( ) : string
static

Gets the current Phing version based on VERSION.TXT file.

Returns
Type Description
string
Throws
Exception Description
\BuildException - if unable to find version file.
methodpublicgetProperties( ) : void
static

Retuns reference to all properties

methodpublicgetProperty(  $propName ) : string
static

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

Parameters
Name Type Description
$propName
Returns
Type Description
string Value of found property (or null, if none found).
methodpublicgetResourcePath(  $path ) : string
static

Looks on include path for specified file.

Parameters
Name Type Description
$path
Returns
Type Description
string File found (null if no file found).
methodpublicgetTimer( ) : \Timer
static

Returns reference to Timer object.

Returns
Type Description
\Timer
methodpublichalt( ) : void
static

Halts the system.

Details
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()  
methodprivatehandleLogfile( ) : void
static

Close logfiles, if we have been writing to them.

Details
Since
Phing 2.3.0  
methodpublichandlePhpError(  $level,  $message,  $file,  $line ) : void
static

Error handler for PHP errors encountered during the build.

This uses the logging for the currently configured project.

Parameters
Name Type Description
$level
$message
$file
$line
methodpublicimport( string $dotPath, mixed $classpath = null ) : string
static

Import a dot-path notation class path.

Parameters
Name Type Description
$dotPath string
$classpath mixed

String or object supporting __toString()

Returns
Type Description
string The unqualified classname (which can be instantiated).
Throws
Exception Description
\BuildException - if cannot find the specified file
methodprivateinitializeOutputStreams( ) : void
static

Sets the stdout and stderr streams if they are not already set.

methodpubliclog( string $message, int $priority = Project::MSG_INFO ) : void
static

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

Parameters
Name Type Description
$message string
$priority int

Project::MSG_INFO, etc.

methodpublicprintDescription(  $project ) : void
static

Print the project description, if any

Parameters
Name Type Description
$project
methodpublicprintMessage( \Exception $t ) : void
static

Prints the message of the Exception if it's not null.

Parameters
Name Type Description
$t \Exception
methodpublicprintTargets(  $project ) : void

Print out a list of all targets in the current buildfile

Parameters
Name Type Description
$project
methodpublicprintUsage( ) : void
static

Prints the usage of how to use this class

methodpublicprintVersion( ) : void
static

Prints the current Phing version.

methodprivaterestoreIni( ) : void
static

Restores [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)

methodpublicrunBuild( ) : void

Executes the build.

methodpublicsetCurrentProject( \Project $p ) : void
static

Sets the current Project

Parameters
Name Type Description
$p \Project
methodpublicsetDefinedProperty( string $name,  $value ) : string
static

This sets a property that was set via command line or otherwise passed into Phing.

Parameters
Name Type Description
$name string
$value
Returns
Type Description
string value of found property (or null, if none found).
methodpublicsetErrorStream( \OutputStream $stream ) : void
static

Sets the stream to use for error output.

Parameters
Name Type Description
$stream \OutputStream

The stream to use for error output.

methodprivatesetIncludePaths( ) : void
static

Sets the include path to PHP_CLASSPATH constant (if this has been defined).

Throws
Exception Description
\ConfigurationException - if the include_path could not be set (for some bizarre reason)
methodprivatesetIni( ) : void
static

Sets PHP INI values that Phing needs.

methodpublicsetOutputStream( \OutputStream $stream ) : void
static

Sets the stream to use for standard (non-error) output.

Parameters
Name Type Description
$stream \OutputStream

The stream to use for standard output.

methodpublicsetProperty(  $propName,  $propValue ) : void
static

Parameters
Name Type Description
$propName
$propValue
methodprivatesetSystemConstants( ) : void
static

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

methodpublicshutdown( ) : void
static

Performs any shutdown routines, such as stopping timers.

methodpublicstart( array $args, array $additionalUserProperties = null ) : void
static

Entry point allowing for more options from other front ends.

This method encapsulates the complete build lifecycle.

Parameters
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

Throws
Exception Description
\Exception - if there is an error during build
Details
See
\execute()  
See
\runBuild()  
methodpublicstartPhpErrorCapture( ) : void
static

Begins capturing PHP errors to a buffer.

While errors are being captured, they are not logged.

methodpublicstartup( ) : void
static

Start up Phing.

Sets up the Phing environment but does not initiate the build process.

Throws
Exception Description
\Exception - If the Phing environment cannot be initialized.
methodpublicstopPhpErrorCapture( ) : void
static

Stops capturing PHP errors to a buffer.

The errors will once again be logged after calling this method.

methodpublicunsetCurrentProject( ) : void
static

Unsets the current Project

Documentation was generated by DocBlox 0.18.1.