Esempio n. 1
0
 /**
  * Creates a UUID from a byte string.
  *
  * @param string $bytes
  * @return Uuid
  * @throws InvalidArgumentException If the $bytes string does not contain 16 characters
  */
 public static function fromBytes($bytes)
 {
     if (strlen($bytes) !== 16) {
         throw new InvalidArgumentException('$bytes string should contain 16 characters.');
     }
     $uuid = '';
     foreach (range(0, 15) as $step) {
         $uuid .= sprintf('%02x', ord($bytes[$step]));
         if (in_array($step, array(3, 5, 7, 9))) {
             $uuid .= '-';
         }
     }
     return Uuid::fromString($uuid);
 }