ringfinger/backend/classes/database/SharingCollection.php

46 lines
690 B
PHP
Raw Permalink Normal View History

2020-09-09 21:35:11 +02:00
<?php
declare(strict_types=1);
final class SharingCollection implements Iterator, JsonSerializable
{
private int $position = 0;
/** @var Sharing[] */
private array $sharings = [];
public function add(Sharing $userId): void
{
$this->sharings[] = $userId;
}
public function current(): Sharing
{
return $this->sharings[$this->position];
}
public function next(): void
{
$this->position++;
}
public function key(): int
{
return $this->position;
}
public function valid(): bool
{
return isset($this->sharings[$this->position]);
}
public function rewind(): void
{
$this->position = 0;
}
public function jsonSerialize()
{
return $this->sharings;
}
}