31 lines
681 B
PHP
31 lines
681 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
// SPDX-FileCopyrightText: 2026 Dillard Blom
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
namespace OCA\NgBackup\Backend;
|
|
|
|
/** IBackend::getMany() for a backend where reading files one after the other costs nothing extra. */
|
|
trait GetsOneByOne {
|
|
/**
|
|
* @param list<string> $paths
|
|
* @return \Generator<string, string>
|
|
*/
|
|
public function getMany(array $paths): \Generator {
|
|
foreach ($paths as $path) {
|
|
$fh = $this->get($path);
|
|
try {
|
|
$data = stream_get_contents($fh);
|
|
} finally {
|
|
fclose($fh);
|
|
}
|
|
if ($data === false) {
|
|
throw new BackendException('Read failed for ' . $path);
|
|
}
|
|
yield $path => $data;
|
|
}
|
|
}
|
|
}
|