AssetIterator: rewrite to standard Iterator interface

This commit is contained in:
2025-05-13 23:29:43 +02:00
parent 9989ba1fa7
commit 4b26c677bb
6 changed files with 75 additions and 87 deletions

View File

@@ -8,11 +8,11 @@
class PhotoMosaic
{
private $descending;
private bool $descending;
private AssetIterator $iterator;
private $layouts;
private $processedImages = 0;
private $queue = [];
private array $layouts;
private int $processedImages = 0;
private array $queue = [];
const IMAGE_MASK_ALL = Image::TYPE_PORTRAIT | Image::TYPE_LANDSCAPE | Image::TYPE_PANORAMA;
const NUM_DAYS_CUTOFF = 7;
@@ -25,11 +25,6 @@ class PhotoMosaic
$this->descending = $iterator->isDescending();
}
public function __destruct()
{
$this->iterator->clean();
}
private function availableLayouts()
{
static $layouts = [
@@ -86,9 +81,14 @@ class PhotoMosaic
}
}
// Check whatever's next up!
while (($asset = $this->iterator->next()) && ($image = $asset->getImage()))
// Check whatever's up next!
// NB: not is not a `foreach` so as to not reset the iterator implicitly
while ($this->iterator->valid())
{
$asset = $this->iterator->current();
$image = $asset->getImage();
$this->iterator->next();
// Give up on the recordset once dates are too far apart
if (isset($refDate) && abs(self::daysApart($image->getDateCaptured(), $refDate)) > self::NUM_DAYS_CUTOFF)
{