for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* event-sourcing (https://github.com/phpgears/event-sourcing).
* Event Sourcing base.
*
* @license MIT
* @link https://github.com/phpgears/event-sourcing
* @author Julián Gutiérrez <[email protected]>
*/
declare(strict_types=1);
namespace Gears\EventSourcing\Event;
use Gears\EventSourcing\Event\Exception\InvalidAggregateEventException;
final class AggregateEventArrayStream implements AggregateEventStream
{
/**
* @var AggregateEvent[]
private $events = [];
* AggregateEventArrayStream constructor.
* @param (AggregateEvent|mixed)[] $events
* @throws InvalidAggregateEventException
public function __construct(array $events)
foreach ($events as $event) {
if (!$event instanceof AggregateEvent) {
throw new InvalidAggregateEventException(\sprintf(
'Aggregate event stream only accepts %s, %s given',
AggregateEvent::class,
\is_object($event) ? \get_class($event) : \gettype($event)
));
}
$this->events[] = $event;
* {@inheritdoc}
* @return AggregateEvent
public function current(): AggregateEvent
return \current($this->events);
public function next(): void
\next($this->events);
* @return string|int|null
public function key()
return \key($this->events);
public function valid(): bool
return \key($this->events) !== null;
public function rewind(): void
\reset($this->events);