File tree Expand file tree Collapse file tree 1 file changed +17
-5
lines changed
Expand file tree Collapse file tree 1 file changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -10,13 +10,25 @@ class Utils {
1010 * @return bool
1111 */
1212 public static function has_stdin () {
13- $ handle = fopen ( 'php://stdin ' , 'r ' );
14- $ read = array ( $ handle );
15- $ write = null ;
16- $ except = null ;
13+ $ handle = fopen ( 'php://stdin ' , 'r ' );
14+ $ read = array ( $ handle );
15+ $ write = null ;
16+ $ except = null ;
1717 $ streams = stream_select ( $ read , $ write , $ except , 0 );
18+ $ fstat = fstat ( $ handle );
19+
1820 fclose ( $ handle );
1921
20- return 1 === $ streams ;
22+ if ( $ streams !== 1 ) {
23+ // No stream on STDIN.
24+ return false ;
25+ }
26+
27+ if ( isset ( $ fstat ['size ' ] ) && $ fstat ['size ' ] === 0 ) {
28+ // A stream on STDIN was detected but has a size of 0 bytes.
29+ return false ;
30+ }
31+
32+ return true ;
2133 }
2234}
You can’t perform that action at this time.
0 commit comments