backend = $backend; $this->container = $fullCont; $this->dir = $dir; if ( substr( $this->dir, -1 ) === '/' ) { $this->dir = substr( $this->dir, 0, -1 ); // remove trailing slash } if ( $this->dir == '' ) { // whole container $this->suffixStart = 0; } else { // dir within container $this->suffixStart = strlen( $this->dir ) + 1; // size of "path/to/dir/" } $this->params = $params; } /** * @see Iterator::key() * @return int */ public function key() { return $this->pos; } /** * @see Iterator::next() */ public function next() { // Advance to the next file in the page next( $this->bufferIter ); ++$this->pos; // Check if there are no files left in this page and // advance to the next page if this page was not empty. if ( !$this->valid() && count( $this->bufferIter ) ) { $this->bufferIter = $this->pageFromList( $this->container, $this->dir, $this->bufferAfter, self::PAGE_SIZE, $this->params ); // updates $this->bufferAfter } } /** * @see Iterator::rewind() */ public function rewind() { $this->pos = 0; $this->bufferAfter = null; $this->bufferIter = $this->pageFromList( // @phan-suppress-next-line PhanTypeMismatchArgumentPropertyReferenceReal $this->container, $this->dir, $this->bufferAfter, self::PAGE_SIZE, $this->params ); // updates $this->bufferAfter } /** * @see Iterator::valid() * @return bool */ public function valid() { if ( $this->bufferIter === null ) { return false; // some failure? } else { return ( current( $this->bufferIter ) !== false ); // no paths can have this value } } /** * Get the given list portion (page) * * @param string $container Resolved container name * @param string $dir Resolved path relative to container * @param string &$after * @param int $limit * @param array $params * @return Traversable|array */ abstract protected function pageFromList( $container, $dir, &$after, $limit, array $params ); }