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

Breadcrumb

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

function OrderedTimeCodec::decodeBytes

Returns a UuidInterface derived from an ordered-time binary string representation

@inheritDoc

Throws

InvalidArgumentException if $bytes is an invalid length

Overrides StringCodec::decodeBytes

File

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

Class

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

Namespace

Ramsey\Uuid\Codec

Code

public function decodeBytes(string $bytes) : UuidInterface {
    if (strlen($bytes) !== 16) {
        throw new InvalidArgumentException('$bytes string should contain 16 characters.');
    }
    // Rearrange the bytes to their original order.
    $rearrangedBytes = $bytes[4] . $bytes[5] . $bytes[6] . $bytes[7] . $bytes[2] . $bytes[3] . $bytes[0] . $bytes[1] . substr($bytes, 8);
    $uuid = parent::decodeBytes($rearrangedBytes);
    if (!$uuid->getFields() instanceof Rfc4122FieldsInterface || $uuid->getFields()
        ->getVersion() !== Uuid::UUID_TYPE_TIME) {
        throw new UnsupportedOperationException('Attempting to decode a non-time-based UUID using ' . 'OrderedTimeCodec');
    }
    return $uuid;
}

API Navigation

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