public static function create($type, $name) { //get or create namespace uuid for Group-Office $namespace = \GO::config()->get_setting('uuid_namespace'); if (!$namespace) { $namespace = UUID::v4(); \GO::config()->save_setting('uuid_namespace', $namespace); } return UUID::v5($namespace, $type . $name); }
/** * Tests UUID::v5() * * @test * @dataProvider provider_v5_sha1 * @covers UUID::v5 * @param string $value value to generate UUID from * @param string $expected UUID */ public function test_v5_sha1($value, $expected) { $this->assertEquals($expected, UUID::v5(UUID::NIL, $value)); }
/** * * getTempFilename - HelperFunction * * @param string $url * @param string $NS * * @return */ function getTempFilename($url, $NS = '09c8637d-64f7-5eed-a80a-07a59059c47c') { //1.3.6.1.4.1.37553.8.1.8.8.5.65.1 return sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'download.zip.' . mt_rand(1000, 9999) . '.' . UUID::v3($NS, $url) . '.' . UUID::v5($NS, $url) . '.' . UUID::v4() . '.' . 'zip'; }
<?php namespace cd; set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/../core/'); require_once 'UUID.php'; $v3 = UUID::v3('514d2ee9-58ed-49ef-a592-1a49c268e2a2', 'test crap 123'); if ($v3 != "19d179a2-9511-3595-a8e2-490b981e92c2") { echo "FAIL 1\n"; } $v5 = UUID::v5('514d2ee9-58ed-49ef-a592-1a49c268e2a2', 'test crap 123'); if ($v5 != "f1b18651-7633-5945-8527-853ddc5b6393") { echo "FAIL 2\n"; } $v4 = UUID::v4(); echo "UUID v3 (md5): " . $v3 . "\n"; echo "UUID v5 (sha1): " . $v5 . "\n"; echo "UUID v4 (rand): " . $v4 . "\n"; $hex = UUID::toHex('3F2504E0-4F89-11D3-9A0C-0305E82C3301'); if ($hex != 'E004253F894FD3119A0C0305E82C3301') { echo "FAIL 3\n"; }
/** Creates iCalendar begin tag */ private function tagBegin($obj, $s = '') { $res = "BEGIN:" . $obj . "\r\n"; switch ($obj) { case 'VCALENDAR': $uuid = UUID::v5('7c7884bf-14f8-478a-ab0e-778a6ac1d437', $this->name); $res .= "VERSION:2.0\r\n" . "PRODID:-//" . $this->prod_id . "//NONSGML v1.0//EN\r\n" . "X-WR-CALNAME:" . $s . "\r\n" . ($this->desc ? "X-WR-CALDESC:" . $this->desc . "\r\n" : '') . "X-WR-TIMEZONE:" . $this->timezone . "\r\n" . "X-WR-RELCALID:" . $uuid . "\r\n" . "CALSCALE:GREGORIAN\r\n" . "METHOD:PUBLISH\r\n"; // XXX ??? snodde från googles kalender break; case 'VEVENT': break; } return $res; }
{ return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xfff) | 0x4000, mt_rand(0, 0x3fff) | 0x8000, mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)); } public static function v5($namespace, $name) { if (!self::is_valid($namespace)) { return false; } // Get hexadecimal components of namespace $nhex = str_replace(array('-', '{', '}'), '', $namespace); // Binary Value $nstr = ''; // Convert Namespace UUID to bits for ($i = 0; $i < strlen($nhex); $i += 2) { $nstr .= chr(hexdec($nhex[$i] . $nhex[$i + 1])); } // 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)); } public static function is_valid($uuid) { return preg_match('/^\\{?[0-9a-f]{8}\\-?[0-9a-f]{4}\\-?[0-9a-f]{4}\\-?' . '[0-9a-f]{4}\\-?[0-9a-f]{12}\\}?$/i', $uuid) === 1; } } // Usage // Named-based UUID. $v3uuid = UUID::v3('1546058f-5a25-4334-85ae-e68f2a44bbaf', 'SomeRandomString'); $v5uuid = UUID::v5('1546058f-5a25-4334-85ae-e68f2a44bbaf', 'SomeRandomString'); // Pseudo-random UUID $v4uuid = UUID::v4();
public static function Create() { return UUID::v5(UUID::v4(), uniqid()); }
public function buildSoapHeaders() { $timeStamp = gmdate("Y-m-d\\TH:i:s\\Z"); $requestId = UUID::v5($this->uuidNameSpace, $timeStamp); if (false === $requestId) { throw new Exception("Failed to generate the mandatory UUID"); } $payzenSoapHeaders = array('shopId' => $this->payzenAccount['shopId'], 'requestId' => $requestId, 'timestamp' => $timeStamp, 'mode' => $this->payzenAccount['mode'], 'authToken' => $this->buildAuthToken($requestId, $timeStamp)); $soapHeaders = array(); foreach ($payzenSoapHeaders as $header => $value) { $soapHeaders[] = new SOAPHeader($this->payzenAccount['ns'], $header, $value); } return $soapHeaders; }