Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
StringTrim.php
Go to the documentation of this file.
1 <?php
25 #require_once 'Zend/Filter/Interface.php';
26 
34 {
43  protected $_charList;
44 
51  public function __construct($options = null)
52  {
53  if ($options instanceof Zend_Config) {
54  $options = $options->toArray();
55  } else if (!is_array($options)) {
56  $options = func_get_args();
57  $temp['charlist'] = array_shift($options);
58  $options = $temp;
59  }
60 
61  if (array_key_exists('charlist', $options)) {
62  $this->setCharList($options['charlist']);
63  }
64  }
65 
71  public function getCharList()
72  {
73  return $this->_charList;
74  }
75 
82  public function setCharList($charList)
83  {
84  $this->_charList = $charList;
85  return $this;
86  }
87 
96  public function filter($value)
97  {
98  if (null === $this->_charList) {
99  return $this->_unicodeTrim((string) $value);
100  } else {
101  return $this->_unicodeTrim((string) $value, $this->_charList);
102  }
103  }
104 
113  protected function _unicodeTrim($value, $charlist = '\\\\s')
114  {
115  $chars = preg_replace(
116  array( '/[\^\-\]\\\]/S', '/\\\{4}/S', '/\//'),
117  array( '\\\\\\0', '\\', '\/' ),
118  $charlist
119  );
120 
121  $pattern = '^[' . $chars . ']*|[' . $chars . ']*$';
122  return preg_replace("/$pattern/sSD", '', $value);
123  }
124 }
setCharList($charList)
Definition: StringTrim.php:82
$pattern
Definition: website.php:22
$value
Definition: gender.phtml:16
__construct($options=null)
Definition: StringTrim.php:51
_unicodeTrim($value, $charlist='\\\\s')
Definition: StringTrim.php:113