File tree 2 files changed +28
-1
lines changed
2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change 9
9
10
10
namespace Toolkit \Stdlib ;
11
11
12
+ use RuntimeException ;
12
13
use function defined ;
13
14
use function explode ;
14
15
use function function_exists ;
25
26
use function putenv ;
26
27
use function rtrim ;
27
28
use function stripos ;
29
+ use function tempnam ;
30
+ use function tmpfile ;
28
31
use const PHP_OS ;
29
32
use const PHP_OS_FAMILY ;
30
33
@@ -205,6 +208,31 @@ public static function getWorkDir(): string
205
208
return (string )getcwd ();
206
209
}
207
210
211
+ /**
212
+ * Creates a temporary file
213
+ *
214
+ * @return resource
215
+ */
216
+ public static function newTempFile ()
217
+ {
218
+ $ fh = tmpfile ();
219
+ if ($ fh === false ) {
220
+ throw new RuntimeException ('create an temporary file fail ' );
221
+ }
222
+
223
+ return $ fh ;
224
+ }
225
+
226
+ /**
227
+ * @param string $prefix
228
+ *
229
+ * @return string
230
+ */
231
+ public static function tempFilePath (string $ prefix = 'tmp_ ' ): string
232
+ {
233
+ return tempnam (self ::getTempDir (), $ prefix );
234
+ }
235
+
208
236
/**
209
237
* @return string
210
238
*/
Original file line number Diff line number Diff line change 9
9
*/
10
10
class Std
11
11
{
12
-
13
12
}
You can’t perform that action at this time.
0 commit comments