Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. OrderedTimeCodec.php

function OrderedTimeCodec::encodeBinary

Returns a binary string representation of a UUID, with the timestamp fields rearranged for optimized storage

@inheritDoc @psalm-return non-empty-string @psalm-suppress MoreSpecificReturnType we know that the retrieved `string` is never empty @psalm-suppress LessSpecificReturnStatement we know that the retrieved `string` is never empty

Overrides StringCodec::encodeBinary

File

vendor/ramsey/uuid/src/Codec/OrderedTimeCodec.php, line 57

Class

OrderedTimeCodec
OrderedTimeCodec encodes and decodes a UUID, optimizing the byte order for more efficient storage

Namespace

Ramsey\Uuid\Codec

Code

public function encodeBinary(UuidInterface $uuid) : string {
    if (!$uuid->getFields() instanceof Rfc4122FieldsInterface || $uuid->getFields()
        ->getVersion() !== Uuid::UUID_TYPE_TIME) {
        throw new InvalidArgumentException('Expected RFC 4122 version 1 (time-based) UUID');
    }
    $bytes = $uuid->getFields()
        ->getBytes();
    
    /** @phpstan-ignore-next-line PHPStan complains that this is not a non-empty-string. */
    return $bytes[6] . $bytes[7] . $bytes[4] . $bytes[5] . $bytes[0] . $bytes[1] . $bytes[2] . $bytes[3] . substr($bytes, 8);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal