public function get(AggregateType $aggregateType, $aggregateId)
    {
        $queryBuilder = $this->connection->createQueryBuilder();
        $table = $this->getTable($aggregateType);
        $queryBuilder
            ->select('*')
            ->from($table, $table)
            ->where('aggregate_type = :aggregate_type')
            ->andWhere('aggregate_id = :aggregate_id')
            ->orderBy('last_version', 'DESC')
            ->setParameter('aggregate_type', $aggregateType->toString())
            ->setParameter('aggregate_id', $aggregateId)
            ->setMaxResults(1);

        $stmt = $queryBuilder->execute();

        $result = $stmt->fetch(\PDO::FETCH_ASSOC);

        if (!$result) {
            return;
        }

        return new Snapshot(
            $aggregateType,
            $aggregateId,
            $this->unserializeAggregateRoot($result['aggregate_root']),
            (int) $result['last_version'],
            \DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.u', $result['created_at'], new \DateTimeZone('UTC'))
        );
    }
public function get(AggregateType $aggregateType, $aggregateId)
    {
        $queryBuilder = $this->connection->createQueryBuilder();
        $table = $this->getTable($aggregateType);
        $queryBuilder
            ->select('*')
            ->from($table, $table)
            ->where('aggregate_type = :aggregate_type')
            ->andWhere('aggregate_id = :aggregate_id')
            ->orderBy('last_version', 'DESC')
            ->setParameter('aggregate_type', $aggregateType->toString())
            ->setParameter('aggregate_id', $aggregateId)
            ->setMaxResults(1);

        $stmt = $queryBuilder->execute();

        $result = $stmt->fetch(\PDO::FETCH_ASSOC);

        if (!$result) {
            return;
        }

        return new Snapshot(
            $aggregateType,
            $aggregateId,
            $this->unserializeAggregateRoot($result['aggregate_root']),
            (int) $result['last_version'],
            \DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.u', $result['created_at'], new \DateTimeZone('UTC'))
        );
    }
public function get ( AggregateType $ aggregateType , $ aggregateId ) { $ queryBuilder = $ this -> connection -> createQueryBuilder ( ) ; $ table = $ this -> getTable ( $ aggregateType ) ; $ queryBuilder -> select ( '*' ) -> from ( $ table , $ table ) -> where ( 'aggregate_type = :aggregate_type' ) -> andWhere ( 'aggregate_id = :aggregate_id' ) -> orderBy ( 'last_version' , 'DESC' ) -> setParameter ( 'aggregate_type' , $ aggregateType -> toString ( ) ) -> setParameter ( 'aggregate_id' , $ aggregateId ) -> setMaxResults ( 1 ) ; $ stmt = $ queryBuilder -> execute ( ) ; $ result = $ stmt -> fetch ( \ PDO :: FETCH_ASSOC ) ; if ( ! $ result ) { return ; } return new Snapshot ( $ aggregateType , $ aggregateId , $ this -> unserializeAggregateRoot ( $ result [ 'aggregate_root' ] ) , ( int ) $ result [ 'last_version' ] , \ DateTimeImmutable :: createFromFormat ( 'Y-m-d\TH:i:s.u' , $ result [ 'created_at' ] , new \ DateTimeZone ( 'UTC' ) ) ) ; }
Get the aggregate root if it exists otherwise null

@param AggregateType $aggregateType
@param string $aggregateId
@return Snapshot
Get the aggregate root if it exists otherwise null