Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
HtmlEntities.php
Go to the documentation of this file.
1 <?php
25 #require_once 'Zend/Filter/Interface.php';
26 
34 {
40  protected $_quoteStyle;
41 
47  protected $_encoding;
48 
54  protected $_doubleQuote;
55 
63  public function __construct($options = array())
64  {
65  if ($options instanceof Zend_Config) {
66  $options = $options->toArray();
67  } else if (!is_array($options)) {
68  $options = func_get_args();
69  $temp['quotestyle'] = array_shift($options);
70  if (!empty($options)) {
71  $temp['charset'] = array_shift($options);
72  }
73 
74  $options = $temp;
75  }
76 
77  if (!isset($options['quotestyle'])) {
78  $options['quotestyle'] = ENT_COMPAT;
79  }
80 
81  if (!isset($options['encoding'])) {
82  $options['encoding'] = 'UTF-8';
83  }
84  if (isset($options['charset'])) {
85  $options['encoding'] = $options['charset'];
86  }
87 
88  if (!isset($options['doublequote'])) {
89  $options['doublequote'] = true;
90  }
91 
92  $this->setQuoteStyle($options['quotestyle']);
93  $this->setEncoding($options['encoding']);
94  $this->setDoubleQuote($options['doublequote']);
95  }
96 
102  public function getQuoteStyle()
103  {
104  return $this->_quoteStyle;
105  }
106 
113  public function setQuoteStyle($quoteStyle)
114  {
115  $this->_quoteStyle = $quoteStyle;
116  return $this;
117  }
118 
119 
125  public function getEncoding()
126  {
127  return $this->_encoding;
128  }
129 
136  public function setEncoding($value)
137  {
138  $this->_encoding = (string) $value;
139  return $this;
140  }
141 
149  public function getCharSet()
150  {
151  return $this->getEncoding();
152  }
153 
162  public function setCharSet($charSet)
163  {
164  return $this->setEncoding($charSet);
165  }
166 
172  public function getDoubleQuote()
173  {
174  return $this->_doubleQuote;
175  }
176 
183  public function setDoubleQuote($doubleQuote)
184  {
185  $this->_doubleQuote = (boolean) $doubleQuote;
186  return $this;
187  }
188 
198  public function filter($value)
199  {
200  $filtered = htmlentities((string) $value, $this->getQuoteStyle(), $this->getEncoding(), $this->getDoubleQuote());
201  if (strlen((string) $value) && !strlen($filtered)) {
202  if (!function_exists('iconv')) {
203  #require_once 'Zend/Filter/Exception.php';
204  throw new Zend_Filter_Exception('Encoding mismatch has resulted in htmlentities errors');
205  }
206  $enc = $this->getEncoding();
207  $value = iconv('', $enc . '//IGNORE', (string) $value);
208  $filtered = htmlentities($value, $this->getQuoteStyle(), $enc, $this->getDoubleQuote());
209  if (!strlen($filtered)) {
210  #require_once 'Zend/Filter/Exception.php';
211  throw new Zend_Filter_Exception('Encoding mismatch has resulted in htmlentities errors');
212  }
213  }
214  return $filtered;
215  }
216 }
$value
Definition: gender.phtml:16
__construct($options=array())
setDoubleQuote($doubleQuote)