2

我有一个 phing 构建文件,它使用 <touch> 任务检查某些文件的权限。

<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 中处理数组属性的唯一解决方案?

4

2 回答 2

3

我最终创建了一个临时任务,因为触摸任务不是检查文件权限的最有效方式。如果用户不是文件的所有者, PHP 的触摸对文件不会按预期工作。

这是我提出的临时任务:

           <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>
于 2009-08-05T19:14:30.310 回答
0

您可能只是创建一个临时任务作为快速-n-dirty 解决方案,或者您自己的任务使其更加健壮。我自己使用 Phing 已经有一段时间了,除了自己编写之外,没有什么能让我跳出来的。

于 2009-08-04T21:26:42.683 回答