/** * @param callable $func * @throws \Exception */ public function init(callable $func = null) { $count = count($this->providers); if (empty($count)) { return; } if (empty($func)) { $func = function ($code, $n) { // do nothing }; } $provider = $this->providers[0]; $func(0, count($provider)); $this->startInsertIndex(); $n = 0; $time = Query::time(); foreach ($provider as $ip => $id) { if (is_string($id)) { $id = $provider->idByDivision($id); } for ($i = 1; $i < $count && $id == 0; $i++) { $id = $this->providers[$i]->findId($ip); } $this->insertIndex($ip, $this->translateId($id)); $n++; if ($time < Query::time()) { $time = Query::time(); $func(1, $n); } } $this->endInsertIndex(); $func(2, 0); $this->rewind(); // init \Iterator offset & buffer }