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:

Some other predicats will help you filtering the files:

Example 43-1. Filter examples


<?php
//Extract all the files that contain an 'a' in their path
// or filename from a tar archive
File_Archive::extract(
    File_Archive::filter(
        File_Archive::predEreg('a'),
        File_Archive::read(
            'archive.tar/',
            'folder'
        )
    ),
    File_Archive::toFiles()
);

//Compress a directory to a zip file, including only the files
//smaller than 1MB that have changed since last hour
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('directory')
    ),
    File_Archive::toArchive(
        'directory.zip',
        File_Archive::toFiles()
    )
);
?>