lithium\util\String::uuid PHP Method

uuid() public static method

Generates an RFC 4122-compliant version 4 UUID.
public static uuid ( ) : string
return string The string representation of an RFC 4122-compliant, version 4 UUID.
    public static function uuid()
    {
        $uuid = static::random(16);
        $uuid[6] = chr(ord($uuid[6]) & static::UUID_CLEAR_VER | static::UUID_VERSION_4);
        $uuid[8] = chr(ord($uuid[8]) & static::UUID_CLEAR_VAR | static::UUID_VAR_RFC);
        return join('-', array(bin2hex(substr($uuid, 0, 4)), bin2hex(substr($uuid, 4, 2)), bin2hex(substr($uuid, 6, 2)), bin2hex(substr($uuid, 8, 2)), bin2hex(substr($uuid, 10, 6))));
    }

Usage Example

Beispiel #1
0
 /**
  * Obtain the session key.
  *
  * For this adapter, it is a UUID based on the SERVER_ADDR variable.
  *
  * @return string UUID.
  */
 public static function key()
 {
     $context = function ($value) use(&$config) {
         return isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '127.0.0.1';
     };
     return String::uuid($context);
 }
All Usage Examples Of lithium\util\String::uuid