v5 example



    public function testV4()
    {
        $uuid = Uuid::v4();

        $this->assertInstanceOf(UuidV4::class$uuid);
    }

    public function testV5()
    {
        $uuid = Uuid::v5(new UuidV4('ec07aa88-f84e-47b9-a581-1c6b30a2f484'), 'the name');

        $this->assertInstanceOf(UuidV5::class$uuid);
        $this->assertSame('851def0c-b9c7-55aa-a991-130e769ec0a9', (string) $uuid);
    }

    public function testV6()
    {
        $uuid = Uuid::v6();

        $this->assertInstanceOf(UuidV6::class$uuid);

        
$em = (new \ReflectionClass(EntityManager::class))->newInstanceWithoutConstructor();
        $generator = new UuidGenerator();
        $this->assertInstanceOf(UuidV6::class$generator->generate($emnew Entity()));

        $generator = $generator->randomBased();
        $this->assertInstanceOf(UuidV4::class$generator->generate($emnew Entity()));

        $generator = $generator->timeBased();
        $this->assertInstanceOf(UuidV6::class$generator->generate($emnew Entity()));

        $generator = $generator->nameBased('prop1', Uuid::NAMESPACE_OID);
        $this->assertEquals(Uuid::v5(new Uuid(Uuid::NAMESPACE_OID), '3')$generator->generate($emnew Entity()));

        $generator = $generator->nameBased('prop2', Uuid::NAMESPACE_OID);
        $this->assertEquals(Uuid::v5(new Uuid(Uuid::NAMESPACE_OID), '2')$generator->generate($emnew Entity()));

        $generator = $generator->nameBased('getProp4', Uuid::NAMESPACE_OID);
        $this->assertEquals(Uuid::v5(new Uuid(Uuid::NAMESPACE_OID), '4')$generator->generate($emnew Entity()));

        $factory = new UuidFactory(6, 6, 5, 5, null, Uuid::NAMESPACE_OID);
        $generator = new UuidGenerator($factory);
        $generator = $generator->nameBased('prop1');
        $this->assertEquals(Uuid::v5(new Uuid(Uuid::NAMESPACE_OID), '3')$generator->generate($emnew Entity()));
    }
private Uuid $namespace;

    public function __construct(string $class, Uuid $namespace)
    {
        $this->class = $class;
        $this->namespace = $namespace;
    }

    public function create(string $name): UuidV5|UuidV3
    {
        switch ($class = $this->class) {
            case UuidV5::classreturn Uuid::v5($this->namespace, $name);
            case UuidV3::classreturn Uuid::v3($this->namespace, $name);
        }

        if (is_subclass_of($class, UuidV5::class)) {
            $uuid = Uuid::v5($this->namespace, $name);
        } else {
            $uuid = Uuid::v3($this->namespace, $name);
        }

        return new $class($uuid);
    }
}
protected function setUp(): void
    {
        $this->normalizer = new UidNormalizer();
    }

    public function testSupportsNormalization()
    {
        $this->assertTrue($this->normalizer->supportsNormalization(Uuid::v1()));
        $this->assertTrue($this->normalizer->supportsNormalization(Uuid::v3(Uuid::v1(), 'foo')));
        $this->assertTrue($this->normalizer->supportsNormalization(Uuid::v4()));
        $this->assertTrue($this->normalizer->supportsNormalization(Uuid::v5(Uuid::v1(), 'foo')));
        $this->assertTrue($this->normalizer->supportsNormalization(Uuid::v6()));
        $this->assertTrue($this->normalizer->supportsNormalization(new Ulid()));
        $this->assertFalse($this->normalizer->supportsNormalization(new \stdClass()));
    }

    public static function normalizeProvider()
    {
        $uidFormats = [null, 'canonical', 'base58', 'base32', 'rfc4122'];
        $data = [
             [
                 UuidV1::fromString('9b7541de-6f87-11ea-ab3c-9da9a81562fc'),
                
Home | Imprint | This part of the site doesn't use cookies.