22 private static $hashMask;
29 for ($i = $len >> 1, $j = 0; $i < $len; ++$i, ++$j) {
31 case $s[$i] <
"\x80": $s[$j] = $s[$i];
break;
32 case $s[$i] <
"\xC0": $s[$j] =
"\xC2"; $s[++$j] = $s[$i];
break;
33 default: $s[$j] =
"\xC3"; $s[++$j] = \chr(\ord($s[$i]) - 64);
break;
37 return substr($s, 0, $j);
45 for ($i = 0, $j = 0; $i < $len; ++$i, ++$j) {
46 switch ($s[$i] &
"\xF0") {
49 $c = (\ord($s[$i] &
"\x1F") << 6) | \ord($s[++$i] &
"\x3F");
50 $s[$j] = $c < 256 ? \chr($c) :
'?';
67 return substr($s, 0, $j);
72 if (
'\\' === \DIRECTORY_SEPARATOR) {
86 return isset($map[PHP_OS]) ? $map[PHP_OS] :
'Unknown';
91 if (
null === self::$hashMask) {
94 if (
null === $hash = spl_object_hash($object)) {
99 return self::$hashMask ^ hexdec(substr($hash, 16 - (\PHP_INT_SIZE * 2 - 1), (\PHP_INT_SIZE * 2 - 1)));
104 if (!\is_resource($stream)) {
105 trigger_error(
'sapi_windows_vt100_support() expects parameter 1 to be resource, '.\gettype($stream).
' given', E_USER_WARNING);
110 $meta = stream_get_meta_data($stream);
112 if (
'STDIO' !== $meta[
'stream_type']) {
113 trigger_error(
'sapi_windows_vt100_support() was not able to analyze the specified stream', E_USER_WARNING);
119 if (
false === $enable || !self::stream_isatty($stream)) {
124 $meta = array_map(
'strtolower', $meta);
125 $stdin =
'php://stdin' === $meta[
'uri'] ||
'php://fd/0' === $meta[
'uri'];
128 && (
false !== getenv(
'ANSICON')
129 ||
'ON' === getenv(
'ConEmuANSI')
130 ||
'xterm' === getenv(
'TERM')
131 ||
'Hyper' === getenv(
'TERM_PROGRAM'));
136 if (!\is_resource($stream)) {
137 trigger_error(
'stream_isatty() expects parameter 1 to be resource, '.\gettype($stream).
' given', E_USER_WARNING);
142 if (
'\\' === \DIRECTORY_SEPARATOR) {
143 $stat = @fstat($stream);
145 return $stat ? 0020000 === ($stat[
'mode'] & 0170000) :
false;
148 return \function_exists(
'posix_isatty') && @posix_isatty($stream);
151 private static function initHashMask()
153 $obj = (object) array();
154 self::$hashMask = -1;
157 $obFuncs = array(
'ob_clean',
'ob_end_clean',
'ob_flush',
'ob_end_flush',
'ob_get_contents',
'ob_get_flush');
158 foreach (debug_backtrace(\PHP_VERSION_ID >= 50400 ? DEBUG_BACKTRACE_IGNORE_ARGS :
false) as $frame) {
159 if (isset($frame[
'function'][0]) && !isset($frame[
'class']) &&
'o' === $frame[
'function'][0] && \in_array($frame[
'function'], $obFuncs)) {
164 if (!empty($frame[
'line'])) {
166 debug_zval_dump($obj);
167 self::$hashMask = (int) substr(ob_get_clean(), 17);
170 self::$hashMask ^= hexdec(substr(spl_object_hash($obj), 16 - (\PHP_INT_SIZE * 2 - 1), (\PHP_INT_SIZE * 2 - 1)));
173 public static function mb_chr($code, $encoding =
null)
175 if (0x80 > $code %= 0x200000) {
177 } elseif (0x800 > $code) {
178 $s = \chr(0xC0 | $code >> 6).\chr(0x80 | $code & 0x3F);
179 } elseif (0x10000 > $code) {
180 $s = \chr(0xE0 | $code >> 12).\chr(0x80 | $code >> 6 & 0x3F).\chr(0x80 | $code & 0x3F);
182 $s = \chr(0xF0 | $code >> 18).\chr(0x80 | $code >> 12 & 0x3F).\chr(0x80 | $code >> 6 & 0x3F).\chr(0x80 | $code & 0x3F);
185 if (
'UTF-8' !== $encoding) {
186 $s = mb_convert_encoding($s, $encoding,
'UTF-8');
192 public static function mb_ord($s, $encoding =
null)
194 if (
null == $encoding) {
195 $s = mb_convert_encoding($s,
'UTF-8');
196 } elseif (
'UTF-8' !== $encoding) {
197 $s = mb_convert_encoding($s,
'UTF-8', $encoding);
200 if (1 === \strlen($s)) {
204 $code = ($s = unpack(
'C*', substr($s, 0, 4))) ? $s[1] : 0;
206 return (($code - 0xF0) << 18) + (($s[2] - 0x80) << 12) + (($s[3] - 0x80) << 6) + $s[4] - 0x80;
209 return (($code - 0xE0) << 12) + (($s[2] - 0x80) << 6) + $s[3] - 0x80;
212 return (($code - 0xC0) << 6) + $s[2] - 0x80;