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 andi@binarycloud.com

author

Hans Lellelid hans@xmpl.org

version

$Id: 4eac7c8602e16648a3f4ed2aac9b7b945221a336 $

package

phing

Methods

Import a PHP file

__import(string $path, mixed $classpath = null) 
static
throws
  • if cannot find the specified file

Arguments

$path

string

Path to the PHP file

$classpath

mixed

String or object supporting __toString()

Search parent directories for the build file.

_findBuildFile(string $start, string $suffix) : \PhingFile

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.

throws

Failed to locate a build file

Arguments

$start

string

Start file path.

$suffix

string

Suffix filename to look for in parents.

Response

\PhingFile

A handle to the build file

Helper to get the parent file for a given file.

_getParentFile(\PhingFile $file) : \PhingFile

Arguments

$file

\PhingFile

Response

\PhingFile

Parent file or null if none

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

_printTargets(array $names, array $descriptions, string $heading, integer $maxlen) 

Arguments

$names

array

The names to be printed.

         Must not be <code>null</code>.

$descriptions

array

The associated target descriptions.

                May be <code>null</code>, in which case
                no descriptions are displayed.
                If non-<code>null</code>, this should have
                as many elements as <code>names</code>.

$heading

string

The heading to display.

           Should not be <code>null</code>.

$maxlen

integer

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
          <i>are</i> shorter than this).

Bind any registered build listeners to this project.

addBuildListeners(\Project $project) : void

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

Arguments

$project

\Project

Creates the InputHandler and adds it to the project.

addInputHandler(\Project $project) 
throws

if a specified InputHandler

                      class could not be loaded.

Arguments

$project

\Project

the project instance.

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

clearCapturedPhpErrors() 
static

comparePhingVersion

comparePhingVersion( $version) 

Arguments

$version

Converts shorthand notation values as returned by ini_get()

convertShorthand(string $val) 
static
see http://www.php.net/ini_get

Arguments

$val

string

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

createLogger() : \BuildLogger

Response

\BuildLogger

The created Logger

currentTimeMillis

currentTimeMillis() 
static

Setup/initialize Phing environment from commandline args.

execute(array $args) : void

Arguments

$args

array

commandline args passed to phing shell.

Explode an include path into an array

explodeIncludePath(string|null $path = null) : array
static

If no path provided, uses current include_path. Works around issues that occur when the path includes stream schemas.

Pulled from Zend_Loader::explodeIncludePath() in ZF1.

copyright

Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)

license

http://framework.zend.com/license/new-bsd New BSD License

Arguments

$path

string|null

Response

array

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.

fire(array $args) : void
static

Arguments

$args

array

Command line args.

Gets any PHP errors that were captured to buffer.

getCapturedPhpErrors() : array
static

Response

array

array('message' => message, 'line' => line number, 'file' => file name, 'level' => error level)

Gets the current Project.

getCurrentProject() : \Project
static

Response

\Project

Current Project or NULL if none is set yet/still.

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

getDefinedProperty(string $name) : string
static

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

Arguments

$name

string

Response

string

value of found property (or null, if none found).

Gets the stream to use for error output.

getErrorStream() : \OutputStream
static

Response

\OutputStream

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.

getMsgOutputLevel() : integer
static

Response

integer

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

getOutputStream() : \OutputStream
static

Response

\OutputStream

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

getPhingVersion() : string
static
throws
  • if unable to find version file.

Response

string

Retuns reference to all properties

getProperties() 
static

Returns property value for a System property.

getProperty( $propName) : string
static

System properties are "global" properties like application.startdir, and user.dir. Many of these correspond to similar properties in Java or Ant.

Arguments

$propName

Response

string

Value of found property (or null, if none found).

Looks on include path for specified file.

getResourcePath( $path) : string
static

Arguments

$path

Response

string

File found (null if no file found).

Returns reference to Timer object.

getTimer() : \Timer
static

Response

\Timer

Halts the system.

halt() 
static
deprecated

This method is deprecated and is no longer called by Phing internally. Any

         normal shutdown routines are handled by the shutdown() method.
see \Phing::shutdown()

Close logfiles, if we have been writing to them.

handleLogfile() 
static
since

Phing 2.3.0

Error handler for PHP errors encountered during the build.

handlePhpError( $level,  $message,  $file,  $line) 
static

This uses the logging for the currently configured project.

