public function testTimestamp() { $key = Base36TimeKey::generate(123456789); $this->assertEquals(123456789, floor(Base36TimeKey::getMsTime($key))); for ($x = 0; $x < 10; $x++) { $limit = 7000; for ($i = 0; $i < $limit; $i++) { $microtime = microtime(true); $key = Base36TimeKey::generate($microtime); $this->assertEquals(floor((string) $microtime), floor((string) Base36TimeKey::getMsTime($key))); } } }
/** * Generate a new FID * * @param string $vendor Vendor Key * @param string $app App key * @param string $type * @param string $indicator * @param null $secret * @param string $location * * @throws FidGenerateException * * @return string FID */ public static function generate($vendor, $app, $type, $indicator = SystemIndicator::ENTITY, $secret = null, $location = Location::UNKNOWN_REGION) { if (strlen($vendor) !== 3) { throw new FidGenerateException("Vendor Key must be 3 characters"); } if (strlen($app) !== 2) { throw new FidGenerateException("App Key must be 2 characters"); } if (strlen($type) !== 2) { throw new FidGenerateException("Entity Type must be 2 characters"); } if (!SystemIndicator::validate($indicator)) { throw new FidGenerateException("Invalid System Indicator"); } if (!Location::validate($location)) { throw new FidGenerateException("Invalid Data Location"); } $fid = sprintf("%s%s%s%s-%s-%s-%s", $indicator, $vendor, $app, $type, Base36TimeKey::generate(), $location, static::randomString($secret === null ? 7 : 6)); if ($secret !== null) { $fid .= strtoupper(substr(md5($secret . $fid), 0, 1)); } return $fid; }