/** * Gets the current internal encoding. * * @return string The encoding "name". * @throws EncodingDetectionException If the detection fails. */ public static function getInternalEncoding() { $encoding = iconv_get_encoding(static::ICONV_INTERNAL_ENCODING_FLAG); if (false === $encoding) { throw EncodingDetectionException::forCurrentSystem(); } return $encoding; }
/** * Resolves the input encoding of a given string. * * May attempt to detect the encoding, or may fall back to using the * internal encoding. * * @param string $string The input string to resolve encoding from. * @return string The encoding "name". * @throws EncodingDetectionException If the detection fails. */ private function resolveInputEncoding($string) { $encoding = null; if ($this->detect) { $encoding = mb_detect_encoding($string, null, true); } // Fall back to the internal encoding if (false === $encoding || null === $encoding) { $encoding = mb_internal_encoding(); } if (false === $encoding || null === $encoding) { throw EncodingDetectionException::forString($string); } return $encoding; }