tags:

views:

136

answers:

2

I have a phing build file that checks the permission of certain files using the <touch> task.

<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>

It calls an extenal file(filesToCheck.txt) which is just a list of different file locations. This works fine. But it prevents me from reusing the same list in my PHP code when I want to access a particular file based on a certain key from the same external file(filesToCheck.txt).

I looked through Phing's documentation but didn't find any array Task. Does anyone know of a work around or is creating a new task the only solution for handling an array property in Phing ?

A: 

You could probably just create an ad-hoc task as a quick-n-dirty solution, or your own task to be a bit more robust about it. I've used Phing for a while myself and nothing jumps out at me as an alternative to writing it yourself.

Ian Selby
A: 

I ended up creating an ad-hoc task because the touch task wasn't the most efficient way of checking for file permissions. PHP's touch doesn't work as expected for files if the user is not the owner of the file.

This is the ad-hoc task I came up with:

           <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>
Jahangir