d46250f7472b379e44ea17f98355af06d2f83eab
[pharext/pharext] / src / pharext / Tempname.php
1 <?php
2
3 namespace pharext;
4
5 use pharext\Exception;
6
7 /**
8 * A temporary file/directory name
9 */
10 class Tempname
11 {
12 /**
13 * @var string
14 */
15 private $name;
16
17 /**
18 * @param string $prefix uniqid() prefix
19 * @param string $suffix e.g. file extension
20 */
21 public function __construct($prefix, $suffix = null) {
22 $temp = sys_get_temp_dir() . "/pharext-" . posix_getlogin();
23 if (!is_dir($temp) && !mkdir($temp, 0700, true)) {
24 throw new Exception;
25 }
26 $this->name = $temp ."/". uniqid($prefix) . $suffix;
27 }
28
29 /**
30 * @return string
31 */
32 public function __toString() {
33 return (string) $this->name;
34 }
35 }