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 | */ |
48 | public function setArray( array $data ) { |
49 | $this->data = $data; |
50 | } |
51 | |
52 | /** |
53 | * @return array |
54 | */ |
55 | public function getArray() { |
56 | return $this->data; |
57 | } |
58 | |
59 | /** |
60 | * Set an element of the replacement array |
61 | * @param string $from |
62 | * @param string $to |
63 | */ |
64 | public function setPair( $from, $to ) { |
65 | $this->data[$from] = $to; |
66 | } |
67 | |
68 | /** |
69 | * @param array $data |
70 | */ |
71 | public function mergeArray( $data ) { |
72 | $this->data = $data + $this->data; |
73 | } |
74 | |
75 | public function merge( ReplacementArray $other ) { |
76 | $this->data = $other->data + $this->data; |
77 | } |
78 | |
79 | /** |
80 | * @param string $from |
81 | */ |
82 | public function removePair( $from ) { |
83 | unset( $this->data[$from] ); |
84 | } |
85 | |
86 | /** |
87 | * @param array $data |
88 | */ |
89 | public function removeArray( $data ) { |
90 | foreach ( $data as $from => $to ) { |
91 | $this->removePair( $from ); |
92 | } |
93 | } |
94 | |
95 | /** |
96 | * @param string $subject |
97 | * @return string |
98 | */ |
99 | public function replace( $subject ) { |
100 | return strtr( $subject, $this->data ); |
101 | } |
102 | } |
103 | |
104 | /** @deprecated class alias since 1.43 */ |
105 | class_alias( ReplacementArray::class, 'ReplacementArray' ); |