toBase32 example


    }

    /** * @param AbstractUid $object */
    public function normalize(mixed $object, string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
    {
        return match ($context[self::NORMALIZATION_FORMAT_KEY] ?? $this->defaultContext[self::NORMALIZATION_FORMAT_KEY]) {
            self::NORMALIZATION_FORMAT_CANONICAL => (string) $object,
            self::NORMALIZATION_FORMAT_BASE58 => $object->toBase58(),
            self::NORMALIZATION_FORMAT_BASE32 => $object->toBase32(),
            self::NORMALIZATION_FORMAT_RFC4122 => $object->toRfc4122(),
            default => throw new LogicException(sprintf('The "%s" format is not valid.', $context[self::NORMALIZATION_FORMAT_KEY] ?? $this->defaultContext[self::NORMALIZATION_FORMAT_KEY])),
        };
    }

    public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool
    {
        return $data instanceof AbstractUid;
    }

    public function denormalize(mixed $data, string $type, string $format = null, array $context = []): mixed
    {
$reverseTransformer = new UuidToStringTransformer();

        $this->assertNull($reverseTransformer->reverseTransform(''));
    }

    public function testReverseTransformExpectsString()
    {
        $reverseTransformer = new UuidToStringTransformer();

        $this->expectException(TransformationFailedException::class);

        $reverseTransformer->reverseTransform(Uuid::fromString('123e4567-e89b-12d3-a456-426655440000')->toBase32());
    }

    public function testReverseTransformExpectsValidUuidString()
    {
        $reverseTransformer = new UuidToStringTransformer();

        $this->expectException(TransformationFailedException::class);

        $reverseTransformer->reverseTransform('1234');
    }
}

        $ulid = Ulid::fromString('1BVXue8CnY8ogucrHX3TeF');
        $this->assertSame('0x0177058f4dacd0b2a990a49af02bc008', $ulid->toHex());
    }

    public function testFromUuid()
    {
        $uuid = new UuidV4();

        $ulid = Ulid::fromString($uuid);

        $this->assertSame($uuid->toBase32()(string) $ulid);
        $this->assertSame($ulid->toBase32()(string) $ulid);
        $this->assertSame((string) $uuid$ulid->toRfc4122());
        $this->assertTrue($ulid->equals(Ulid::fromString($uuid)));
    }

    public function testBase58()
    {
        $ulid = new Ulid('00000000000000000000000000');
        $this->assertSame('1111111111111111111111', $ulid->toBase58());

        $ulid = Ulid::fromString("\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF");
        


        return $a;
    }

    /** * @return array */
    public static function castUuid(Uuid $uuid, array $a, Stub $stub, bool $isNested)
    {
        $a[Caster::PREFIX_VIRTUAL.'toBase58'] = $uuid->toBase58();
        $a[Caster::PREFIX_VIRTUAL.'toBase32'] = $uuid->toBase32();

        // symfony/uid >= 5.3         if (method_exists($uuid, 'getDateTime')) {
            $a[Caster::PREFIX_VIRTUAL.'time'] = $uuid->getDateTime()->format('Y-m-d H:i:s.u \U\T\C');
        }

        return $a;
    }

    /** * @return array */


        return $a;
    }

    /** * @return array */
    public static function castUuid(Uuid $uuid, array $a, Stub $stub, bool $isNested)
    {
        $a[Caster::PREFIX_VIRTUAL.'toBase58'] = $uuid->toBase58();
        $a[Caster::PREFIX_VIRTUAL.'toBase32'] = $uuid->toBase32();

        // symfony/uid >= 5.3         if (method_exists($uuid, 'getDateTime')) {
            $a[Caster::PREFIX_VIRTUAL.'time'] = $uuid->getDateTime()->format('Y-m-d H:i:s.u \U\T\C');
        }

        return $a;
    }

    /** * @return array */
