示例#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);
 }
示例#2
0
 public function SetUser($user = null, $firstName = null, $fullName = null, $email = null, $isAnonymous = null, $uuid = null)
 {
     $timestamp = time() + 60 * 60 * 24 * 30;
     $this->firstName = $this->StoreOrRetrieveUserCookie('rgfirstname', $firstName);
     $this->fullName = $this->StoreOrRetrieveUserCookie('rgfullname', $fullName);
     $this->email = $this->StoreOrRetrieveUserCookie('rgemail', $email);
     $this->uuid = $this->StoreOrRetrieveUserCookie('rguuidvalue', $uuid);
     $this->isAnonymous = $this->StoreOrRetrieveUserCookie('rgisanonymous', $isAnonymous ? 'true' : 'false') == 'true' ? true : false;
     if (is_string($user)) {
         $this->user = $user;
         if (php_sapi_name() != 'cli' && !headers_sent()) {
             setcookie('rguserid', $user, $timestamp);
             setcookie('rguuid', 'false', $timestamp);
         }
     } else {
         if (!array_key_exists('rguuid', $_COOKIE)) {
             $this->user = (string) Uuid::uuid4();
             if (php_sapi_name() != 'cli' && !headers_sent()) {
                 setcookie('rguserid', $this->user, $timestamp);
                 setcookie('rguuid', 'true', $timestamp);
             }
         } else {
             if (array_key_exists('rguserid', $_COOKIE)) {
                 $this->user = $_COOKIE['rguserid'];
             }
         }
         $this->isAnonymous = $this->StoreOrRetrieveUserCookie('rgisanonymous', 'true') == 'true';
     }
 }