Debian Codegraph @

lib/3rdParty/composer/symfony/uid/Factory/NameBasedUuidFactory.php

raw symbols SCIP
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <[email protected]>
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 public function __construct(
21 private string $class,
22 private Uuid $namespace,
23 ) {
24 }
25
26 public function create(string $name): UuidV5|UuidV3
27 {
28 switch ($class = $this->class) {
29 case UuidV5::class: return Uuid::v5($this->namespace, $name);
30 case UuidV3::class: return Uuid::v3($this->namespace, $name);
31 }
32
33 if (is_subclass_of($class, UuidV5::class)) {
34 $uuid = Uuid::v5($this->namespace, $name);
35 } else {
36 $uuid = Uuid::v3($this->namespace, $name);
37 }
38
39 return new $class($uuid);
40 }
41 }