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\Factory;
13
 
14
use Symfony\Component\Uid\Uuid;
15
use Symfony\Component\Uid\UuidV3;
16
use Symfony\Component\Uid\UuidV5;
17
 
18
class NameBasedUuidFactory
19
{
20
    private string $class;
21
    private Uuid $namespace;
22
 
23
    public function __construct(string $class, Uuid $namespace)
24
    {
25
        $this->class = $class;
26
        $this->namespace = $namespace;
27
    }
28
 
29
    public function create(string $name): UuidV5|UuidV3
30
    {
31
        switch ($class = $this->class) {
32
            case UuidV5::class: return Uuid::v5($this->namespace, $name);
33
            case UuidV3::class: return Uuid::v3($this->namespace, $name);
34
        }
35
 
36
        if (is_subclass_of($class, UuidV5::class)) {
37
            $uuid = Uuid::v5($this->namespace, $name);
38
        } else {
39
            $uuid = Uuid::v3($this->namespace, $name);
40
        }
41
 
42
        return new $class($uuid);
43
    }
44
}