php - Phing 中的数组属性

标签 php phing

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

相关文章:

php - 如何在 web 服务器下的 Windows 平台上通过 PHP 进行 gpg 加密?

php - 在 MATCH 之后添加 2 行时,全文查询将不起作用

php - 是否有可用于 phing 的 ssh 和 scp 任务?

eclipse-pdt - Eclipse PDT 和 Phing

php - Propel 1.6、Phing、Windows 7 - 如何设置?

php - MySQL 查询合并两个表以获得单个结果

PHP代码没有被执行,但是代码显示在浏览器源代码中

php - Docker : Could not find any MySQL database drivers.(需要 MySQLi 或 PDO。)

php - 如何正确部署您的 PHP 应用程序?

Phing - 导入的构建文件不执行