/** * * Returns the OS-specific directory for temporary files; uses the Solar * `$system/tmp` directory when available. * * @param string $sub Add this subdirectory to the returned temporary * directory name. * * @return string The temporary directory path. * */ public static function tmp($sub = '') { // find the tmp dir if needed if (!Solar_Dir::$_tmp) { // use the system if we can if (Solar::$system) { $tmp = Solar::$system . "/tmp"; } elseif (function_exists('sys_get_temp_dir')) { $tmp = sys_get_temp_dir(); } else { $tmp = Solar_Dir::_tmp(); } // remove trailing separator and save Solar_Dir::$_tmp = rtrim($tmp, DIRECTORY_SEPARATOR); } // do we have a subdirectory request? $sub = trim($sub); if ($sub) { // remove leading and trailing separators, and force exactly // one trailing separator $sub = trim($sub, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; } return Solar_Dir::$_tmp . DIRECTORY_SEPARATOR . $sub; }