1<?php
2/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
3
4/**
5 * A reader that appears exactly as another does
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: Relay.php,v 1.19 2005/07/09 12:54:35 vincentlascaux Exp $
29 * @link       http://pear.php.net/package/File_Archive
30 */
31
32require_once "File/Archive/Reader.php";
33
34/**
35 * This reader appear exactly as $source does
36 * This is usefull if you want to dynamically change $source or change
37 * its behaviour
38 */
39class File_Archive_Reader_Relay extends File_Archive_Reader
40{
41    /**
42     * @var    File_Archive_Reader This reader will have the same comportment as
43     *         $source
44     * @access protected
45     */
46    var $source;
47
48    function File_Archive_Reader_Relay(&$source)
49    {
50        $this->source =& $source;
51    }
52
53    /**
54     * @see File_Archive_Reader::next()
55     */
56    function next() { return $this->source->next(); }
57    /**
58     * @see File_Archive_Reader::getFilename()
59     */
60    function getFilename() { return $this->source->getFilename(); }
61    /**
62     * @see File_Archive_Reader::getStat()
63     */
64    function getStat() { return $this->source->getStat(); }
65    /**
66     * @see File_Archive_Reader::getMime()
67     */
68    function getMime() { return $this->source->getMime(); }
69    /**
70     * @see File_Archive_Reader::getDataFilename()
71     */
72    function getDataFilename() { return $this->source->getDataFilename(); }
73    /**
74     * @see File_Archive_Reader::getData()
75     */
76    function getData($length = -1) { return $this->source->getData($length); }
77    /**
78     * @see File_Archive_Reader::skip()
79     */
80    function skip($length = -1) { return $this->source->skip($length); }
81    /**
82     * @see File_Archive_Reader::rewind()
83     */
84    function rewind($length = -1) { return $this->source->rewind($length); }
85    /**
86     * @see File_Archive_Reader::tell()
87     */
88    function tell() { return $this->source->tell(); }
89
90    /**
91     * @see File_Archive_Reader::close()
92     */
93    function close()
94    {
95        if ($this->source !== null) {
96            return $this->source->close();
97        }
98    }
99    /**
100     * @see File_Archive_Reader::makeAppendWriter()
101     */
102    function makeAppendWriter()
103    {
104        $writer = $this->source->makeAppendWriter();
105        if (!PEAR::isError($writer)) {
106            $this->close();
107        }
108        return $writer;
109    }
110    /**
111     * @see File_Archive_Reader::makeWriterRemoveFiles()
112     */
113    function makeWriterRemoveFiles($pred)
114    {
115        $writer = $this->source->makeWriterRemoveFiles($pred);
116        if (!PEAR::isError($writer)) {
117            $this->close();
118        }
119        return $writer;
120    }
121    /**
122     * @see File_Archive_Reader::makeWriterRemoveBlocks()
123     */
124    function makeWriterRemoveBlocks($blocks, $seek = 0)
125    {
126        $writer = $this->source->makeWriterRemoveBlocks($blocks, $seek);
127        if (!PEAR::isError($writer)) {
128            $this->close();
129        }
130        return $writer;
131    }
132}
133
134?>