Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Ganze Datei anzeigen | Leerzeichen ignorieren | Details | Blame | Letzte Änderung | Log anzeigen | RSS feed

Revision 148 Revision 1464
Zeile 291... Zeile 291...
291
    /**
291
    /**
292
     * Converts the UUID to a string for PHP serialization
292
     * Converts the UUID to a string for PHP serialization
293
     */
293
     */
294
    public function serialize(): string
294
    public function serialize(): string
295
    {
295
    {
296
        return $this->getFields()->getBytes();
296
        return $this->codec->encode($this);
297
    }
297
    }
Zeile 298... Zeile 298...
298
 
298
 
299
    /**
299
    /**
300
     * @return array{bytes: string}
300
     * @return array{bytes: string}
Zeile 444... Zeile 444...
444
     *                                      is generally to be discouraged. Until the factory is kept
444
     *                                      is generally to be discouraged. Until the factory is kept
445
     *                                      un-replaced, this method is effectively pure.
445
     *                                      un-replaced, this method is effectively pure.
446
     */
446
     */
447
    public static function fromBytes(string $bytes): UuidInterface
447
    public static function fromBytes(string $bytes): UuidInterface
448
    {
448
    {
449
        if (! self::$factoryReplaced && strlen($bytes) === 16) {
449
        if (!self::$factoryReplaced && strlen($bytes) === 16) {
450
            $base16Uuid = bin2hex($bytes);
450
            $base16Uuid = bin2hex($bytes);
Zeile 451... Zeile 451...
451
 
451
 
452
            // Note: we are calling `fromString` internally because we don't know if the given `$bytes` is a valid UUID
452
            // Note: we are calling `fromString` internally because we don't know if the given `$bytes` is a valid UUID
453
            return self::fromString(
453
            return self::fromString(
454
                substr($base16Uuid, 0, 8)
454
                substr($base16Uuid, 0, 8)
455
                . '-'
455
                    . '-'
456
                . substr($base16Uuid, 8, 4)
456
                    . substr($base16Uuid, 8, 4)
457
                . '-'
457
                    . '-'
458
                . substr($base16Uuid, 12, 4)
458
                    . substr($base16Uuid, 12, 4)
459
                . '-'
459
                    . '-'
460
                . substr($base16Uuid, 16, 4)
460
                    . substr($base16Uuid, 16, 4)
461
                . '-'
461
                    . '-'
462
                . substr($base16Uuid, 20, 12)
462
                    . substr($base16Uuid, 20, 12)
463
            );
463
            );
Zeile 464... Zeile 464...
464
        }
464
        }
465
 
465
 
Zeile 483... Zeile 483...
483
     *                                      un-replaced, this method is effectively pure.
483
     *                                      un-replaced, this method is effectively pure.
484
     */
484
     */
485
    public static function fromString(string $uuid): UuidInterface
485
    public static function fromString(string $uuid): UuidInterface
486
    {
486
    {
487
        $uuid = strtolower($uuid);
487
        $uuid = strtolower($uuid);
488
        if (! self::$factoryReplaced && preg_match(LazyUuidFromString::VALID_REGEX, $uuid) === 1) {
488
        if (!self::$factoryReplaced && preg_match(LazyUuidFromString::VALID_REGEX, $uuid) === 1) {
489
            assert($uuid !== '');
489
            assert($uuid !== '');
Zeile 490... Zeile 490...
490
 
490
 
491
            return new LazyUuidFromString($uuid);
491
            return new LazyUuidFromString($uuid);