public function project(Snapshot $fromSnapshot = null) { if ($fromSnapshot instanceof Snapshot && $fromSnapshot->projectorSignature() === $this->signature()) { $this->projection = $fromSnapshot->data(); $this->lastIndex = $fromSnapshot->index(); } $eventSources = []; foreach ($this->streams as $streamId) { $stream = new Stream(Stream\Id::fromString((string) $streamId)); $eventSources = array_merge($eventSources, $this->eventStore->fetchEvents($stream)); } $events = $this->removeProjectedEvents($this->sortEvents($this->filterEventsBasedOnSpecification($eventSources))); // Apply event on projection foreach ($events as $event) { $this->applyEventOnProjection($event); } return $this->projection(); }
<?php use PhpInPractice\EventStore\EventStore; use PhpInPractice\EventStore\Storage\InMemory; use PhpInPractice\EventStore\Stream; use PhpInPractice\EventStore\Stream\Event; require_once __DIR__ . '/../vendor/autoload.php'; $eventStore = new EventStore(new InMemory()); $stream = new Stream(Stream\Id::generate()); $eventStore->persist($stream, [new Event(Event\Id::generate(), new Event\Payload())]); $eventStore->persist($stream, [new Event(Event\Id::generate(), new Event\Payload())]); $events = $eventStore->fetchEvents($stream); var_export($events);