Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PregReplace.php
Go to the documentation of this file.
1 <?php
25 #require_once 'Zend/Filter/Interface.php';
26 
34 {
39  protected $_matchPattern = null;
40 
45  protected $_replacement = '';
46 
52  static protected $_unicodeSupportEnabled = null;
53 
59  static public function isUnicodeSupportEnabled()
60  {
61  if (self::$_unicodeSupportEnabled === null) {
63  }
64 
66  }
67 
73  static protected function _determineUnicodeSupport()
74  {
75  self::$_unicodeSupportEnabled = (@preg_match('/\pL/u', 'a')) ? true : false;
76  }
77 
87  public function __construct($options = null)
88  {
89  if ($options instanceof Zend_Config) {
90  $options = $options->toArray();
91  } else if (!is_array($options)) {
92  $options = func_get_args();
93  $temp = array();
94  if (!empty($options)) {
95  $temp['match'] = array_shift($options);
96  }
97 
98  if (!empty($options)) {
99  $temp['replace'] = array_shift($options);
100  }
101 
102  $options = $temp;
103  }
104 
105  if (array_key_exists('match', $options)) {
106  $this->setMatchPattern($options['match']);
107  }
108 
109  if (array_key_exists('replace', $options)) {
110  $this->setReplacement($options['replace']);
111  }
112  }
113 
120  public function setMatchPattern($match)
121  {
122  $this->_matchPattern = $match;
123  return $this;
124  }
125 
131  public function getMatchPattern()
132  {
133  return $this->_matchPattern;
134  }
135 
142  public function setReplacement($replacement)
143  {
144  $this->_replacement = $replacement;
145  return $this;
146  }
147 
153  public function getReplacement()
154  {
155  return $this->_replacement;
156  }
157 
164  public function filter($value)
165  {
166  if ($this->_matchPattern == null) {
167  #require_once 'Zend/Filter/Exception.php';
168  throw new Zend_Filter_Exception(get_class($this) . ' does not have a valid MatchPattern set.');
169  }
170 
171  return preg_replace($this->_matchPattern, $this->_replacement, $value);
172  }
173 
174 }
setReplacement($replacement)
__construct($options=null)
Definition: PregReplace.php:87
$replacement
Definition: website.php:23
$value
Definition: gender.phtml:16
static _determineUnicodeSupport()
Definition: PregReplace.php:73
static isUnicodeSupportEnabled()
Definition: PregReplace.php:59