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
49 public function setArray( array $data ) {
50 $this->data = $data;
51 }
52
56 public function getArray() {
57 return $this->data;
58 }
59
65 public function setPair( $from, $to ) {
66 $this->data[$from] = $to;
67 }
68
72 public function mergeArray( $data ) {
73 $this->data = $data + $this->data;
74 }
75
79 public function merge( ReplacementArray $other ) {
80 $this->data = $other->data + $this->data;
81 }
82
86 public function removePair( $from ) {
87 unset( $this->data[$from] );
88 }
89
93 public function removeArray( $data ) {
94 foreach ( $data as $from => $to ) {
95 $this->removePair( $from );
96 }
97 }
98
103 public function replace( $subject ) {
104 return strtr( $subject, $this->data );
105 }
106}
107
109class_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.