Пример #1
0
 /**
  * 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
0
 /**
  * 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));
 }