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

Breadcrumb

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

function StringCodec::encode

Overrides CodecInterface::encode

2 methods override StringCodec::encode()
GuidStringCodec::encode in vendor/ramsey/uuid/src/Codec/GuidStringCodec.php
Returns a hexadecimal string representation of a UuidInterface
TimestampFirstCombCodec::encode in vendor/ramsey/uuid/src/Codec/TimestampFirstCombCodec.php
@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

File

vendor/ramsey/uuid/src/Codec/StringCodec.php, line 49

Class

StringCodec
StringCodec encodes and decodes RFC 4122 UUIDs

Namespace

Ramsey\Uuid\Codec

Code

public function encode(UuidInterface $uuid) : string {
    $hex = bin2hex($uuid->getFields()
        ->getBytes());
    
    /** @var non-empty-string */
    return sprintf('%08s-%04s-%04s-%04s-%012s', substr($hex, 0, 8), substr($hex, 8, 4), substr($hex, 12, 4), substr($hex, 16, 4), substr($hex, 20));
}

API Navigation

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