MediaWiki master
ReplacementArray.php
Go to the documentation of this file.
1<?php
7namespace Wikimedia;
8
13 private array $data;
14
20 public function __construct( array $data = [] ) {
21 $this->data = $data;
22 }
23
27 public function __sleep() {
28 return [ 'data' ];
29 }
30
34 public function setArray( array $data ) {
35 $this->data = $data;
36 }
37
41 public function getArray() {
42 return $this->data;
43 }
44
50 public function setPair( $from, $to ) {
51 $this->data[$from] = $to;
52 }
53
57 public function mergeArray( $data ) {
58 $this->data = $data + $this->data;
59 }
60
61 public function merge( ReplacementArray $other ) {
62 $this->data = $other->data + $this->data;
63 }
64
68 public function removePair( $from ) {
69 unset( $this->data[$from] );
70 }
71
75 public function removeArray( $data ) {
76 foreach ( $data as $from => $to ) {
77 $this->removePair( $from );
78 }
79 }
80
85 public function replace( $subject ) {
86 return strtr( $subject, $this->data );
87 }
88}
89
91class_alias( ReplacementArray::class, 'ReplacementArray' );
93class_alias( ReplacementArray::class, 'MediaWiki\\Language\\ReplacementArray' );
Wrapper around strtr() that holds replacements.
setPair( $from, $to)
Set an element of the replacement array.
setArray(array $data)
Set the whole replacement array at once.
merge(ReplacementArray $other)
__construct(array $data=[])
Create an object with the specified replacement array The array should have the same form as the repl...