Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 12 |
|
0.00% |
0 / 10 |
CRAP | |
0.00% |
0 / 1 |
ReplacementArray | |
0.00% |
0 / 11 |
|
0.00% |
0 / 10 |
132 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
__sleep | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setArray | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getArray | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setPair | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
mergeArray | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
merge | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
removePair | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
removeArray | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
replace | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
16 | * http://www.gnu.org/copyleft/gpl.html |
17 | * |
18 | * @file |
19 | */ |
20 | |
21 | namespace MediaWiki\Language; |
22 | |
23 | /** |
24 | * Wrapper around strtr() that holds replacements |
25 | */ |
26 | class ReplacementArray { |
27 | private array $data; |
28 | |
29 | /** |
30 | * Create an object with the specified replacement array |
31 | * The array should have the same form as the replacement array for strtr() |
32 | * @param array $data |
33 | */ |
34 | public function __construct( array $data = [] ) { |
35 | $this->data = $data; |
36 | } |
37 | |
38 | /** |
39 | * @return array |
40 | */ |
41 | public function __sleep() { |
42 | return [ 'data' ]; |
43 | } |
44 | |
45 | /** |
46 | * Set the whole replacement array at once |
47 | * @param array $data |
48 | */ |
49 | public function setArray( array $data ) { |
50 | $this->data = $data; |
51 | } |
52 | |
53 | /** |
54 | * @return array |
55 | */ |
56 | public function getArray() { |
57 | return $this->data; |
58 | } |
59 | |
60 | /** |
61 | * Set an element of the replacement array |
62 | * @param string $from |
63 | * @param string $to |
64 | */ |
65 | public function setPair( $from, $to ) { |
66 | $this->data[$from] = $to; |
67 | } |
68 | |
69 | /** |
70 | * @param array $data |
71 | */ |
72 | public function mergeArray( $data ) { |
73 | $this->data = $data + $this->data; |
74 | } |
75 | |
76 | /** |
77 | * @param ReplacementArray $other |
78 | */ |
79 | public function merge( ReplacementArray $other ) { |
80 | $this->data = $other->data + $this->data; |
81 | } |
82 | |
83 | /** |
84 | * @param string $from |
85 | */ |
86 | public function removePair( $from ) { |
87 | unset( $this->data[$from] ); |
88 | } |
89 | |
90 | /** |
91 | * @param array $data |
92 | */ |
93 | public function removeArray( $data ) { |
94 | foreach ( $data as $from => $to ) { |
95 | $this->removePair( $from ); |
96 | } |
97 | } |
98 | |
99 | /** |
100 | * @param string $subject |
101 | * @return string |
102 | */ |
103 | public function replace( $subject ) { |
104 | return strtr( $subject, $this->data ); |
105 | } |
106 | } |
107 | |
108 | /** @deprecated class alias since 1.43 */ |
109 | class_alias( ReplacementArray::class, 'ReplacementArray' ); |