Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
3
 
4
/**
5
 * Base class for all the transformation writers that will generate one single
6
 * file
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: Archive.php,v 1.14 2008/06/05 21:30:47 cbrunet Exp $
30
 * @link       http://pear.php.net/package/File_Archive
31
 */
32
 
33
require_once "File/Archive/Writer.php";
34
 
35
/**
36
 * Base class for all the transformation writers that will generate one single
37
 * file
38
 */
39
class File_Archive_Writer_Archive extends File_Archive_Writer
40
{
41
    /**
42
     * @var File_Archive_Writer The compressed data will be written to this
43
     * writer
44
     * @access protected
45
     */
46
    var $innerWriter;
47
 
48
    /**
49
     * @var bool If true, the innerWriter will be closed when closing this
50
     * @access private
51
     */
52
    var $autoClose;
53
 
54
    /**
55
     * @var Array List of empty folders that will be added when closing the archive
56
     */
57
    var $emptyFolders = array();
58
 
59
    /**
60
     * @param String $filename Name to give to the archive (the name will
61
     *        be used by the inner writer)
62
     *        If $filename is null, the innerWriter is considered already
63
     *        opened (and thus newFile will not be called)
64
     * @param File_Archive_Writer $innerWriter The inner writer to which the
65
     *        compressed data will be written
66
     * @param array $stat The stat of the archive (see the PHP stat() function).
67
     *        No element are required in this array
68
     * @param bool $autoClose Indicate if the inner writer must be closed when
69
     *        closing this
70
     */
71
    function File_Archive_Writer_Archive($filename, &$innerWriter,
72
                                         $stat = array(), $autoClose = true)
73
    {
74
        $this->innerWriter =& $innerWriter;
75
        $this->autoClose = $autoClose;
76
        if ($filename !== null) {
77
            $this->innerWriter->newFile($filename, $stat, $this->getMime());
78
        }
79
    }
80
 
81
    function newFile($filename, $stat = array(),
82
                     $mime = 'application/octet-stream')
83
    {
84
        if (substr($filename, -1) == '/') {
85
            $this->emptyFolders[$filename] = array($stat, $mime);
86
        } else {
87
            // Remove the folders that may no longer be empty
88
            $current = '';
89
            foreach (explode('/', $filename) as $folder) {
90
                $current .= $folder.'/';
91
                unset($this->emptyFolders[$current]);
92
            }
93
            $err = $this->_newFile($filename, $stat, $mime);
94
            if (PEAR::isError($err)) {
95
                return $err;
96
            }
97
        }
98
    }
99
//MUST REWRITE FUNCTIONS
100
    function _newFile($filename, $stat, $mime) {}
101
 
102
    /**
103
     * @return the MIME extension of the files generated by this writer
104
     */
105
    function getMime() { return "application/octet-stream"; }
106
 
107
    /**
108
     * @see File_Archive_Writer::close()
109
     */
110
    function close()
111
    {
112
        foreach ($this->emptyFolders as $folder => $info) {
113
            $err = $this->_newFile($folder, $info[0], $info[1]);
114
            if (PEAR::isError($err)) {
115
                return $err;
116
            }
117
        }
118
 
119
        if ($this->autoClose) {
120
            return $this->innerWriter->close();
121
        }
122
    }
123
//  function writeData($data)
124
 
125
//SHOULD REWRITE FUNCTIONS
126
//  function writeFile($filename)
127
}
128
 
129
?>