Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Filter / HtmlEntities.php
blob962fb389736866623208798adcb9ef842e9fca5f
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\Filter;
12 use Traversable;
13 use Zend\Stdlib\ArrayUtils;
15 class HtmlEntities extends AbstractFilter
17 /**
18 * Corresponds to the second htmlentities() argument
20 * @var int
22 protected $quoteStyle;
24 /**
25 * Corresponds to the third htmlentities() argument
27 * @var string
29 protected $encoding;
31 /**
32 * Corresponds to the forth htmlentities() argument
34 * @var bool
36 protected $doubleQuote;
38 /**
39 * Sets filter options
41 * @param array|Traversable $options
43 public function __construct($options = array())
45 if ($options instanceof Traversable) {
46 $options = ArrayUtils::iteratorToArray($options);
48 if (!is_array($options)) {
49 $options = func_get_args();
50 $temp['quotestyle'] = array_shift($options);
51 if (!empty($options)) {
52 $temp['charset'] = array_shift($options);
55 $options = $temp;
58 if (!isset($options['quotestyle'])) {
59 $options['quotestyle'] = ENT_QUOTES;
62 if (!isset($options['encoding'])) {
63 $options['encoding'] = 'UTF-8';
65 if (isset($options['charset'])) {
66 $options['encoding'] = $options['charset'];
69 if (!isset($options['doublequote'])) {
70 $options['doublequote'] = true;
73 $this->setQuoteStyle($options['quotestyle']);
74 $this->setEncoding($options['encoding']);
75 $this->setDoubleQuote($options['doublequote']);
78 /**
79 * Returns the quoteStyle option
81 * @return int
83 public function getQuoteStyle()
85 return $this->quoteStyle;
88 /**
89 * Sets the quoteStyle option
91 * @param int $quoteStyle
92 * @return self Provides a fluent interface
94 public function setQuoteStyle($quoteStyle)
96 $this->quoteStyle = $quoteStyle;
97 return $this;
102 * Get encoding
104 * @return string
106 public function getEncoding()
108 return $this->encoding;
112 * Set encoding
114 * @param string $value
115 * @return self
117 public function setEncoding($value)
119 $this->encoding = (string) $value;
120 return $this;
124 * Returns the charSet option
126 * Proxies to {@link getEncoding()}
128 * @return string
130 public function getCharSet()
132 return $this->getEncoding();
136 * Sets the charSet option
138 * Proxies to {@link setEncoding()}
140 * @param string $charSet
141 * @return self Provides a fluent interface
143 public function setCharSet($charSet)
145 return $this->setEncoding($charSet);
149 * Returns the doubleQuote option
151 * @return bool
153 public function getDoubleQuote()
155 return $this->doubleQuote;
159 * Sets the doubleQuote option
161 * @param bool $doubleQuote
162 * @return self Provides a fluent interface
164 public function setDoubleQuote($doubleQuote)
166 $this->doubleQuote = (bool) $doubleQuote;
167 return $this;
171 * Defined by Zend\Filter\FilterInterface
173 * Returns the string $value, converting characters to their corresponding HTML entity
174 * equivalents where they exist
176 * If the value provided is non-scalar, the value will remain unfiltered
177 * and an E_USER_WARNING will be raised indicating it's unfilterable.
179 * @param string $value
180 * @return string|mixed
181 * @throws Exception\DomainException on encoding mismatches
183 public function filter($value)
185 if (null === $value) {
186 return null;
189 if (!is_scalar($value)) {
190 trigger_error(
191 sprintf(
192 '%s expects parameter to be scalar, "%s" given; cannot filter',
193 __METHOD__,
194 (is_object($value) ? get_class($value) : gettype($value))
196 E_USER_WARNING
198 return $value;
201 $filtered = htmlentities((string) $value, $this->getQuoteStyle(), $this->getEncoding(), $this->getDoubleQuote());
202 if (strlen((string) $value) && !strlen($filtered)) {
203 if (!function_exists('iconv')) {
204 throw new Exception\DomainException('Encoding mismatch has resulted in htmlentities errors');
206 $enc = $this->getEncoding();
207 $value = iconv('', $this->getEncoding() . '//IGNORE', (string) $value);
208 $filtered = htmlentities($value, $this->getQuoteStyle(), $enc, $this->getDoubleQuote());
209 if (!strlen($filtered)) {
210 throw new Exception\DomainException('Encoding mismatch has resulted in htmlentities errors');
213 return $filtered;