public function createTempFile(
        $prefix,
        $suffix,
        PhingFile $parentDir = null,
        $deleteOnExit = false,
        $createFile = false
    ) {
        $result = null;
        $parent = ($parentDir === null) ? sys_get_temp_dir() : $parentDir->getPath();

        if ($createFile) {
            try {
                $result = PhingFile::createTempFile($prefix, $suffix, new PhingFile($parent));
            } catch (IOException $e) {
                throw new BuildException("Could not create tempfile in " . $parent, $e);
            }
        } else {
            do {
                $result = new PhingFile($parent, $prefix . substr(md5((string) time()), 0, 8) . $suffix);
            } while ($result->exists());
        }

        if ($deleteOnExit) {
            $result->deleteOnExit();
        }

        return $result;
    }