1

Background

I started with this open ended question https://stackoverflow.com/questions/36602830/list-differences-between-two-directories-from-point-of-view-of-one-directory-by

Then tried this to solve it using phing's native utilities, but got stuck - How to return a value from a phing target?

Now I am trying to write a custom Phing task, as per https://www.phing.info/docs/guide/trunk/ch06s06.html. I tried echoing the list of files in this, with an intention to somehow collect the same in a property when the task is called from the build xml -

<addedfiles message="Hello World" outputProperty="output"/>

But I found that an outputProperty attribute is not supported in the call from the build xml file.

Any pointers on how to do this, or to the other two questions would help a lot.

Community
  • 1
  • 1
Sandeepan Nath
  • 9,966
  • 17
  • 86
  • 144
  • A note for those trying to use a custom phing task like a function (a reusable utility), the output variable's names need to be different across multiple calls to that phing property. I passed the name of the output variable as a parameter while calling the property, and used the same name to set the name of the output property. – Sandeepan Nath May 24 '16 at 07:43

2 Answers2

0

Oh it is simple. We can set a property within the custom task class like this -

$this->getProject()->setNewProperty('output', "hello world");

and it can be accessed in the build xml, after the task call, like this -

<addedfiles message="Hello World" />
<echo>See ${output}</echo>
Sandeepan Nath
  • 9,966
  • 17
  • 86
  • 144
0

You can improve your solution doing this

private $outputProperty;

public function setOutputProperty($str)
{
    $this->outputProperty = $str;
}

and then, when you catch the output

$this->getProject()->setNewProperty($this->outputProperty, "hello world");
corretge
  • 1,751
  • 11
  • 24