46 lines
690 B
PHP
46 lines
690 B
PHP
<?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;
|
|
}
|
|
} |