Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

5.4: Cannot access COM_CREATE_GUID #591

Closed
jcookems opened this Issue · 1 comment

2 participants

@jcookems

When I upgraded to PHP 5.4, the unit tests failed because PHP could not access the COM_CREATE_GUID function. Instead of trying to figure out how to get it re-enabled, we should remove the call to that function, as pointed out in #465.

Removed Windows specific code (com_create_guid()) to make tests run on linux

I extracted @beberlei's getGuid method, made a few minor changes:

/**
 * 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.
 *
 * @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"
    );

Then, in MimeReaderWriter,

-    $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();
@ogail
Collaborator

yup we have to do this as this will stop our code from working on other platforms than Windows

@ogail ogail closed this issue from a commit
@ogail ogail Fix #591 a8435bc
@ogail ogail closed this in a8435bc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.