* @package Mammut\IO */ class TempFile extends File { const _VERSION_ = '0.5.0.0'; /** * Create a new temp file object * * @param string $path * (optional) a created file that should be used as a "temp file" */ public function __construct($path = false, $prefix = 'TMP') { $this->path = $path ? $path : self::genTempfileName($prefix); if($this->isDir()) throw new IllegalStateException('dir'); $this->readonly = false; register_shutdown_function([$this,'kill']); if(!$this->exists()) $this->create(); $this->open(); } public static function genTempfileName($prefix = '') { return tempnam(sys_get_temp_dir(), $prefix); } /** * Kills the temp file * * @throws IllegalStateException if file is a directory */ public function kill() { if($this->isDir()) throw new IllegalStateException('dir'); if($this->isOpen()) $this->close(); $this->delete(); } }