Advertisement
fruffl

Untitled

Jul 18th, 2013
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.90 KB | None | 0 0
  1.  
  2.         CONST ENCODE_BASE_64        = 1;
  3.        
  4.         CONST UUID_CLEAR_VER        = 15;
  5.         CONST UUID_VERSION_4        = 64;
  6.         CONST UUID_CLEAR_VAR        = 63;
  7.         CONST UUID_VAR_RFC      = 128;
  8.  
  9.         static function uuid(array $__options = [])
  10.         {
  11.             $__options +=
  12.             [
  13.                 'delimiter'     => self::MINUS,
  14.                 'before'    => self::DEVOID,
  15.                 'after'     => self::DEVOID
  16.             ];
  17.            
  18.             $uuid       = static::random(0x10);
  19.            
  20.             $uuid[0x06] = chr(ord($uuid[0x06]) & static::UUID_CLEAR_VER | static::UUID_VERSION_4);
  21.             $uuid[0x08] = chr(ord($uuid[0x08]) & static::UUID_CLEAR_VAR | static::UUID_VAR_RFC);
  22.            
  23.             return static::insert('{:before}{:value}{:after}', ['value' => static::join([
  24.                 bin2hex(static::sub($uuid, 0x00, 0x04)),
  25.                 bin2hex(static::sub($uuid, 0x04, 0x02)),
  26.                 bin2hex(static::sub($uuid, 0x06, 0x02)),
  27.                 bin2hex(static::sub($uuid, 0x08, 0x02)),
  28.                 bin2hex(static::sub($uuid, 0x0A, 0x06))], $__options['delimiter'])] + $__options);
  29.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement