_destination = $destination; $this->_directory = preg_replace("/^\/+/", "/", $directory); $this->rewind(); } /** * @return void * @throws IOException */ public function rewind():void { try{ $this->_list = []; $list = $this->_destination->_listDir($this->_directory); foreach($list as $item) $this->_list[$item->getFullPath()] = $item; if($this->_list) krsort($this->_list, SORT_STRING); } catch (Exception $e) { if($e->getCode() == FTPClient::CODE_TRUNCATED) throw new IOException($e->getMessage(), $e->getCode()); } } /** * @return bool */ public function hasNext(): bool { return !!$this->_list; } /** * @return iDestinationFile|null */ public function getNext():?iDestinationFile { if(!$this->hasNext()) return null; $file = array_pop($this->_list); $file->setPath($this->_destination->removeRealPath($file->getPath())); return $file; } }