43 lines
836 B
PHP
43 lines
836 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Drupal\opd_presentations;
|
|
|
|
use Webmozart\Assert\Assert;
|
|
|
|
/**
|
|
* @implements \IteratorAggregate<Event>
|
|
*/
|
|
readonly final class Events implements \IteratorAggregate {
|
|
|
|
public function filter(\Closure $callback): self {
|
|
return new self(array_filter(
|
|
array: $this->events,
|
|
callback: $callback,
|
|
));
|
|
}
|
|
|
|
public function first(): Event {
|
|
return array_values($this->events)[0];
|
|
}
|
|
|
|
public function getIterator(): \Traversable {
|
|
return new \ArrayIterator($this->events);
|
|
}
|
|
|
|
/**
|
|
* @param Event[] $events
|
|
*/
|
|
public static function fromEvents(array $events): self {
|
|
return new self($events);
|
|
}
|
|
|
|
/**
|
|
* @param Event[] $events
|
|
*/
|
|
private function __construct(private array $events) {
|
|
Assert::allIsInstanceOf($events, Event::class);
|
|
}
|
|
|
|
}
|