Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
48 lines (37 loc) · 1.09 KB

File metadata and controls

48 lines (37 loc) · 1.09 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
/**
* @file
* Contains \DrupalPatchUtils\Php.
*/
namespace DrupalPatchUtils;
/**
* Generates a UUID v4 using PHP code.
*
* Loosely based on Ruby's UUIDTools generate_random logic.
*
* @see http://uuidtools.rubyforge.org/api/classes/UUIDTools/UUID.html
*/
class Uuid {
/**
* {@inheritdoc}
*/
public static function generate() {
$hex = substr(hash('sha256', microtime() . mt_rand()), 0, 32);
// The field names refer to RFC 4122 section 4.1.2.
$time_low = substr($hex, 0, 8);
$time_mid = substr($hex, 8, 4);
$time_hi_and_version = base_convert(substr($hex, 12, 4), 16, 10);
$time_hi_and_version &= 0x0FFF;
$time_hi_and_version |= (4 << 12);
$clock_seq_hi_and_reserved = base_convert(substr($hex, 16, 4), 16, 10);
$clock_seq_hi_and_reserved &= 0x3F;
$clock_seq_hi_and_reserved |= 0x80;
$clock_seq_low = substr($hex, 20, 2);
$nodes = substr($hex, 20);
$uuid = sprintf('%s-%s-%04x-%02x%02x-%s',
$time_low, $time_mid,
$time_hi_and_version, $clock_seq_hi_and_reserved,
$clock_seq_low, $nodes);
return $uuid;
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.