[Mapbender-commits] r6585 - trunk/mapbender/http/classes

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Jul 8 09:14:11 EDT 2010


Author: christoph
Date: 2010-07-08 13:14:11 +0000 (Thu, 08 Jul 2010)
New Revision: 6585

Added:
   trunk/mapbender/http/classes/class_Uuid.php
Log:
Uuid class

Added: trunk/mapbender/http/classes/class_Uuid.php
===================================================================
--- trunk/mapbender/http/classes/class_Uuid.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_Uuid.php	2010-07-08 13:14:11 UTC (rev 6585)
@@ -0,0 +1,37 @@
+<?php
+# License:
+# Copyright (c) 2009, Open Source Geospatial Foundation
+# This program is dual licensed under the GNU General Public License 
+# and Simplified BSD license.  
+# http://svn.osgeo.org/mapbender/trunk/mapbender/license/license.txt
+
+class Uuid {
+	private $uuid;
+	
+	public function __construct ($aUuid = null) {
+		if (is_null($aUuid)) {
+			$chars = md5(uniqid(mt_rand(), true));
+			$uuid  = substr($chars,0,8) . '-';
+			$uuid .= substr($chars,8,4) . '-';
+			$uuid .= substr($chars,12,4) . '-';
+			$uuid .= substr($chars,16,4) . '-';
+			$uuid .= substr($chars,20,12);
+			$this->uuid = $uuid;
+		}
+		else {
+			$this->uuid = $aUuid;
+		}
+	}	
+
+	public function isValid () {
+		if(preg_match('/^\{?[0-9a-f]{8}\-?[0-9a-f]{4}\-?[0-9a-f]{4}\-?[0-9a-f]{4}\-?[0-9a-f]{12}\}?$/i', $this->uuid)){
+			return true;
+		}
+		return false;
+	}
+
+	public function __toString () {
+		return $this->uuid;
+	}
+}
+?>
\ No newline at end of file



More information about the Mapbender_commits mailing list