Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
StringToLower.php
Go to the documentation of this file.
1 <?php
25 #require_once 'Zend/Filter/Interface.php';
26 
34 {
40  protected $_encoding = null;
41 
47  public function __construct($options = null)
48  {
49  if ($options instanceof Zend_Config) {
50  $options = $options->toArray();
51  } else if (!is_array($options)) {
52  $options = func_get_args();
53  $temp = array();
54  if (!empty($options)) {
55  $temp['encoding'] = array_shift($options);
56  }
57  $options = $temp;
58  }
59 
60  if (!array_key_exists('encoding', $options) && function_exists('mb_internal_encoding')) {
61  $options['encoding'] = mb_internal_encoding();
62  }
63 
64  if (array_key_exists('encoding', $options)) {
65  $this->setEncoding($options['encoding']);
66  }
67  }
68 
74  public function getEncoding()
75  {
76  return $this->_encoding;
77  }
78 
86  public function setEncoding($encoding = null)
87  {
88  if ($encoding !== null) {
89  if (!function_exists('mb_strtolower')) {
90  #require_once 'Zend/Filter/Exception.php';
91  throw new Zend_Filter_Exception('mbstring is required for this feature');
92  }
93 
94  $encoding = (string) $encoding;
95  if (!in_array(strtolower($encoding), array_map('strtolower', mb_list_encodings()))) {
96  #require_once 'Zend/Filter/Exception.php';
97  throw new Zend_Filter_Exception("The given encoding '$encoding' is not supported by mbstring");
98  }
99  }
100 
101  $this->_encoding = $encoding;
102  return $this;
103  }
104 
113  public function filter($value)
114  {
115  if ($this->_encoding !== null) {
116  return mb_strtolower((string) $value, $this->_encoding);
117  }
118 
119  return strtolower((string) $value);
120  }
121 }
__construct($options=null)
$value
Definition: gender.phtml:16
setEncoding($encoding=null)