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
10 namespace Zend\Filter
;
12 abstract class AbstractUnicode
extends AbstractFilter
15 * Set the input encoding for the given string
17 * @param string|null $encoding
19 * @throws Exception\InvalidArgumentException
20 * @throws Exception\ExtensionNotLoadedException
22 public function setEncoding($encoding = null)
24 if ($encoding !== null) {
25 if (!function_exists('mb_strtolower')) {
26 throw new Exception\
ExtensionNotLoadedException(sprintf(
27 '%s requires mbstring extension to be loaded',
32 $encoding = strtolower($encoding);
33 $mbEncodings = array_map('strtolower', mb_list_encodings());
34 if (!in_array($encoding, $mbEncodings)) {
35 throw new Exception\
InvalidArgumentException(sprintf(
36 "Encoding '%s' is not supported by mbstring extension",
42 $this->options
['encoding'] = $encoding;
47 * Returns the set encoding
51 public function getEncoding()
53 if ($this->options
['encoding'] === null && function_exists('mb_internal_encoding')) {
54 $this->options
['encoding'] = mb_internal_encoding();
57 return $this->options
['encoding'];