6 * Create a new temporary file
8 class Tempfile
extends \SplFileInfo
16 * @param string $prefix uniqid() prefix
17 * @param string $suffix e.g. file extension
18 * @throws \pharext\Exception
20 public function __construct($prefix, $suffix = ".tmp") {
24 $path = new Tempname($prefix, $suffix);
25 $this->handle
= fopen($path, "x");
26 } while (!is_resource($this->handle
) && $tries++
< 10);
29 if (!is_resource($this->handle
)) {
30 throw new Exception("Could not create temporary file");
33 parent
::__construct($path);
39 public function __destruct() {
40 @unlink
($this->getPathname());
46 public function closeStream() {
47 fclose($this->handle
);
51 * Retrieve the stream resource
54 public function getStream() {