major refactoring under the hood
[pharext/pharext] / src / pharext / Tempdir.php
index 2de174dfc8272889ab2d57677b7ea984eeaa39e5..eb592637e5ea921640bdce316549c676a285217f 100644 (file)
@@ -2,16 +2,19 @@
 
 namespace pharext;
 
+/**
+ * Create a temporary directory
+ */
 class Tempdir extends \SplFileInfo
 {
-       private $dir;
-       
+       /**
+        * @param string $prefix prefix to uniqid()
+        * @throws \pharext\Exception
+        */
        public function __construct($prefix) {
-               $temp = sprintf("%s/%s", sys_get_temp_dir(), uniqid($prefix));
-               if (!is_dir($temp)) {
-                       if (!mkdir($temp, 0700, true)) {
-                               throw new Exception("Could not create tempdir: ".error_get_last()["message"]);
-                       }
+               $temp = new Tempname($prefix);
+               if (!is_dir($temp) && !mkdir($temp, 0700, true)) {
+                       throw new Exception("Could not create tempdir: ".error_get_last()["message"]);
                }
                parent::__construct($temp);
        }