我有一个 phing 构建文件,它使用
<target description="list of files to check permission" name="files-to-test">
<property name="filesToCheck" value=""/>
<php expression="file_get_contents('filesToCheck.txt')" returnProperty="filesToCheck"/>
<foreach list="${filesToCheck}" param="file" target="permission-test"/>
</target>
<target description="Test the permission of files that needs to be written" name="permission-test">
<touch file="${file}"/>
</target>
它调用一个外部文件(filesToCheck.txt),它只是不同文件位置的列表。这很好用。但当我想根据同一外部文件 (filesToCheck.txt) 中的某个键访问特定文件时,它会阻止我在 PHP 代码中重复使用相同的列表。
我翻阅了 Phing 的文档,但没有找到任何数组任务。有谁知道解决方法或者创建新任务是在 Phing 中处理数组属性的唯一解决方案?
最佳答案
我最终创建了一个临时任务,因为触摸任务不是检查文件权限的最有效方法。 PHP 的 touch如果用户不是文件的所有者,则该文件无法按预期工作。
这是我想出的临时任务:
<adhoc-task name="is-file-writeable">
<![CDATA[
class IsFileWriteableTest extends Task
{
private $file;
function setFile($file)
{
$filesArray = parse_ini_file('filesToCheck.ini');
$this->files = $filesArray;
}
function main()
{
foreach ($this->files as $fileName => $fileLocation)
{
if (!is_writable($fileLocation))
{
throw new Exception("No write permission for $fileLocation");
}
}
}
}
]]>
</adhoc-task>
<target description="list of files to check permission" name="files-to-test">
<is-file-writeable file="/path/to/filesToCheck.ini" />
</target>
关于php - Phing 中的数组属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1229814/