Permalink
Browse files

Fix #591

  • Loading branch information...
1 parent 3ae3263 commit a8435bccad099322afdf1a5191ad5df9dc1516cf @ogail ogail committed Jul 24, 2012
@@ -521,6 +521,38 @@ public static function tryGetValueInsensitive($key, $haystack, $default = null)
$array = array_change_key_case($haystack);
return Utilities::tryGetValue($array, strtolower($key), $default);
}
-}
-
-
+
+ /**
+ * Returns a string representation of a version 4 GUID, which uses random
+ * numbers.There are 6 reserved bits, and the GUIDs have this format:
+ * xxxxxxxx-xxxx-4xxx-[8|9|a|b]xxx-xxxxxxxxxxxx
+ * where 'x' is a hexadecimal digit, 0-9a-f.
+ *
+ * See http://tools.ietf.org/html/rfc4122 for more information.
+ *
+ * Note: This function is available on all platforms, while the
+ * com_create_guid() is only available for Windows.
+ *
+ * @static
+ *
+ * @return string A new GUID.
+ */
+ public static function getGuid()
+ {
+ return sprintf('%04x%04x-%04x-%04x-%02x%02x-%04x%04x%04x',
+ mt_rand(0, 65535),
+ mt_rand(0, 65535), // 32 bits for "time_low"
+ mt_rand(0, 65535), // 16 bits for "time_mid"
+ mt_rand(0, 4096) + 16384, // 16 bits for "time_hi_and_version", with
+ // the most significant 4 bits being 0100
+ // to indicate randomly generated version
+ mt_rand(0, 64) + 128, // 8 bits for "clock_seq_hi", with
+ // the most significant 2 bits being 10,
+ // required by version 4 GUIDs.
+ mt_rand(0, 256), // 8 bits for "clock_seq_low"
+ mt_rand(0, 65535), // 16 bits for "node 0" and "node 1"
+ mt_rand(0, 65535), // 16 bits for "node 2" and "node 3"
+ mt_rand(0, 65535) // 16 bits for "node 4" and "node 5"
+ );
+ }
+}
@@ -27,6 +27,7 @@
require_once 'Mail/mimePart.php';
require_once 'Mail/mimeDecode.php';
use WindowsAzure\Common\Internal\Resources;
+use WindowsAzure\Common\Internal\Utilities;
/**
* Reads and writes MIME for batch API.
@@ -54,10 +55,10 @@ public function encodeMimeMultipart($bodyPartContents)
{
$count = count($bodyPartContents);
$mimeType = Resources::MULTIPART_MIXED_TYPE;
- $batchGuid = strtolower(trim(com_create_guid(), '{}'));
+ $batchGuid = Utilities::getGuid();
$batchId = sprintf('batch_%s', $batchGuid);
$contentType1 = array('content_type' => "$mimeType");
- $changeSetGuid = strtolower(trim(com_create_guid(), '{}'));
+ $changeSetGuid = Utilities::getGuid();
$changeSetId = sprintf('changeset_%s', $changeSetGuid);
$contentType2 = array('content_type' => "$mimeType; boundary=$changeSetId");
$options = array(
@@ -482,6 +482,9 @@ public function testArrayKeyExistsInsensitive()
$this->assertTrue($actual);
}
+ /**
+ * @covers WindowsAzure\Common\Internal\Utilities::tryGetValueInsensitive
+ */
public function testTryGetValueInsensitive()
{
// Setup
@@ -495,6 +498,21 @@ public function testTryGetValueInsensitive()
// Assert
$this->assertEquals($value, $actual);
}
-}
-
-
+
+ /**
+ * @covers WindowsAzure\Common\Internal\Utilities::getGuid
+ */
+ public function testGetGuid()
+ {
+ // Test
+ $actual1 = Utilities::getGuid();
+ $actual2 = Utilities::getGuid();
+
+ // Assert
+ $this->assertNotNull($actual1);
+ $this->assertNotNull($actual2);
+ $this->assertInternalType('string', $actual1);
+ $this->assertInternalType('string', $actual2);
+ $this->assertNotEquals($actual1, $actual2);
+ }
+}

0 comments on commit a8435bc

Please sign in to comment.