File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change 99
1010namespace Toolkit \Stdlib ;
1111
12+ use RuntimeException ;
1213use function defined ;
1314use function explode ;
1415use function function_exists ;
2526use function putenv ;
2627use function rtrim ;
2728use function stripos ;
29+ use function tempnam ;
30+ use function tmpfile ;
2831use const PHP_OS ;
2932use const PHP_OS_FAMILY ;
3033
@@ -205,6 +208,31 @@ public static function getWorkDir(): string
205208 return (string )getcwd ();
206209 }
207210
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+
208236 /**
209237 * @return string
210238 */
Original file line number Diff line number Diff line change 99 */
1010class Std
1111{
12-
1312}
You can’t perform that action at this time.
0 commit comments