2. Phing for power users
About me
Stephan Hochdörfer
Head of IT at bitExpert AG, Germany
enjoying PHP since 1999
S.Hochdoerfer@bitExpert.de
@shochdoerfer
22. Enforce Internal Targets
Phing for power users
User can call both targets from command line.
We do not want that.
<?xml version="1.0"?>
<project name="myproject" default="hello">
<target name="init"
description="Property initialization">
<property name="Hello" value="Hello, world!" />
</target>
<target name="hello"
depends="init">
<echo msg="${Hello}" />
</target>
</project>
23. <?xml version="1.0"?>
<project name="myproject" default="hello">
<target name="-init"
description="Property initialization">
<property name="Hello" value="Hello, world!" />
</target>
<target name="hello"
depends="-init">
<echo msg="${Hello}" />
</target>
</project>
Enforce Internal Targets
Phing for power users
Prefixing a targets with a „-“ prevents the target
from being called from the command line.
24. $> ./vendor/bin/phing -l
Buildfile: /home/shochdoerfer/myproject/build.xml
Default target:
---------------------------------------------------------
hello
Main targets:
---------------------------------------------------------
-init Property initialization
Subtargets:
---------------------------------------------------------
hello
Enforce Internal Targets
Phing for power users
32. <?php
require_once 'phing/Task.php';
class MyTask extends Task {
protected $file;
/**
* @param string $file
*/
public function setFile($file) {
$this->file = $file;
}
/**
* @see Task::main()
*/
public function main() {
// Custom code here...
}
}
Custom Task with Parameters
Phing for power users
33. <?xml version="1.0"?>
<project name="myproject" default="hello">
<target name="init">
<taskdef
name="mytask"
classpath="${project.basedir}"
classname="MyApp.Common.Phing.MyTask" />
</target>
<target name="hello"
depends="init">
<mytask file="myfile.txt" />
</target>
</project>
Custom Task with Parameters
Phing for power users
34. <?xml version="1.0"?>
<project name="myproject" default="app:run">
<!--
The following target namespaces exist:
db:* - Database specific targets
app:* - Application specific tasks
ci:* - CI server specific tasks
-->
<import file="build/build.db.xml" />
<import file="build/build.app.xml" />
<import file="build/build.ci.xml" />
</project>
Imports for Targets can help structuring
Phing for power users