當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Utilities::generateUID方法代碼示例

本文整理匯總了PHP中Utilities::generateUID方法的典型用法代碼示例。如果您正苦於以下問題:PHP Utilities::generateUID方法的具體用法?PHP Utilities::generateUID怎麽用?PHP Utilities::generateUID使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Utilities的用法示例。


在下文中一共展示了Utilities::generateUID方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: create

 /**
  * Create a new translatable email
  * 
  * @param DBObject $context
  * @param string $translation_id
  * @param array $variables
  * 
  * @return TranslatableEmail
  */
 public static function create($translation_id, $variables)
 {
     $email = new self();
     // Get translation data and variables
     $email->translation_id = $translation_id;
     $email->variables = array();
     if ($variables) {
         foreach ($variables as $k => $v) {
             // Convert DBObject types to type/id pairs for saving
             if ($v instanceof DBObject) {
                 $v = array('dbobject_type' => get_class($v), 'dbobject_id' => $v->id);
             }
             $email->variables[$k] = $v;
         }
     }
     // Add meta
     $email->created = time();
     // Generate token until it is indeed unique
     $email->token = Utilities::generateUID(function ($token) {
         $statement = DBI::prepare('SELECT * FROM ' . TranslatableEmail::getDBTable() . ' WHERE token = :token');
         $statement->execute(array(':token' => $token));
         $data = $statement->fetch();
         return !$data;
     });
     $email->save();
     return $email;
 }
開發者ID:eheb,項目名稱:renater-decide,代碼行數:36,代碼來源:TranslatableEmail.class.php

示例2: __construct

 /**
  * Constructor
  * 
  * @param integer $id identifier of user to load from database (null if loading not wanted)
  * @param array $data data to create the user from (if already fetched from database)
  * 
  * @throws UserNotFoundException
  */
 protected function __construct($id = null, $data = null)
 {
     if (!is_null($id)) {
         // Load from database if id given
         $statement = DBI::prepare('SELECT * FROM ' . self::getDBTable() . ' WHERE id = :id');
         $statement->execute(array(':id' => $id));
         $data = $statement->fetch();
     }
     if ($data) {
         // Fill properties from provided data
         $this->fillFromDBData($data);
         $this->hasPreferences = true;
     } else {
         // New user, set base data
         $this->id = $id;
         $this->created = time();
     }
     // Generate user remote auth secret
     if (Config::get('auth_remote_user_autogenerate_secret') && !$this->auth_secret) {
         $this->auth_secret = hash('sha256', $this->id . '|' . time() . '|' . Utilities::generateUID());
         $this->save();
     }
 }
開發者ID:eheb,項目名稱:renater-decide,代碼行數:31,代碼來源:UserBase.class.php

示例3: getSecurityToken

 /**
  * Get the security token, refreshing it in the process if needed
  * 
  * @return string
  */
 public static function getSecurityToken()
 {
     if (!is_null(self::$security_token)) {
         return self::$security_token['value'];
     }
     // Fetch existing token
     $token = array_key_exists('security_token', $_SESSION) ? $_SESSION['security_token'] : null;
     // Old token style, cancel it
     if (!is_array($token)) {
         $token = null;
     }
     if (!$token) {
         // First access
         $token = array('value' => Utilities::generateUID(), 'valid_until' => time() + 3600, 'old_value' => null);
     } else {
         if ($token['valid_until'] < time()) {
             // Must renew
             $token['old_value'] = $token['value'];
             $token['value'] = Utilities::generateUID();
             $token['valid_until'] = time() + 3600;
         } else {
             // Still valid, scrape old value from any previous changes
             $token['old_value'] = null;
         }
     }
     if ($token['old_value']) {
         // Send new value as header if changed
         header('X-Application-Security-Token: ' . $token['value']);
     }
     // Store in session
     $_SESSION['security_token'] = $token;
     // Cache in class
     self::$security_token = $token;
     return $token['value'];
 }
開發者ID:eheb,項目名稱:renater-decide,代碼行數:40,代碼來源:Utilities.class.php


注:本文中的Utilities::generateUID方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。