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

Breadcrumb

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

function DefaultTimeGenerator::getValidNode

Uses the node provider given when constructing this instance to get the node ID (usually a MAC address)

Parameters

int|string|null $node A node value that may be used to override the node provider:

Return value

string 6-byte binary string representation of the node

Throws

InvalidArgumentException

1 call to DefaultTimeGenerator::getValidNode()
DefaultTimeGenerator::generate in vendor/ramsey/uuid/src/Generator/DefaultTimeGenerator.php
@inheritDoc

File

vendor/ramsey/uuid/src/Generator/DefaultTimeGenerator.php, line 112

Class

DefaultTimeGenerator
DefaultTimeGenerator generates strings of binary data based on a node ID, clock sequence, and the current time

Namespace

Ramsey\Uuid\Generator

Code

private function getValidNode(int|string|null $node) : string {
    if ($node === null) {
        $node = $this->nodeProvider
            ->getNode();
    }
    // Convert the node to hex, if it is still an integer.
    if (is_int($node)) {
        $node = dechex($node);
    }
    if (!preg_match('/^[A-Fa-f0-9]+$/', (string) $node) || strlen((string) $node) > 12) {
        throw new InvalidArgumentException('Invalid node value');
    }
    return (string) hex2bin(str_pad((string) $node, 12, '0', STR_PAD_LEFT));
}

API Navigation

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