本文整理汇总了PHP中Uuid::nameBased方法的典型用法代码示例。如果您正苦于以下问题:PHP Uuid::nameBased方法的具体用法?PHP Uuid::nameBased怎么用?PHP Uuid::nameBased使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Uuid
的用法示例。
在下文中一共展示了Uuid::nameBased方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testNameBased
public function testNameBased()
{
// test UUID parts
$uuid = explode('-', Uuid::nameBased('bar'));
$this->assertEquals(5, count($uuid));
$this->assertEquals(true, ctype_xdigit($uuid[0]), 'time-low');
$this->assertEquals(true, ctype_xdigit($uuid[1]), 'time-mid');
$this->assertEquals(true, ctype_xdigit($uuid[2]), 'time-high-and-version');
$this->assertEquals(true, ctype_xdigit($uuid[3]), 'clock-seq-and-reserved / clock-seq-low');
$this->assertEquals(true, ctype_xdigit($uuid[4]), 'node');
$this->assertEquals(8, strlen($uuid[0]), 'time-low');
$this->assertEquals(4, strlen($uuid[1]), 'time-mid');
$this->assertEquals(4, strlen($uuid[2]), 'time-high-and-version');
$this->assertEquals(4, strlen($uuid[3]), 'clock-seq-and-reserved / clock-seq-low');
$this->assertEquals(12, strlen($uuid[4]), 'node');
$this->assertEquals(5, hexdec($uuid[2]) >> 12, 'Set the four most significant bits (bits 12 through 15) of the time_hi_and_version field to the appropriate 4-bit version number from Section 4.1.3.');
$this->assertEquals(2, hexdec($uuid[3]) >> 14, 'Set the two most significant bits (bits 6 and 7) of the clock_seq_hi_and_reserved to zero and one, respectively.');
// the UUIDs generated at different times from the same name in the same
// namespace MUST be equal.
$uuid = Uuid::nameBased('foobar');
sleep(1);
$this->assertEquals($uuid, Uuid::nameBased('foobar'));
// the UUIDs generated from two different names in the same namespace
// should be different (with very high probability).
$this->assertTrue(Uuid::nameBased('foobar') != Uuid::nameBased('bar'));
}