/** * Uses the provided seconds and micro-seconds to calculate the time_low, * time_mid, and time_high fields used by RFC 4122 version 1 UUIDs * * @param string $seconds * @param string $microSeconds * @return string[] An array containing `low`, `mid`, and `high` keys * @link http://tools.ietf.org/html/rfc4122#section-4.2.2 */ public function calculateTime($seconds, $microSeconds) { $uuidTime = new BigNumber('0'); $sec = new BigNumber($seconds); $sec->multiply('10000000'); $usec = new BigNumber($microSeconds); $usec->multiply('10'); $uuidTime->add($sec)->add($usec)->add('122192928000000000'); $uuidTimeHex = sprintf('%016s', $uuidTime->convertToBase(16)); return array('low' => substr($uuidTimeHex, 8), 'mid' => substr($uuidTimeHex, 4, 4), 'hi' => substr($uuidTimeHex, 0, 4)); }
/** * Transforms a given string to a (big) number, based on the set alphabet. * * @param string $string * * @return BigNumber */ private function stringToNum($string) { $number = new BigNumber(0); foreach (str_split(strrev($string)) as $char) { $number->multiply($this->alphabetLength)->add(array_search($char, $this->alphabet, false)); } return $number; }