本文整理汇总了PHP中UUID::valid方法的典型用法代码示例。如果您正苦于以下问题:PHP UUID::valid方法的具体用法?PHP UUID::valid怎么用?PHP UUID::valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UUID
的用法示例。
在下文中一共展示了UUID::valid方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_valid
/**
* Tests UUID::valid()
*
* @test
* @dataProvider provider_valid
* @covers UUID::valid
* @param string $uuid UUID to test validity
* @param boolean $expected expect UUID to be valid?
*/
public function test_valid($uuid, $expected)
{
$this->assertEquals($expected, UUID::valid($uuid));
}
示例2: v5
/**
* Version 5 UUIDs are named based. They require a namespace (another
* valid UUID) and a value (the name). Given the same namespace and
* name, the output is always the same.
*
* @param string namespace
* @param string key name
* @return string
*/
public static function v5($namespace, $name)
{
if (!UUID::valid($namespace)) {
// All namespaces must be valid UUIDs
return FALSE;
}
// Get namespace in binary format
$nstr = UUID::bin($namespace);
// Calculate hash value
$hash = sha1($nstr . $name);
return sprintf('%08s-%04s-%04x-%04x-%12s', substr($hash, 0, 8), substr($hash, 8, 4), hexdec(substr($hash, 12, 4)) & 0xfff | 0x5000, hexdec(substr($hash, 16, 4)) & 0x3fff | 0x8000, substr($hash, 20, 12));
}