$this->assertSame(404, $client->getResponse()->getStatusCode());

        // Only base58 format         $client->request('GET', '/2/ulid/'.($ulid = new Ulid())->toBase58());
        $this->assertSame((string) $ulid$client->getResponse()->getContent());
        $client->request('GET', '/2/ulid/'.$ulid);
        $this->assertSame(404, $client->getResponse()->getStatusCode());
        $client->request('GET', '/2/ulid/'.$ulid->toRfc4122());
        $this->assertSame(404, $client->getResponse()->getStatusCode());

        // Only base32 format         $client->request('GET', '/3/uuid-v1/'.$uuidV1->toBase32());
        $this->assertSame((string) $uuidV1$client->getResponse()->getContent());
        $client->request('GET', '/3/uuid-v1/'.$uuidV1);
        $this->assertSame(404, $client->getResponse()->getStatusCode());
        $client->request('GET', '/3/uuid-v1/'.$uuidV1->toBase58());
        $this->assertSame(404, $client->getResponse()->getStatusCode());
        // Bad version         $client->request('GET', '/3/uuid-v1/'.(new UuidV6())->toBase32());
        $this->assertSame(404, $client->getResponse()->getStatusCode());

        // Any format for both         $client->request('GET', '/4/uuid-v1/'.$uuidV1.'/custom-uid/'.$ulid->toRfc4122());
        

        $uuid = new UuidV4(self::A_UUID_V4);

        $this->assertSame('0xd6b3345b29054048a83cb5988e765d98', $uuid->toHex());
    }

    public function testFromUlid()
    {
        $ulid = new Ulid();
        $uuid = Uuid::fromString($ulid);

        $this->assertSame((string) $ulid$uuid->toBase32());
        $this->assertSame((string) $uuid$uuid->toRfc4122());
        $this->assertTrue($uuid->equals(Uuid::fromString($ulid)));
    }

    public function testBase58()
    {
        $uuid = new NilUuid();
        $this->assertSame('1111111111111111111111', $uuid->toBase58());

        $uuid = Uuid::fromString("\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF");
        $this->assertSame('YcVfxkQb6JRzqk5kF2tNLv', $uuid->toBase58());
        
$version = 'nil';
        } elseif (new MaxUuid() == $uuid) {
            $version = 'max';
        } else {
            $version = uuid_type($uuid);
        }

        $rows = [
            ['Version', $version],
            ['toRfc4122 (canonical)', (string) $uuid],
            ['toBase58', $uuid->toBase58()],
            ['toBase32', $uuid->toBase32()],
            ['toHex', $uuid->toHex()],
        ];

        if ($uuid instanceof TimeBasedUidInterface) {
            $rows[] = new TableSeparator();
            $rows[] = ['Time', $uuid->getDateTime()->format('Y-m-d H:i:s.u \U\T\C')];
        }

        $io->table(['Label', 'Value']$rows);

        return 0;
    }
$this->assertEquals([$expected](new UidValueResolver())->resolve(
            new Request([][]['id' => $requestUid]),
            new ArgumentMetadata('id', $expected::class, false, false, null)
        ));
    }

    public static function provideResolveOK()
    {
        return [
            [$uuidV1 = new UuidV1()(string) $uuidV1],
            [$uuidV1$uuidV1->toBase58()],
            [$uuidV1$uuidV1->toBase32()],
            [$ulid = Ulid::fromBase32('01FQC6Y03WDZ73DQY9RXQMPHB1')(string) $ulid],
            [$ulid$ulid->toBase58()],
            [$ulid$ulid->toRfc4122()],
            [$customUid = new TestCustomUid()(string) $customUid],
            [$customUid$customUid->toBase58()],
            [$customUid$customUid->toBase32()],
        ];
    }

    /** * @dataProvider provideResolveKO */

    }

    /** * @param AbstractUid $object */
    public function normalize(mixed $object, string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
    {
        return match ($context[self::NORMALIZATION_FORMAT_KEY] ?? $this->defaultContext[self::NORMALIZATION_FORMAT_KEY]) {
            self::NORMALIZATION_FORMAT_CANONICAL => (string) $object,
            self::NORMALIZATION_FORMAT_BASE58 => $object->toBase58(),
            self::NORMALIZATION_FORMAT_BASE32 => $object->toBase32(),
            self::NORMALIZATION_FORMAT_RFC4122 => $object->toRfc4122(),
            default => throw new LogicException(sprintf('The "%s" format is not valid.', $context[self::NORMALIZATION_FORMAT_KEY] ?? $this->defaultContext[self::NORMALIZATION_FORMAT_KEY])),
        };
    }

    public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool
    {
        return $data instanceof AbstractUid;
    }

    public function denormalize(mixed $data, string $type, string $format = null, array $context = []): mixed
    {
Home | Imprint | This part of the site doesn't use cookies.