Home > PHP > Built In Properties In Phing

Built In Properties In Phing

January 9th, 2009 Leave a comment Go to comments

Aside from assigning and using your own properties Phing also comes with a set of built in properties that can be used to find out all sorts of information regarding the system that Phing is run on.

As an example, lets say you wanted to found out the operating system that phing is being run on. In this case you would use the variable host.os, which on a Windows XP system would print out WINNT.

There are a lot of different properties available, so I have included the table from the phing website at the bottom of this post as a reference. However, there is one special variable called env that needs further explanation. The env variable references any environment variables that have been set. For example, if you set an environment variable using the following shell command (on UNIX based systems only).

export TESTVAR=mytestvar

You can now reference this in your build.xml file by using the following.

${env.TESTVAR}

Here is a table of the built in properties available.

Property Contents
application.startdir Current work directory
env.* Environment variables, extracted from $_SERVER.
host.arch System architecture, i.e. i586. Not available on Windows machines.
host.domain DNS domain name, i.e. php.net. Not available on Windows machines.
host.fstype The type of the filesystem. Possible values are UNIX, WINNT and WIN32
host.name Operating System hostname as returned by posix_uname(). Not available on Windows machines.
host.os Operating System description as set in PHP_OS variable (see PHP Manual).
host.os.release Operating version release, i.e. 2.2.10. Not available on Windows machines.
host.os.version Operating system version, i.e. #4 Tue Jul 20 17:01:36 MEST 1999. Not available on Windows machines.
line.separator Character(s) that signal the end of a line, "\n" for Linux, "\r\n" for Windows system, "\r" for Macintosh.
os.name Operating System description as set in PHP_OS variable.
phing.file Full path to current buildfile.
phing.home Phing installation directory, not set in PEAR installations.
phing.version Current Phing version.
phing.project.name Name of the currently processed project.
php.classpath The value of the environment variable PHP_CLASSPATH.
php.version Version of the PHP interpreter. Same as PHP constant PHP_VERSION (see PHP Manual).
project.basedir The current project basedir.
user.home Value of the environment variable HOME.

This list can also be found on the Phing website.

I have found that even though some of variables specifically say "not available on Windows" most of them will produce some sort of output, even on Windows machines. Here is a test build.xml file that you can use to see what the different variables print out on your system.

<?xml version="1.0"?>
<!-- build xml -->
<project name="myProject" default="main">
 
 <target name="main">
  <echo>application.startdir ${application.startdir}</echo>
  <echo>host.arch ${host.arch}</echo>
  <echo>host.domain ${host.domain}</echo>
  <echo>host.fstype ${host.fstype}</echo>
  <echo>host.name ${host.name}</echo>
  <echo>host.os ${host.os}</echo>
  <echo>host.os.release ${host.os.release}</echo>
  <echo>host.os.version ${host.os.version}</echo>
  <echo>line.separator ${line.separator}</echo>
  <echo>os.name ${os.name}</echo>
  <echo>phing.file ${phing.file}</echo>
  <echo>phing.home ${phing.home}</echo>
  <echo>phing.version ${phing.version}</echo>
  <echo>phing.project.name ${phing.project.name}</echo>
  <echo>php.classpath${php.classpath}</echo>
  <echo>php.version ${php.version}</echo>
  <echo>project.basedir ${project.basedir}</echo>
  <echo>user.home ${user.home}</echo>
 </target>
</project>

This file misses out the env property as this is a custom property.

Information, services, and products:
Franking Machines europeanpostalsystems.co.uk
Click here for Rome Xpat Rentals
www.altalift.co.uk
click here for a selection of Wool Rugs
visit http://www.urang.co.uk/ for Builder London
Categories: PHP Tags: , , , ,
  1. No comments yet.
  1. No trackbacks yet.