Revision
72
Author
emsmith
Date
2006-12-12 13:47:21 -0800 (Tue, 12 Dec 2006)

Log Message

Better singleton handling and added support for sys_get_temp_dir which is in 5.2 cvs

Modified Paths

Diff

Modified: desktop/trunk/lib/folders.class.php (71 => 72)


--- desktop/trunk/lib/folders.class.php	2006-12-12 17:38:23 UTC (rev 71)
+++ desktop/trunk/lib/folders.class.php	2006-12-12 21:47:21 UTC (rev 72)
@@ -109,23 +109,15 @@
 	protected $appdata;
 
 	/**
-	 * public function __construct
+	 * protected function __construct
 	 *
 	 * Uses PHP_OS to get a "general" OS name and tries to figure out the
 	 * current desktop system
 	 *
 	 * @return void
 	 */
-	public function __construct()
+	protected function __construct()
 	{
-		if (!is_null(self::$singleton))
-		{
-			throw new CC_Exception(
-			'%1$s is a singleton class - use %1$s::instance() to retrieve the current object',
-			'CC_Folders');
-		}
-		self::$singleton = $this;
-
 		if (stristr(PHP_OS, 'winnt'))
 		{
 			$this->os = self::WINNT;
@@ -322,6 +314,10 @@
 	 */
 	public function get_temp()
 	{
+		if(function_exists('sys_get_temp_dir'))
+		{
+			return sys_get_temp_dir();
+		}
 		if (is_null($this->temp))
 		{
 			$env = $_SERVER + $_ENV;
@@ -333,13 +329,26 @@
 			{
 				$this->temp = $env['TMP'];
 			}
+			elseif (isset($env['TMPDIR']) && file_exists($env['TMPDIR']) && is_dir($env['TMPDIR']))
+			{
+				$this->temp = $env['TMPDIR'];
+			}
 			elseif (file_exists('/tmp/') && is_dir('/tmp/'))
 			{
 				$this->temp = '/tmp/';
 			}
 			else
 			{
-				$this->temp = $this->get_profile();
+				$temp_file = tempnam(md5(uniqid(rand(), TRUE)), '');
+				if($temp_file)
+				{
+					$this->temp = realpath(dirname($temp_file));
+					unlink($temp_file);
+				}
+				else
+				{
+					$this->temp = $this->get_profile();
+				}
 			}
 		}
 		return $this->temp;
@@ -416,16 +425,12 @@
 	}
 
 	/**
-	 * public function __clone()
+	 * protected function __clone()
 	 *
 	 * disable cloning of a singleton
 	 *
 	 * @return void
 	 */
-	public function __clone()
-	{
-		throw new CC_Exception('Cannot clone singleton object %s', 'CC_Folders');
-		return;
-	}
+	protected function __clone() {}
 
 }
\ No newline at end of file