本文整理汇总了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;
}
示例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();
}
}
示例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'];
}