Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
/*
4
 * This file is part of the Symfony package.
5
 *
6
 * (c) Fabien Potencier <fabien@symfony.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
 
12
namespace Symfony\Component\Uid;
13
 
14
/**
15
 * A v4 UUID contains a 122-bit random number.
16
 *
17
 * @author Grégoire Pineau <lyrixx@lyrixx.info>
18
 */
19
class UuidV4 extends Uuid
20
{
21
    protected const TYPE = 4;
22
 
23
    public function __construct(string $uuid = null)
24
    {
25
        if (null === $uuid) {
26
            $uuid = random_bytes(16);
27
            $uuid[6] = $uuid[6] & "\x0F" | "\x40";
28
            $uuid[8] = $uuid[8] & "\x3F" | "\x80";
29
            $uuid = bin2hex($uuid);
30
 
31
            $this->uid = substr($uuid, 0, 8).'-'.substr($uuid, 8, 4).'-'.substr($uuid, 12, 4).'-'.substr($uuid, 16, 4).'-'.substr($uuid, 20, 12);
32
        } else {
33
            parent::__construct($uuid, true);
34
        }
35
    }
36
}