add ExecCmd and Tempdir
[pharext/pharext] / src / pharext / Tempdir.php
diff --git a/src/pharext/Tempdir.php b/src/pharext/Tempdir.php
new file mode 100644 (file)
index 0000000..585033a
--- /dev/null
@@ -0,0 +1,18 @@
+<?php
+
+namespace pharext;
+
+class Tempdir extends \SplFileInfo
+{
+       private $dir;
+       
+       public function __construct($prefix) {
+               $temp = sprintf("%s/%s.%s", sys_get_temp_dir(), $prefix, uniqid());
+               if (!is_dir($temp)) {
+                       if (!mkdir($temp, 0700, true)) {
+                               throw new Exception("Could not create tempdir: ".error_get_last()["message"]);
+                       }
+               }
+               parent::__construct($temp);
+       }
+}