| 1 |
lars |
1 |
<?php
|
|
|
2 |
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
|
|
3 |
|
|
|
4 |
/**
|
|
|
5 |
* Regroups several readers to make them appear as a single one
|
|
|
6 |
*
|
|
|
7 |
* PHP versions 4 and 5
|
|
|
8 |
*
|
|
|
9 |
* This library is free software; you can redistribute it and/or
|
|
|
10 |
* modify it under the terms of the GNU Lesser General Public
|
|
|
11 |
* License as published by the Free Software Foundation; either
|
|
|
12 |
* version 2.1 of the License, or (at your option) any later version.
|
|
|
13 |
*
|
|
|
14 |
* This library is distributed in the hope that it will be useful,
|
|
|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
17 |
* Lesser General Public License for more details.
|
|
|
18 |
*
|
|
|
19 |
* You should have received a copy of the GNU Lesser General Public
|
|
|
20 |
* License along with this library; if not, write to the Free Software
|
|
|
21 |
* Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA
|
|
|
22 |
*
|
|
|
23 |
* @category File Formats
|
|
|
24 |
* @package File_Archive
|
|
|
25 |
* @author Vincent Lascaux <vincentlascaux@php.net>
|
|
|
26 |
* @copyright 1997-2005 The PHP Group
|
|
|
27 |
* @license http://www.gnu.org/copyleft/lesser.html LGPL
|
|
|
28 |
* @version CVS: $Id: Multi.php,v 1.10 2005/05/26 21:30:18 vincentlascaux Exp $
|
|
|
29 |
* @link http://pear.php.net/package/File_Archive
|
|
|
30 |
*/
|
|
|
31 |
|
|
|
32 |
require_once "File/Archive/Reader/Relay.php";
|
|
|
33 |
|
|
|
34 |
/**
|
|
|
35 |
* Regroups several readers to make them appear as a single one
|
|
|
36 |
*/
|
|
|
37 |
class File_Archive_Reader_Multi extends File_Archive_Reader_Relay
|
|
|
38 |
{
|
|
|
39 |
/**
|
|
|
40 |
* @var Array All the sources regrouped in this reader
|
|
|
41 |
* @access private
|
|
|
42 |
*/
|
|
|
43 |
var $sources = array();
|
|
|
44 |
/**
|
|
|
45 |
* @var Int Index of the source being read currently
|
|
|
46 |
* @access private
|
|
|
47 |
*/
|
|
|
48 |
var $currentIndex = 0;
|
|
|
49 |
|
|
|
50 |
function File_Archive_Reader_Multi()
|
|
|
51 |
{
|
|
|
52 |
parent::File_Archive_Reader_Relay($tmp = null);
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
/**
|
|
|
56 |
* Add a new reader to the list of readers
|
|
|
57 |
* @param File_Archive_Reader $source The source to add
|
|
|
58 |
*/
|
|
|
59 |
function addSource(&$source)
|
|
|
60 |
{
|
|
|
61 |
$this->sources[] =& $source;
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
/**
|
|
|
65 |
* @see File_Archive_Reader::next()
|
|
|
66 |
*/
|
|
|
67 |
function next()
|
|
|
68 |
{
|
|
|
69 |
while (array_key_exists($this->currentIndex, $this->sources)) {
|
|
|
70 |
$this->source =& $this->sources[$this->currentIndex];
|
|
|
71 |
|
|
|
72 |
if (($error = $this->source->next()) === false) {
|
|
|
73 |
$error = $this->source->close();
|
|
|
74 |
if (PEAR::isError($error)) {
|
|
|
75 |
return $error;
|
|
|
76 |
}
|
|
|
77 |
$this->currentIndex++;
|
|
|
78 |
} else {
|
|
|
79 |
return $error;
|
|
|
80 |
}
|
|
|
81 |
}
|
|
|
82 |
return false;
|
|
|
83 |
}
|
|
|
84 |
/**
|
|
|
85 |
* @see File_Archive_Reader::close()
|
|
|
86 |
*/
|
|
|
87 |
function close()
|
|
|
88 |
{
|
|
|
89 |
$error = parent::close();
|
|
|
90 |
$this->currentIndex = 0;
|
|
|
91 |
return $error;
|
|
|
92 |
}
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
?>
|