src/Domain/EventSourcing/EventSourcedAggregateRoot.php
public static function reconstitute(iterable $eventRecords)
    {
        $reflection = new ReflectionClass(static::class);

        /** @var EventSourcedAggregateRoot $aggregate */
        $aggregate = $reflection->newInstanceWithoutConstructor();

        $lastSequence = null;
        /** @var EventRecord $eventRecord */
        foreach ($eventRecords as $eventRecord) {
            $lastSequence = $eventRecord->sequenceNumber();
            /** @var Event $event */
            $event = $eventRecord->eventMessage()->payload();
            $aggregate->handleRecursively($event);
        }

        $aggregate->initializeCommittedVersion($lastSequence);

        return $aggregate;
    }
public static function reconstitute(iterable $eventRecords)
    {
        $reflection = new ReflectionClass(static::class);

        /** @var EventSourcedAggregateRoot $aggregate */
        $aggregate = $reflection->newInstanceWithoutConstructor();

        $lastSequence = null;
        /** @var EventRecord $eventRecord */
        foreach ($eventRecords as $eventRecord) {
            $lastSequence = $eventRecord->sequenceNumber();
            /** @var Event $event */
            $event = $eventRecord->eventMessage()->payload();
            $aggregate->handleRecursively($event);
        }

        $aggregate->initializeCommittedVersion($lastSequence);

        return $aggregate;
    }
public static function reconstitute ( iterable $ eventRecords ) { $ reflection = new ReflectionClass ( static :: class ) ; /** @var EventSourcedAggregateRoot $aggregate */ $ aggregate = $ reflection -> newInstanceWithoutConstructor ( ) ; $ lastSequence = null ; /** @var EventRecord $eventRecord */ foreach ( $ eventRecords as $ eventRecord ) { $ lastSequence = $ eventRecord -> sequenceNumber ( ) ; /** @var Event $event */ $ event = $ eventRecord -> eventMessage ( ) -> payload ( ) ; $ aggregate -> handleRecursively ( $ event ) ; } $ aggregate -> initializeCommittedVersion ( $ lastSequence ) ; return $ aggregate ; }
Creates instance from an event stream history

Override to customize instantiation without using reflection.

@param iterable $eventRecords The event records

@return EventSourcedAggregateRoot
Creates instance from an event stream history