Phing中的数组属性

时间:2009-08-04 20:39:41

标签: php phing

我有一个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>

它调用一个extenal文件(filesToCheck.txt),它只是一个不同文件位置的列表。这很好用。但是当我想根据同一外部文件中的某个键(filesToCheck.txt)访问特定文件时,它阻止我在我的PHP代码中重用相同的列表。

我查看了Phing的文档,但没有找到任何数组任务。有没有人知道一个解决方法或正在创建一个新任务是处理Phing中数组属性的唯一解决方案?

2 个答案:

答案 0 :(得分:3)

我最终创建了一个临时任务,因为触摸任务不是检查文件权限的最有效方法。如果用户不是文件的所有者,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>

答案 1 :(得分:0)

您可能只是创建一个临时任务作为快速解决方案,或者您自己的任务是对它更加健壮。我已经习惯了Phing一段时间了,没有什么可以跳出来作为自己写作的替代品。