MediaWiki master
ReplacementArray.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Language;
22
27 private array $data;
28
34 public function __construct( array $data = [] ) {
35 $this->data = $data;
36 }
37
41 public function __sleep() {
42 return [ 'data' ];
43 }
44
48 public function setArray( array $data ) {
49 $this->data = $data;
50 }
51
55 public function getArray() {
56 return $this->data;
57 }
58
64 public function setPair( $from, $to ) {
65 $this->data[$from] = $to;
66 }
67
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
82 public function removePair( $from ) {
83 unset( $this->data[$from] );
84 }
85
89 public function removeArray( $data ) {
90 foreach ( $data as $from => $to ) {
91 $this->removePair( $from );
92 }
93 }
94
99 public function replace( $subject ) {
100 return strtr( $subject, $this->data );
101 }
102}
103
105class_alias( ReplacementArray::class, 'ReplacementArray' );
Wrapper around strtr() that holds replacements.
__construct(array $data=[])
Create an object with the specified replacement array The array should have the same form as the repl...
setPair( $from, $to)
Set an element of the replacement array.
setArray(array $data)
Set the whole replacement array at once.