class Fields
Same name in this branch
- 11.1.x vendor/ramsey/uuid/src/Nonstandard/Fields.php \Ramsey\Uuid\Nonstandard\Fields
- 11.1.x vendor/ramsey/uuid/src/Guid/Fields.php \Ramsey\Uuid\Guid\Fields
- 11.1.x core/modules/views/src/Plugin/views/row/Fields.php \Drupal\views\Plugin\views\row\Fields
RFC 4122 variant UUIDs are comprised of a set of named fields
Internally, this class represents the fields together as a 16-byte binary string.
@psalm-immutable
Hierarchy
- class \Ramsey\Uuid\Rfc4122\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
1 file declares its use of Fields
- DegradedUuidBuilder.php in vendor/
ramsey/ uuid/ src/ Builder/ DegradedUuidBuilder.php
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.
File
-
vendor/
ramsey/ uuid/ src/ Rfc4122/ Fields.php, line 41
Namespace
Ramsey\Uuid\Rfc4122View 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 an RFC 4122 UUID
* @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 variant');
}
if (!$this->isCorrectVersion()) {
throw new InvalidArgumentException('The byte string received does not contain a valid RFC 4122 version');
}
}
public function getBytes() : string {
return $this->bytes;
}
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 getTimeHiAndVersion() : Hexadecimal {
return new Hexadecimal(bin2hex(substr($this->bytes, 6, 2)));
}
public function getTimeLow() : Hexadecimal {
return new Hexadecimal(bin2hex(substr($this->bytes, 0, 4)));
}
public function getTimeMid() : Hexadecimal {
return new Hexadecimal(bin2hex(substr($this->bytes, 4, 2)));
}
/**
* Returns the full 60-bit timestamp, without the version
*
* For version 2 UUIDs, the time_low field is the local identifier and
* should not be returned as part of the time. For this reason, we set the
* bottom 32 bits of the timestamp to 0's. As a result, there is some loss
* of fidelity of the timestamp, for version 2 UUIDs. The timestamp can be
* off by a range of 0 to 429.4967295 seconds (or 7 minutes, 9 seconds, and
* 496730 microseconds).
*
* For version 6 UUIDs, the timestamp order is reversed from the typical RFC
* 4122 order (the time bits are in the correct bit order, so that it is
* monotonically increasing). In returning the timestamp value, we put the
* bits in the order: time_low + time_mid + time_hi.
*/
public function getTimestamp() : Hexadecimal {
$timestamp = match ($this->getVersion()) { Uuid::UUID_TYPE_DCE_SECURITY => sprintf('%03x%04s%08s', hexdec($this->getTimeHiAndVersion()
->toString()) & 0xfff, $this->getTimeMid()
->toString(), ''),
Uuid::UUID_TYPE_REORDERED_TIME => sprintf('%08s%04s%03x', $this->getTimeLow()
->toString(), $this->getTimeMid()
->toString(), hexdec($this->getTimeHiAndVersion()
->toString()) & 0xfff),
Uuid::UUID_TYPE_UNIX_TIME => sprintf('%011s%04s', $this->getTimeLow()
->toString(), $this->getTimeMid()
->toString()),
default => sprintf('%03x%04s%08s', hexdec($this->getTimeHiAndVersion()
->toString()) & 0xfff, $this->getTimeMid()
->toString(), $this->getTimeLow()
->toString()),
};
return new Hexadecimal($timestamp);
}
public function getVersion() : ?int {
if ($this->isNil() || $this->isMax()) {
return null;
}
/** @var int[] $parts */
$parts = unpack('n*', $this->bytes);
return $parts[4] >> 12;
}
private function isCorrectVariant() : bool {
if ($this->isNil() || $this->isMax()) {
return true;
}
return $this->getVariant() === Uuid::RFC_4122;
}
}
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 |