Merge "StringUtils: Add a utility for checking if a string is a valid regex"
[lhc/web/wiklou.git] / includes / export / DumpMultiWriter.php
1 <?php
2 /**
3 * Base class for output stream; prints to stdout or buffer or wherever.
4 *
5 * Copyright © 2003, 2005, 2006 Brion Vibber <brion@pobox.com>
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 /** @var array */
31 private $sinks;
32 /** @var int */
33 private $count;
34
35 /**
36 * @param array $sinks
37 */
38 function __construct( $sinks ) {
39 $this->sinks = $sinks;
40 $this->count = count( $sinks );
41 }
42
43 /**
44 * @param string $string
45 */
46 function writeOpenStream( $string ) {
47 for ( $i = 0; $i < $this->count; $i++ ) {
48 $this->sinks[$i]->writeOpenStream( $string );
49 }
50 }
51
52 /**
53 * @param string $string
54 */
55 function writeCloseStream( $string ) {
56 for ( $i = 0; $i < $this->count; $i++ ) {
57 $this->sinks[$i]->writeCloseStream( $string );
58 }
59 }
60
61 /**
62 * @param object $page
63 * @param string $string
64 */
65 function writeOpenPage( $page, $string ) {
66 for ( $i = 0; $i < $this->count; $i++ ) {
67 $this->sinks[$i]->writeOpenPage( $page, $string );
68 }
69 }
70
71 /**
72 * @param string $string
73 */
74 function writeClosePage( $string ) {
75 for ( $i = 0; $i < $this->count; $i++ ) {
76 $this->sinks[$i]->writeClosePage( $string );
77 }
78 }
79
80 /**
81 * @param object $rev
82 * @param string $string
83 */
84 function writeRevision( $rev, $string ) {
85 for ( $i = 0; $i < $this->count; $i++ ) {
86 $this->sinks[$i]->writeRevision( $rev, $string );
87 }
88 }
89
90 /**
91 * @param array $newnames
92 */
93 function closeRenameAndReopen( $newnames ) {
94 $this->closeAndRename( $newnames, true );
95 }
96
97 /**
98 * @param array $newnames
99 * @param bool $open
100 */
101 function closeAndRename( $newnames, $open = false ) {
102 for ( $i = 0; $i < $this->count; $i++ ) {
103 $this->sinks[$i]->closeAndRename( $newnames[$i], $open );
104 }
105 }
106
107 /**
108 * @return array
109 */
110 function getFilenames() {
111 $filenames = [];
112 for ( $i = 0; $i < $this->count; $i++ ) {
113 $filenames[] = $this->sinks[$i]->getFilenames();
114 }
115 return $filenames;
116 }
117 }