使用phing/phingcall内部调用目标时返回值 [英] Return value when internally calling target with phing/phingcall
问题描述
我正在通过phingcall命令调用目标. 我想从被调用目标中传回状态变量,或者至少从调用目标中更改现有值. 目标:如果子目标失败(我用属性指示),我想分支到我的主要目标控制逻辑中. 下面的代码不起作用.知道如何实现它或实现我的目标的替代方法吗?
I am calling a target by means of phingcall command. I want to pass back a status variable from the called target or at least change the existing value from the calling target. Goal: I want to branch in my main target controlling logic if the sub target fails which I indicate with a property. The code below does not work. Any idea how to make it work or an altertive approach for my goal?
谢谢, 于尔根
<target name="main">
<echo>target a</echo>
<echo>${bOk}</echo>
<exec command="echo 1" outputProperty="bOk" />
<echo>bOk is 1: ${bOk}</echo>
<phingcall inheritRefs="true" target="sub">
</phingcall>
<echo>bOk should now be 0: ${bOk}</echo>
</target>
<target name="sub">
<echo>target b</echo>
<echo>bOk is 1: ${bOk}</echo>
<exec command="echo 0" outputProperty="bOk" />
<echo>bOk now is 0: ${bOk}</echo>
</target>
这里的问题是
<echo>bOk should now be 0: ${bOk}</echo>
echos
bOk should now be 0: 1
推荐答案
即使在#phing IRC的强大帮助下,我也无法解决问题. 我决定编写一个自定义任务来说明目标之间的数据传递:
Even with the great help of #phing IRC I couldn't solve the problem. I decided to write a custom task to account for data passing between targets:
<?php
require_once "phing/Task.php";
class rvGlobalTask extends Task {
private static $bOk = 1;
private $sMode = null;
private $bValue = null;
private $outputProperty = null;
public function setSMode( $sMode ) {
$this->sMode = $sMode;
}
public function setBValue( $bValue ) {
$this->bValue = $bValue;
}
public function setOutputProperty( $outputProperty ) {
$this->outputProperty = $outputProperty;
}
public function main() {
if ( $this->sMode == "set" ) {
rvGlobalTask::$bOk = $this->bValue;
} else {
$this->project->setProperty(
$this->outputProperty,
rvGlobalTask::$bOk
);
}
}
}
?>
这对我的问题很好.也许其他人也觉得这很有用.
This works fine for my problem. Perhaps someone else finds this useful as well.
这篇关于使用phing/phingcall内部调用目标时返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!