本文整理汇总了PHP中UUID::randomSource方法的典型用法代码示例。如果您正苦于以下问题:PHP UUID::randomSource方法的具体用法?PHP UUID::randomSource怎么用?PHP UUID::randomSource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UUID
的用法示例。
在下文中一共展示了UUID::randomSource方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initRandom
public static function initRandom()
{
/* Look for a system-provided source of randomness, which is usually crytographically secure.
/dev/urandom is tried first because tests suggest CAPICOM is quite slow to initialize. */
if (is_readable('/dev/urandom')) {
self::$randomSource = fopen('/dev/urandom', 'rb');
self::$randomFunc = 'randomFRead';
} else {
if (class_exists('COM', 0)) {
try {
self::$randomSource = new COM('CAPICOM.Utilities.1');
// See http://msdn.microsoft.com/en-us/library/aa388182(VS.85).aspx
self::$randomFunc = 'randomCOM';
} catch (Exception $e) {
}
}
}
return self::$randomFunc;
}
示例2: initRandom
public static function initRandom($how = NULL)
{
/* Look for a system-provided source of randomness, which is usually crytographically secure.
/dev/urandom is tried first because tests suggest it is faster than other options. */
if ($how === NULL) {
if (self::$randomFunc != self::randChoose) {
return self::$randomFunc;
} else {
if (is_readable('/dev/urandom')) {
$how = self::randDev;
} else {
if (function_exists('openssl_random_pseudo_bytes')) {
$how = self::randOpenSSL;
} else {
if (function_exists('mcrypt_create_iv')) {
$how = self::randMcrypt;
} else {
$how = self::randCAPICOM;
}
}
}
}
try {
self::initRandom($how);
} catch (Exception $e) {
self::$randomFunc = self::randPoor;
}
} else {
$source = NULL;
switch ($how) {
case self::randChoose:
self::$randomFunc = $how;
return self::initRandom();
case self::randPoor:
self::$randomFunc = $how;
break;
case self::randDev:
$source = @fopen('/dev/urandom', 'rb');
if (!$source) {
throw new UUIDException("Randomness source is not available.", 802);
}
break;
case self::randOpenSSL:
if (!function_exists('openssl_random_pseudo_bytes')) {
throw new UUIDException("Randomness source is not available.", 802);
}
break;
case self::randMcerypt:
if (!function_exists('mcrypt_create_iv')) {
throw new UUIDException("Randomness source is not available.", 802);
}
break;
case self::randCAPICOM:
// See http://msdn.microsoft.com/en-us/library/aa388182(VS.85).aspx
if (!class_exists('COM', 0)) {
throw new UUIDException("Randomness source is not available.", 802);
}
try {
$source = new COM('CAPICOM.Utilities.1');
} catch (Exception $e) {
throw new UUIDException("Randomness source is not available.", 802, $e);
}
break;
default:
throw new UUIDException("Randomness source not implemented.", 902);
}
self::$randomSource = $source;
self::$randomFunc = $how;
}
return self::$randomFunc;
}