/** * Recursive backup collecting. * * @param string $path * @param integer $depth */ protected function collect($path, $depth) { $dItter = new DirectoryIterator($path); // collect all matching subdirs and get all the backup files if ($depth < $this->target->countChangingPathElements()) { foreach ($dItter as $i => $file) { if ($file->isDot()) { continue; } // TODO: match directory against dir-regex Target::getChangingPathElements if ($file->isDir()) { $this->collect($file->getPathname(), $depth + 1); } } } else { // create regex to match only created backup files $fileRegex = Str::datePlaceholdersToRegex($this->target->getFilenameRaw()); if ($this->target->shouldBeCompressed()) { $fileRegex .= '.' . $this->target->getCompressor()->getSuffix(); } /** @var \SplFileInfo $file */ foreach ($dItter as $i => $file) { if ($file->isDir()) { continue; } // skip currently created backup if ($file->getPathname() == $this->target->getPathname()) { continue; } if (preg_match('#' . $fileRegex . '#i', $file->getFilename())) { $index = date('YmdHis', $file->getMTime()) . '-' . $i . '-' . $file->getPathname(); $this->files[$index] = new File($file->getFileInfo()); } } } }