Get current working directory in PHP with Phing

The ResolvePathTask in Phing “turns a relative path into an absolute path, with respect to specified directory or the project basedir (if no dir attribute specified)”.

We can use this to dynamically get a base path for relative path components:

<property name="URI.base" value="./"/>
<resolvepath propertyName="URI.base" file="${URI.base}"/>

With this, we compose absolute paths:

<property name="URI.utilities" value="${URI.base}/utilities"/>

Example:

<project name="sandbox" default="main">
 <target name="sandbox_init" description="Init build and set properties">
  <property name="URI.base" value="./"/>
  <resolvepath propertyName="URI.base" file="${URI.base}"/>
  <echo>Resolved [absolute] path: ${URI.base}</echo>
  <!-- Directories -->
  <property name="URI.utilities" value="${URI.base}/utilities"/>
  <echo>Utilities path: ${URI.utilities}</echo>
  <!--File names -->
  <property name="URI.autoload.outfile" value="${URI.utilities}/autoload.inc.php"/>
  <property name="URI.autoload.templatefile" value="${URI.utilities}/autoload.template.tpl"/>
 </target>
 <target name="main" depends="sandbox_init" description="Main build task"/>
</project>

The above code sample prints:
Buildfile: /var/www/sandbox/build.xml
sandbox > sandbox_init:
[echo] Resolved [absolute] path: /var/www/sandbox
[echo] Utilities path: /var/www/sandbox/utilities