Predicates

Predicates – Filters

Introduction

File_Archive introduces the concept of filters to be able to select the files from a source. A filter is a particular reader that you can create with the File_Archive::filter() function. This function requires you to give a predicate. You can build this predicate using the File_Archive::pred* functions.

The standard logic predicates are:

  • predTrue(): toujours évalue à vrai

  • predFalse(): toujours évalue à faux

  • predAnd($p1, $p2, ...): evaluates to $p1 && $p2 && ...

  • predOr($p1, $p2, ...): evaluates to $p1 || $p2 || ...

  • predNot($p): evaluates to !$p

Some other predicats will help you filtering the files:

  • predMinSize($size): prendre uniquement les fichiers dont la taille >= $size (en bytes).

  • predMinTime($time): prendre uniquement les fichiers qui on été modifié après $time (unix timestamp).

  • predMaxDepth($depth): prendre uniquement les fichiers have a public name with less than $depth directories.

  • predExtension($list): keep only the files with a given extension. $list is an array or a comma separated string of allowed extensions.

  • predEreg($ereg): prendre uniquement les fichiers have a public name that matches the given regular expression.

  • predEregi($ereg): same as predEreg(), but the test is case insensitive.

  • predMIME($mimes): Select files with a certain MIME type. You can pass an array of types or a string, and use wildcards.

Exemples de filtres

<?php
// extraire d'un archive tart
// tous les fichiers qui contiennent un 'a'
// dans leur path ou nom de fichier
File_Archive::extract(
    
File_Archive::filter(
        
File_Archive::predEreg('a'),
        
File_Archive::read(
            
'l_archive_a_lire.tar/',
            
'folder'
        
)
    ),
    
File_Archive::toFiles()
);

//Compresser un répertoire en fichier zip,
//en incluant seulement les fichiers
//plus petit qu'un MB et changé dans l'heure qui précède
File_Archive::extract(
    
File_Archive::filter(
        
File_Archive::predAnd(
            
File_Archive::predNot(
                
File_Archive::predMinSize(1024 1024)
            ),
            
File_Archive::predMinTime(time()-3600)
        ),
        
File_Archive::read('mon_repertoire')
    ),
    
File_Archive::toArchive(
        
'archive_de_mon_repertoire.zip',
        
File_Archive::toFiles()
    )
);
?>
Sauvegarder une archive (Previous) Supprimer et ajouter des fichiers (Next)
Last updated: Sun, 29 Aug 2010 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report or add a note.
View this page in:

User Notes:

There are no user contributed notes for this page.