@@ -101,10 +101,12 @@ public static function resolveStdinPath($filepath = null)
101
101
102
102
// If a filepath is provided, use it for better config resolution
103
103
if ($ filepath ) {
104
- // Create temp file with same name in temp directory
105
104
$ tempDir = sys_get_temp_dir ();
106
105
$ fileName = basename ($ filepath );
107
- static ::$ stdinTempFile = $ tempDir .DIRECTORY_SEPARATOR .$ fileName ;
106
+ $ uniqueSuffix = '_ ' .uniqid ().'_ ' .getmypid ();
107
+ $ pathInfo = pathinfo ($ fileName );
108
+ $ uniqueFileName = $ pathInfo ['filename ' ].$ uniqueSuffix .(isset ($ pathInfo ['extension ' ]) ? '. ' .$ pathInfo ['extension ' ] : '' );
109
+ static ::$ stdinTempFile = $ tempDir .DIRECTORY_SEPARATOR .$ uniqueFileName ;
108
110
109
111
if (file_put_contents (static ::$ stdinTempFile , $ content ) === false ) {
110
112
abort (1 , "Failed to create temporary file for stdin content: {$ filepath }" );
@@ -132,6 +134,11 @@ public static function resolveStdinPath($filepath = null)
132
134
protected static function isStdinAvailable ()
133
135
{
134
136
$ stdin = fopen ('php://stdin ' , 'r ' );
137
+
138
+ if ($ stdin === false ) {
139
+ return false ;
140
+ }
141
+
135
142
$ status = stream_get_meta_data ($ stdin );
136
143
fclose ($ stdin );
137
144
@@ -145,7 +152,13 @@ protected static function isStdinAvailable()
145
152
*/
146
153
protected static function readStdinContent ()
147
154
{
148
- return stream_get_contents (STDIN );
155
+ $ content = stream_get_contents (STDIN );
156
+
157
+ if ($ content === false ) {
158
+ abort (1 , 'Failed to read content from stdin. ' );
159
+ }
160
+
161
+ return $ content ;
149
162
}
150
163
151
164
/**
0 commit comments