*/
/**
- * Replacement array for FSS with fallback to strtr()
- * Supports lazy initialisation of FSS resource
+ * Wrapper around strtr() that holds replacements
*/
class ReplacementArray {
- private $data = false;
- private $fss = false;
+ private $data = [];
/**
* Create an object with the specified replacement array
* The array should have the same form as the replacement array for strtr()
* @param array $data
*/
- public function __construct( $data = array() ) {
+ public function __construct( array $data = [] ) {
$this->data = $data;
}
* @return array
*/
public function __sleep() {
- return array( 'data' );
- }
-
- public function __wakeup() {
- $this->fss = false;
+ return [ 'data' ];
}
/**
* Set the whole replacement array at once
* @param array $data
*/
- public function setArray( $data ) {
+ public function setArray( array $data ) {
$this->data = $data;
- $this->fss = false;
}
/**
- * @return array|bool
+ * @return array
*/
public function getArray() {
return $this->data;
*/
public function setPair( $from, $to ) {
$this->data[$from] = $to;
- $this->fss = false;
}
/**
*/
public function mergeArray( $data ) {
$this->data = $data + $this->data;
- $this->fss = false;
}
/**
*/
public function merge( ReplacementArray $other ) {
$this->data = $other->data + $this->data;
- $this->fss = false;
}
/**
*/
public function removePair( $from ) {
unset( $this->data[$from] );
- $this->fss = false;
}
/**
foreach ( $data as $from => $to ) {
$this->removePair( $from );
}
- $this->fss = false;
}
/**
* @return string
*/
public function replace( $subject ) {
- if (
- function_exists( 'fss_prep_replace' ) &&
- version_compare( PHP_VERSION, '5.5.0' ) < 0
- ) {
- if ( $this->fss === false ) {
- $this->fss = fss_prep_replace( $this->data );
- }
- $result = fss_exec_replace( $this->fss, $subject );
- } else {
- $result = strtr( $subject, $this->data );
- }
-
- return $result;
+ return strtr( $subject, $this->data );
}
}