/** * Constructor to set required paremeters * * @param mixed $dataCenter_id Unique ID for datacenter (if multiple locations are used) * @param mixed $machine_id Unique ID for machine (if multiple machines are used) * @throws \Exception */ publicfunction__construct($dataCenter_id, $machine_id) { if ($dataCenter_id > $this->maxDataCenterId) { thrownew \Exception('dataCenter id should between 0 and ' . $this->maxDataCenterId); } if ($machine_id > $this->maxMachineId) { thrownew \Exception('machine id should between 0 and ' . $this->maxMachineId); } $this->datacenter_id = $dataCenter_id; $this->machine_id = $machine_id; }
/** * Generate an unique ID based on SnowFlake * @return string * @throws \Exception */ publicfunctiongenerateID() { $sign = 0; // default 0 $timestamp = $this->getUnixTimestamp();