|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Base class for output stream; prints to stdout or buffer or wherever. |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright © 2003, 2005, 2006 Brion Vibber <[email protected]> |
|
6
|
|
|
* https://www.mediawiki.org/ |
|
7
|
|
|
* |
|
8
|
|
|
* This program is free software; you can redistribute it and/or modify |
|
9
|
|
|
* it under the terms of the GNU General Public License as published by |
|
10
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
|
11
|
|
|
* (at your option) any later version. |
|
12
|
|
|
* |
|
13
|
|
|
* This program is distributed in the hope that it will be useful, |
|
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16
|
|
|
* GNU General Public License for more details. |
|
17
|
|
|
* |
|
18
|
|
|
* You should have received a copy of the GNU General Public License along |
|
19
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc., |
|
20
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
21
|
|
|
* http://www.gnu.org/copyleft/gpl.html |
|
22
|
|
|
* |
|
23
|
|
|
* @file |
|
24
|
|
|
*/ |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @ingroup Dump |
|
28
|
|
|
*/ |
|
29
|
|
|
class DumpMultiWriter { |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param array $sinks |
|
33
|
|
|
*/ |
|
34
|
|
|
function __construct( $sinks ) { |
|
35
|
|
|
$this->sinks = $sinks; |
|
|
|
|
|
|
36
|
|
|
$this->count = count( $sinks ); |
|
|
|
|
|
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param string $string |
|
41
|
|
|
*/ |
|
42
|
|
|
function writeOpenStream( $string ) { |
|
43
|
|
|
for ( $i = 0; $i < $this->count; $i++ ) { |
|
44
|
|
|
$this->sinks[$i]->writeOpenStream( $string ); |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @param string $string |
|
50
|
|
|
*/ |
|
51
|
|
|
function writeCloseStream( $string ) { |
|
52
|
|
|
for ( $i = 0; $i < $this->count; $i++ ) { |
|
53
|
|
|
$this->sinks[$i]->writeCloseStream( $string ); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @param object $page |
|
59
|
|
|
* @param string $string |
|
60
|
|
|
*/ |
|
61
|
|
|
function writeOpenPage( $page, $string ) { |
|
62
|
|
|
for ( $i = 0; $i < $this->count; $i++ ) { |
|
63
|
|
|
$this->sinks[$i]->writeOpenPage( $page, $string ); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @param string $string |
|
69
|
|
|
*/ |
|
70
|
|
|
function writeClosePage( $string ) { |
|
71
|
|
|
for ( $i = 0; $i < $this->count; $i++ ) { |
|
72
|
|
|
$this->sinks[$i]->writeClosePage( $string ); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @param object $rev |
|
78
|
|
|
* @param string $string |
|
79
|
|
|
*/ |
|
80
|
|
|
function writeRevision( $rev, $string ) { |
|
81
|
|
|
for ( $i = 0; $i < $this->count; $i++ ) { |
|
82
|
|
|
$this->sinks[$i]->writeRevision( $rev, $string ); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @param array $newnames |
|
88
|
|
|
*/ |
|
89
|
|
|
function closeRenameAndReopen( $newnames ) { |
|
90
|
|
|
$this->closeAndRename( $newnames, true ); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @param array $newnames |
|
95
|
|
|
* @param bool $open |
|
96
|
|
|
*/ |
|
97
|
|
|
function closeAndRename( $newnames, $open = false ) { |
|
98
|
|
|
for ( $i = 0; $i < $this->count; $i++ ) { |
|
99
|
|
|
$this->sinks[$i]->closeAndRename( $newnames[$i], $open ); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @return array |
|
105
|
|
|
*/ |
|
106
|
|
|
function getFilenames() { |
|
107
|
|
|
$filenames = []; |
|
108
|
|
|
for ( $i = 0; $i < $this->count; $i++ ) { |
|
109
|
|
|
$filenames[] = $this->sinks[$i]->getFilenames(); |
|
110
|
|
|
} |
|
111
|
|
|
return $filenames; |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: