File tree 3 files changed +52
-2
lines changed 3 files changed +52
-2
lines changed Original file line number Diff line number Diff line change @@ -95,6 +95,34 @@ public static function spl_object_id($object)
95
95
return self ::$ hashMask ^ hexdec (substr ($ hash , 16 - \PHP_INT_SIZE , \PHP_INT_SIZE ));
96
96
}
97
97
98
+ public static function sapi_windows_vt100_support ($ stream , $ enable = null )
99
+ {
100
+ // We cannot actually disable vt100 support if it is set
101
+ if (false === $ enable || !self ::stream_isatty ($ stream )) {
102
+ return false ;
103
+ }
104
+
105
+ // The native function does not apply to stdin
106
+ $ meta = array_map ('strtolower ' , stream_get_meta_data ($ stream ));
107
+ $ stdin = 'php://stdin ' === $ meta ['uri ' ] || 'php://fd/0 ' === $ meta ['uri ' ];
108
+
109
+ return !$ stdin
110
+ && (false !== getenv ('ANSICON ' )
111
+ || 'ON ' === getenv ('ConEmuANSI ' )
112
+ || 'xterm ' === getenv ('TERM ' ));
113
+ }
114
+
115
+ public static function stream_isatty ($ stream )
116
+ {
117
+ if ('\\' === DIRECTORY_SEPARATOR ) {
118
+ $ stat = @fstat ($ stream );
119
+ // Check if formatted mode is S_IFCHR
120
+ return $ stat ? 0020000 === ($ stat ['mode ' ] & 0170000 ) : false ;
121
+ }
122
+
123
+ return function_exists ('posix_isatty ' ) && @posix_isatty ($ stream );
124
+ }
125
+
98
126
private static function initHashMask ()
99
127
{
100
128
$ obj = (object ) array ();
Original file line number Diff line number Diff line change 13
13
14
14
if (PHP_VERSION_ID < 70200 ) {
15
15
if ('\\' === DIRECTORY_SEPARATOR && !function_exists ('sapi_windows_vt100_support ' )) {
16
- function sapi_windows_vt100_support () { return false ; }
16
+ function sapi_windows_vt100_support ($ stream , $ enable = null ) { return p \Php72:: sapi_windows_vt100_support ( $ stream , $ enable ) ; }
17
17
}
18
18
if (!function_exists ('stream_isatty ' )) {
19
- function stream_isatty ($ stream ) { return function_exists ( ' posix_isatty ' ) && @ posix_isatty ($ stream ); }
19
+ function stream_isatty ($ stream ) { return p \Php72:: stream_isatty ($ stream ); }
20
20
}
21
21
if (!function_exists ('utf8_encode ' )) {
22
22
function utf8_encode ($ s ) { return p \Php72::utf8_encode ($ s ); }
Original file line number Diff line number Diff line change @@ -64,4 +64,26 @@ public function testSplObjectId()
64
64
65
65
$ this ->assertNull (@spl_object_id (123 ));
66
66
}
67
+
68
+ /**
69
+ * @covers Symfony\Polyfill\Php72\Php72::sapi_windows_vt100_support
70
+ */
71
+ public function testSapiWindowsVt100Support ()
72
+ {
73
+ if ('\\' !== DIRECTORY_SEPA
8D8C
RATOR ) {
74
+ $ this ->markTestSkipped ('Windows only test ' );
75
+ }
76
+
77
+ $ this ->assertFalse (sapi_windows_vt100_support (STDIN , true ));
78
+ }
79
+
80
+ /**
81
+ * @covers Symfony\Polyfill\Php72\Php72::stream_isatty
82
+ */
83
+ public function testStreamIsatty ()
84
+ {
85
+ $ fp = fopen ('php://temp ' , 'r+ ' );
86
+ $ this ->assertFalse (stream_isatty ($ fp ));
87
+ fclose ($ fp );
88
+ }
67
89
}
You can’t perform that action at this time.
0 commit comments