Wyck
Wyck

Reputation: 2023

How to use PHP in a Phing build file correctly?

I am writing PHP directly inside a Phing build.xml file using adhoc-task.

The following does work but throws up console errors:

<adhoc-task name="foo"><![CDATA[

 define('WP_INSTALLING', true);

 require_once '${build.dir.wp}/wp-load.php';
 require_once '${build.dir.wp}/wp-admin/includes/upgrade.php';
 require_once '${build.dir.wp}/wp-includes/wp-db.php';

 $result = wp_install( 'title', 'admin', '[email protected]');

]]></adhoc-task>

The error: The adhoc class you defined must be an instance of phing.Task BUILD FAILED.The adhoc class you defined must be an instance of phing.Task

But it still works...

If I wrap the PHP in a class it doesn't work at all:

<adhoc-task name="foo"><![CDATA[

   class FooTest extends Task {
   //php code ....
   }
]]></adhoc-task>

The error: You must define at least one class for AdhocTaskdefTask.

What is the proper way to include PHP inside the build file (without having access to the php/phing/tasks folder)?

Upvotes: 2

Views: 1762

Answers (1)

cweiske
cweiske

Reputation: 31117

From test/etc/regression/299/build.xml:

<?xml version="1.0" encoding="utf-8"?>
<project name="test" default="main">

  <target name="main">
    <bar/>
  </target>

  <adhoc-task name="bar"><![CDATA[
      class BarTask extends Task {
          function main() {
              print("BarTask: success!\n");
          }
      }
  ]]></adhoc-task>

</project>

Upvotes: 2

Related Questions