generator = $this->createGenerator($paths); return $this->generator->valid(); } /** * @return string|false */ public function readDir() { if ($this->generator !== null && $this->generator->valid()) { $path = $this->generator->current(); $this->generator->next(); return $path; } return false; } public function rewindDir(): bool { if ($this->generator === null) { return false; } $this->generator->rewind(); return $this->generator->valid(); } public function closeDir(): bool { $this->generator = null; return true; } /** * @return mixed * @throws \BadMethodCallException Call undefined method */ public function __call(string $method, array $arguments) { $aliases = [ 'dir_opendir' => 'openDir', 'dir_readdir' => 'readDir', 'dir_rewinddir' => 'rewindDir', 'dir_closedir' => 'closeDir', ]; if (!isset($aliases[$method])) { throw new \BadMethodCallException('Call undefined method: ' . $method); } return $this->{$aliases[$method]}(...$arguments); } }