1<?php
2/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
3
4/**
5 * Evaluates to true iif all predicates given as constructor parameters evaluate
6 * to true
7 *
8 * PHP versions 4 and 5
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA
23 *
24 * @category   File Formats
25 * @package    File_Archive
26 * @author     Vincent Lascaux <vincentlascaux@php.net>
27 * @copyright  1997-2005 The PHP Group
28 * @license    http://www.gnu.org/copyleft/lesser.html  LGPL
29 * @version    CVS: $Id: And.php,v 1.8 2005/04/21 10:01:46 vincentlascaux Exp $
30 * @link       http://pear.php.net/package/File_Archive
31 */
32
33require_once "File/Archive/Predicate.php";
34
35/**
36 * Evaluates to true iif all predicates given as constructor parameters evaluate
37 * to true
38 *
39 * Example:
40 *  new File_Archive_Predicate_And($pred1, $pred2, $pred3)
41 *
42 * @see File_Archive_Predicate, File_Archive_Reader_Filter
43 */
44class File_Archive_Predicate_And extends File_Archive_Predicate
45{
46    /**
47     * @var Array List of File_Archive_Predicate objects given as an argument
48     * @access private
49     */
50    var $preds;
51
52    /**
53     * Build the predicate using the optional File_Archive_Predicates given as
54     * arguments
55     *
56     * Example:
57     *   new File_Archive_Predicate_And($pred1, $pred2, $pred3)
58     */
59    function File_Archive_Predicate_And()
60    {
61        $this->preds = func_get_args();
62    }
63
64    /**
65     * Add a new predicate to the list
66     *
67     * @param File_Archive_Predicate The predicate to add
68     */
69    function addPredicate($pred)
70    {
71        $this->preds[] = $pred;
72    }
73    /**
74     * @see File_Archive_Predicate::isTrue()
75     */
76    function isTrue(&$source)
77    {
78        foreach ($this->preds as $p) {
79            if (!$p->isTrue($source)) {
80                return false;
81            }
82        }
83        return true;
84    }
85}
86
87?>