Created
July 20, 2020 08:56
-
-
Save webdevilopers/e2b0d1de9d8f1a0e965b9eedda67d523 to your computer and use it in GitHub Desktop.
Prooph Event Store: Query event stream
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
final class Merger | |
{ | |
// ... | |
private function getInitialEventFromStream(EmploymentContractId $contractId): EmploymentContractSigned | |
{ | |
$query = $this->projectionManager->createQuery(); | |
$query | |
->init(function (): array { | |
return []; | |
}) | |
->fromStream('employment_contract_stream') | |
->when([ | |
EmploymentContractSigned::class => function ( | |
array $state, EmploymentContractSigned $event | |
) use ($contractId): array { | |
if ($event->contractId()->sameValueAs($contractId)) { | |
$state[] = $event; | |
$this->stop(); | |
} | |
return $state; | |
} | |
]) | |
->run(); | |
return $query->getState()[0]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Update fromStream for Projection, Query and ReadModelProjection: