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

Breadcrumb

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

class Fields

Same name in this branch
  1. 11.1.x vendor/ramsey/uuid/src/Nonstandard/Fields.php \Ramsey\Uuid\Nonstandard\Fields
  2. 11.1.x vendor/ramsey/uuid/src/Rfc4122/Fields.php \Ramsey\Uuid\Rfc4122\Fields
  3. 11.1.x core/modules/views/src/Plugin/views/row/Fields.php \Drupal\views\Plugin\views\row\Fields

GUIDs are comprised of a set of named fields, according to RFC 4122

@psalm-immutable

Hierarchy

  • class \Ramsey\Uuid\Guid\Fields implements \Ramsey\Uuid\Rfc4122\FieldsInterface uses \Ramsey\Uuid\Rfc4122\MaxTrait, \Ramsey\Uuid\Rfc4122\NilTrait, \Ramsey\Uuid\Fields\SerializableFieldsTrait, \Ramsey\Uuid\Rfc4122\VariantTrait, \Ramsey\Uuid\Rfc4122\VersionTrait

Expanded class hierarchy of Fields

See also

Guid

47 string references to 'Fields'
AddFormBase::buildEntityFormElement in core/modules/media_library/src/Form/AddFormBase.php
Builds the sub-form for setting required fields on a new media item.
CachePluginBase::getRowCacheKeys in core/modules/views/src/Plugin/views/cache/CachePluginBase.php
Returns the row cache keys.
Collection::getCompositeOption in vendor/symfony/validator/Constraints/Collection.php
Returns the name of the property that contains the nested constraints.
Collection::getRequiredOptions in vendor/symfony/validator/Constraints/Collection.php
Returns the name of the required options.
Comment::rowStyleOptions in core/modules/comment/src/Plugin/views/wizard/Comment.php
Retrieves row style plugin names.

... See full list

File

vendor/ramsey/uuid/src/Guid/Fields.php, line 46

Namespace

Ramsey\Uuid\Guid
View source
final class Fields implements FieldsInterface {
    use MaxTrait;
    use NilTrait;
    use SerializableFieldsTrait;
    use VariantTrait;
    use VersionTrait;
    
    /**
     * @param string $bytes A 16-byte binary string representation of a UUID
     *
     * @throws InvalidArgumentException if the byte string is not exactly 16 bytes
     * @throws InvalidArgumentException if the byte string does not represent a GUID
     * @throws InvalidArgumentException if the byte string does not contain a valid version
     */
    public function __construct(string $bytes) {
        if (strlen($this->bytes) !== 16) {
            throw new InvalidArgumentException('The byte string must be 16 bytes long; ' . 'received ' . strlen($this->bytes) . ' bytes');
        }
        if (!$this->isCorrectVariant()) {
            throw new InvalidArgumentException('The byte string received does not conform to the RFC ' . '4122 or Microsoft Corporation variants');
        }
        if (!$this->isCorrectVersion()) {
            throw new InvalidArgumentException('The byte string received does not contain a valid version');
        }
    }
    public function getBytes() : string {
        return $this->bytes;
    }
    public function getTimeLow() : Hexadecimal {
        // Swap the bytes from little endian to network byte order.
        
        /** @var array $hex */
        $hex = unpack('H*', pack('v*', hexdec(bin2hex(substr($this->bytes, 2, 2))), hexdec(bin2hex(substr($this->bytes, 0, 2)))));
        return new Hexadecimal((string) ($hex[1] ?? ''));
    }
    public function getTimeMid() : Hexadecimal {
        // Swap the bytes from little endian to network byte order.
        
        /** @var array $hex */
        $hex = unpack('H*', pack('v', hexdec(bin2hex(substr($this->bytes, 4, 2)))));
        return new Hexadecimal((string) ($hex[1] ?? ''));
    }
    public function getTimeHiAndVersion() : Hexadecimal {
        // Swap the bytes from little endian to network byte order.
        
        /** @var array $hex */
        $hex = unpack('H*', pack('v', hexdec(bin2hex(substr($this->bytes, 6, 2)))));
        return new Hexadecimal((string) ($hex[1] ?? ''));
    }
    public function getTimestamp() : Hexadecimal {
        return new Hexadecimal(sprintf('%03x%04s%08s', hexdec($this->getTimeHiAndVersion()
            ->toString()) & 0xfff, $this->getTimeMid()
            ->toString(), $this->getTimeLow()
            ->toString()));
    }
    public function getClockSeq() : Hexadecimal {
        if ($this->isMax()) {
            $clockSeq = 0xffff;
        }
        elseif ($this->isNil()) {
            $clockSeq = 0x0;
        }
        else {
            $clockSeq = hexdec(bin2hex(substr($this->bytes, 8, 2))) & 0x3fff;
        }
        return new Hexadecimal(str_pad(dechex($clockSeq), 4, '0', STR_PAD_LEFT));
    }
    public function getClockSeqHiAndReserved() : Hexadecimal {
        return new Hexadecimal(bin2hex(substr($this->bytes, 8, 1)));
    }
    public function getClockSeqLow() : Hexadecimal {
        return new Hexadecimal(bin2hex(substr($this->bytes, 9, 1)));
    }
    public function getNode() : Hexadecimal {
        return new Hexadecimal(bin2hex(substr($this->bytes, 10)));
    }
    public function getVersion() : ?int {
        if ($this->isNil() || $this->isMax()) {
            return null;
        }
        
        /** @var array $parts */
        $parts = unpack('n*', $this->bytes);
        return (int) $parts[4] >> 4 & 0xf;
    }
    private function isCorrectVariant() : bool {
        if ($this->isNil() || $this->isMax()) {
            return true;
        }
        $variant = $this->getVariant();
        return $variant === Uuid::RFC_4122 || $variant === Uuid::RESERVED_MICROSOFT;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
Fields::getBytes public function Returns the bytes that comprise the fields Overrides MaxTrait::getBytes
Fields::getClockSeq public function Returns the full 16-bit clock sequence, with the variant bits (two most
significant bits) masked out
Overrides FieldsInterface::getClockSeq
Fields::getClockSeqHiAndReserved public function Returns the high field of the clock sequence multiplexed with the variant Overrides FieldsInterface::getClockSeqHiAndReserved
Fields::getClockSeqLow public function Returns the low field of the clock sequence Overrides FieldsInterface::getClockSeqLow
Fields::getNode public function Returns the node field Overrides FieldsInterface::getNode
Fields::getTimeHiAndVersion public function Returns the high field of the timestamp multiplexed with the version Overrides FieldsInterface::getTimeHiAndVersion
Fields::getTimeLow public function Returns the low field of the timestamp Overrides FieldsInterface::getTimeLow
Fields::getTimeMid public function Returns the middle field of the timestamp Overrides FieldsInterface::getTimeMid
Fields::getTimestamp public function Returns the full 60-bit timestamp, without the version Overrides FieldsInterface::getTimestamp
Fields::getVersion public function Returns the version Overrides VersionTrait::getVersion
Fields::isCorrectVariant private function
Fields::__construct public function Overrides SerializableFieldsTrait::__construct
MaxTrait::isMax public function Returns true if the byte string represents a max UUID
NilTrait::isNil public function Returns true if the byte string represents a nil UUID
SerializableFieldsTrait::serialize public function Returns a string representation of object
SerializableFieldsTrait::unserialize public function Constructs the object from a serialized string representation
SerializableFieldsTrait::__serialize public function
SerializableFieldsTrait::__unserialize public function @psalm-suppress UnusedMethodCall
VariantTrait::getVariant public function Returns the variant identifier, according to RFC 4122, for the given bytes
VersionTrait::isCorrectVersion private function Returns true if the version matches one of those defined by RFC 4122

API Navigation

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