function Uuid::fromBytes
Creates a UUID from a byte string
@psalm-pure note: changing the internal factory is an edge case not covered by purity invariants, but under constant factory setups, this method operates in functionally pure manners
@psalm-suppress ImpureStaticProperty we know that the factory being replaced can lead to massive havoc across all consumers: that should never happen, and is generally to be discouraged. Until the factory is kept un-replaced, this method is effectively pure.
Parameters
string $bytes A binary string:
Return value
UuidInterface A UuidInterface instance created from a binary string representation
File
-
vendor/
ramsey/ uuid/ src/ Uuid.php, line 447
Class
- Uuid
- Uuid provides constants and static methods for working with and generating UUIDs
Namespace
Ramsey\UuidCode
public static function fromBytes(string $bytes) : UuidInterface {
if (!self::$factoryReplaced && strlen($bytes) === 16) {
$base16Uuid = bin2hex($bytes);
// Note: we are calling `fromString` internally because we don't know if the given `$bytes` is a valid UUID
return self::fromString(substr($base16Uuid, 0, 8) . '-' . substr($base16Uuid, 8, 4) . '-' . substr($base16Uuid, 12, 4) . '-' . substr($base16Uuid, 16, 4) . '-' . substr($base16Uuid, 20, 12));
}
return self::getFactory()->fromBytes($bytes);
}