Arguments

$level

$message

$file

$line

Import a path, supporting the following conventions: - PEAR style (@link http://pear.php.net/manual/en/standards.naming.php) - PSR-0 (@link https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md) - dot-path

import(string $dotPath, mixed $classpath = null) : string
static
throws
  • if cannot find the specified file

Arguments

$dotPath

string

Path

$classpath

mixed

String or object supporting __toString()

Response

string

The unqualified classname (which can be instantiated).

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

initializeOutputStreams() 
static

A static convenience method to send a log to the current (last-setup) Project.

log(string $message, integer $priority = \Project::MSG_INFO) 
static

If there is no currently-configured Project, then this will do nothing.

Arguments

$message

string

$priority

integer

Project::MSG_INFO, etc.

Print the project description, if any

printDescription(\Project $project) 
static

Arguments

$project

\Project

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

printMessage(\Exception $t) 
static

Arguments

$t

\Exception

Print out a list of all targets in the current buildfile

printTargets( $project) 

Arguments

$project

Prints the usage of how to use this class

printUsage() 
static

Prints the current Phing version.

printVersion() 
static

Restores [most] PHP INI values to their pre-Phing state.

restoreIni() : void
static

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)

Executes the build.

runBuild() : void

Sets the current Project

setCurrentProject(\Project $p) 
static

Arguments

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

setDefinedProperty(string $name,  $value) : string
static

Arguments

$name

string

$value

Response

string

value of found property (or null, if none found).

Sets the stream to use for error output.

setErrorStream(\OutputStream $stream) 
static

Arguments

$stream

\OutputStream

The stream to use for error output.

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

setIncludePaths() : void
static
throws
  • if the include_path could not be set (for some bizarre reason)

Sets PHP INI values that Phing needs.

setIni() : void
static

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

setOutputStream(\OutputStream $stream) 
static

Arguments

$stream

\OutputStream

The stream to use for standard output.

setProperty

setProperty( $propName,  $propValue) 
static

Arguments

$propName

$propValue

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

setSystemConstants() : void
static

Performs any shutdown routines, such as stopping timers.

shutdown() : void
static

Entry point allowing for more options from other front ends.

start(array $args, array $additionalUserProperties = null) 
static

This method encapsulates the complete build lifecycle.

see \Phing::execute() \Phing::runBuild()
throws
  • if there is an error during build

Arguments

$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

Begins capturing PHP errors to a buffer.

startPhpErrorCapture() 
static

While errors are being captured, they are not logged.

Start up Phing.

startup() : void
static

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

throws
  • If the Phing environment cannot be initialized.

Stops capturing PHP errors to a buffer.

stopPhpErrorCapture() 
static

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

Unsets the current Project

unsetCurrentProject() 
static

Constants

Alias for phar file

PHAR_ALIAS

The default build file name

DEFAULT_BUILD_FILENAME

Properties

Our current message output status. Follows Project::MSG_XXX

msgOutputLevel : 
static

Type(s)

PhingFile that we are using for configuration

buildFile : 

Type(s)

The build targets

targets : 

Type(s)

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

definedProps : \Properties
static
var

Type(s)

\Properties

Names of classes to add as listeners to project

listeners : 

Type(s)

loggerClassname

loggerClassname : 

Type(s)

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

inputHandlerClassname : 

Type(s)

Indicates if this phing should be run

readyToRun : 

Type(s)

Indicates we should only parse and display the project help information

projectHelp : 

Type(s)

Used by utility function getResourcePath()

importPaths : 
static

Type(s)

System-wide static properties (moved from System)

properties : 
static

Type(s)

Static system timer.

timer : 
static

Type(s)

The current Project

currentProject : 
static

Type(s)

Whether to capture PHP errors to buffer.

phpErrorCapture : 
static

Type(s)

Array of captured PHP errors

capturedPhpErrors : 
static

Type(s)

Stream for standard output.

out : \OUtputStream
static
var

Stream for standard output.

Type(s)

\OUtputStream

Stream for error output.

err : \OutputStream
static
var

Stream for error output.

Type(s)

\OutputStream

Whether we are using a logfile.

isLogFileUsed : boolean
static
var

Whether we are using a logfile.

Type(s)

boolean

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

origIniSettings : array
static
var

Struct of array(setting-name => setting-value)

see

Type(s)

array