ringfinger/backend/classes/database/FingerprintCollection.php

52 lines
867 B
PHP
Raw Permalink Normal View History

<?php
declare(strict_types=1);
final class FingerprintCollection implements Iterator, JsonSerializable
{
private int $position = 0;
/** @var Fingerprint[] */
private array $fingerprints = [];
public function add(Fingerprint $fingerprint): void
{
$this->fingerprints[] = $fingerprint;
}
public function current(): Fingerprint
{
return $this->fingerprints[$this->position];
}
public function next(): void
{
$this->position++;
}
public function key(): int
{
return $this->position;
}
public function valid(): bool
{
return isset($this->fingerprints[$this->position]);
}
public function rewind(): void
{
$this->position = 0;
}
public function jsonSerialize(): array
{
$fingerprints = [];
foreach ($this->fingerprints as $fingerprint) {
$fingerprints[] = $fingerprint->jsonSerialize();
}
return $fingerprints;
}
}