data = $data; } /** * @return array */ public function __sleep() { return [ 'data' ]; } /** * Set the whole replacement array at once * @param array $data */ public function setArray( array $data ) { $this->data = $data; } /** * @return array */ public function getArray() { return $this->data; } /** * Set an element of the replacement array * @param string $from * @param string $to */ public function setPair( $from, $to ) { $this->data[$from] = $to; } /** * @param array $data */ public function mergeArray( $data ) { $this->data = $data + $this->data; } /** * @param ReplacementArray $other */ public function merge( ReplacementArray $other ) { $this->data = $other->data + $this->data; } /** * @param string $from */ public function removePair( $from ) { unset( $this->data[$from] ); } /** * @param array $data */ public function removeArray( $data ) { foreach ( $data as $from => $to ) { $this->removePair( $from ); } } /** * @param string $subject * @return string */ public function replace( $subject ) { return strtr( $subject, $this->data ); } }