public function getAggregateRoot(string $aggregateId)
    {
        if (! $this->disableIdentityMap && isset($this->identityMap[$aggregateId])) {
            return $this->identityMap[$aggregateId];
        }

        if ($this->snapshotStore) {
            $eventSourcedAggregateRoot = $this->loadFromSnapshotStore($aggregateId);

            if ($eventSourcedAggregateRoot && ! $this->disableIdentityMap) {
                //Cache aggregate root in the identity map
                $this->identityMap[$aggregateId] = $eventSourcedAggregateRoot;
            }

            return $eventSourcedAggregateRoot;
        }

        $streamName = $this->determineStreamName($aggregateId);

        if ($this->oneStreamPerAggregate) {
            try {
                $streamEvents = $this->eventStore->load($streamName, 1);
            } catch (StreamNotFound $e) {
                return null;
            }
        } else {
            $metadataMatcher = new MetadataMatcher();
            $metadataMatcher = $metadataMatcher->withMetadataMatch(
                '_aggregate_type',
                Operator::EQUALS(),
                $this->aggregateType->toString()
            );
            $metadataMatcher = $metadataMatcher->withMetadataMatch(
                '_aggregate_id',
                Operator::EQUALS(),
                $aggregateId
            );

            try {
                $streamEvents = $this->eventStore->load($streamName, 1, null, $metadataMatcher);
            } catch (StreamNotFound $e) {
                return null;
            }
        }

        if (! $streamEvents->valid()) {
            return null;
        }

        $eventSourcedAggregateRoot = $this->aggregateTranslator->reconstituteAggregateFromHistory(
            $this->aggregateType,
            $streamEvents
        );

        if (! $this->disableIdentityMap) {
            //Cache aggregate root in the identity map but without pending events
            $this->identityMap[$aggregateId] = $eventSourcedAggregateRoot;
        }

        return $eventSourcedAggregateRoot;
    }
public function getAggregateRoot(string $aggregateId)
    {
        if (! $this->disableIdentityMap && isset($this->identityMap[$aggregateId])) {
            return $this->identityMap[$aggregateId];
        }

        if ($this->snapshotStore) {
            $eventSourcedAggregateRoot = $this->loadFromSnapshotStore($aggregateId);

            if ($eventSourcedAggregateRoot && ! $this->disableIdentityMap) {
                //Cache aggregate root in the identity map
                $this->identityMap[$aggregateId] = $eventSourcedAggregateRoot;
            }

            return $eventSourcedAggregateRoot;
        }

        $streamName = $this->determineStreamName($aggregateId);

        if ($this->oneStreamPerAggregate) {
            try {
                $streamEvents = $this->eventStore->load($streamName, 1);
            } catch (StreamNotFound $e) {
                return null;
            }
        } else {
            $metadataMatcher = new MetadataMatcher();
            $metadataMatcher = $metadataMatcher->withMetadataMatch(
                '_aggregate_type',
                Operator::EQUALS(),
                $this->aggregateType->toString()
            );
            $metadataMatcher = $metadataMatcher->withMetadataMatch(
                '_aggregate_id',
                Operator::EQUALS(),
                $aggregateId
            );

            try {
                $streamEvents = $this->eventStore->load($streamName, 1, null, $metadataMatcher);
            } catch (StreamNotFound $e) {
                return null;
            }
        }

        if (! $streamEvents->valid()) {
            return null;
        }

        $eventSourcedAggregateRoot = $this->aggregateTranslator->reconstituteAggregateFromHistory(
            $this->aggregateType,
            $streamEvents
        );

        if (! $this->disableIdentityMap) {
            //Cache aggregate root in the identity map but without pending events
            $this->identityMap[$aggregateId] = $eventSourcedAggregateRoot;
        }

        return $eventSourcedAggregateRoot;
    }
Returns null if no stream events can be found for aggregate root otherwise the reconstituted aggregate root

@return null|object