Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Faker\Core;
4
 
5
use Faker\Extension\UuidExtension;
6
 
7
final class Uuid implements UuidExtension
8
{
9
    public function uuid3(): string
10
    {
11
        $number = new Number();
12
 
13
        // fix for compatibility with 32bit architecture; each mt_rand call is restricted to 32bit
14
        // two such calls will cause 64bits of randomness regardless of architecture
15
        $seed = $number->numberBetween(0, 2147483647) . '#' . $number->numberBetween(0, 2147483647);
16
 
17
        // Hash the seed and convert to a byte array
18
        $val = md5($seed, true);
19
        $byte = array_values(unpack('C16', $val));
20
 
21
        // extract fields from byte array
22
        $tLo = ($byte[0] << 24) | ($byte[1] << 16) | ($byte[2] << 8) | $byte[3];
23
        $tMi = ($byte[4] << 8) | $byte[5];
24
        $tHi = ($byte[6] << 8) | $byte[7];
25
        $csLo = $byte[9];
26
        $csHi = $byte[8] & 0x3f | (1 << 7);
27
 
28
        // correct byte order for big edian architecture
29
        if (pack('L', 0x6162797A) == pack('N', 0x6162797A)) {
30
            $tLo = (($tLo & 0x000000ff) << 24) | (($tLo & 0x0000ff00) << 8)
31
                | (($tLo & 0x00ff0000) >> 8) | (($tLo & 0xff000000) >> 24);
32
            $tMi = (($tMi & 0x00ff) << 8) | (($tMi & 0xff00) >> 8);
33
            $tHi = (($tHi & 0x00ff) << 8) | (($tHi & 0xff00) >> 8);
34
        }
35
 
36
        // apply version number
37
        $tHi &= 0x0fff;
38
        $tHi |= (3 << 12);
39
 
40
        // cast to string
41
        return sprintf(
42
            '%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x',
43
            $tLo,
44
            $tMi,
45
            $tHi,
46
            $csHi,
47
            $csLo,
48
            $byte[10],
49
            $byte[11],
50
            $byte[12],
51
            $byte[13],
52
            $byte[14],
53
            $byte[15],
54
        );
55
    }
56
}