-
-
Save alle/a0a5866b916737b6477d6e7184ce3b33 to your computer and use it in GitHub Desktop.
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 | |
declare(strict_types=1); | |
namespace Funct\Ion\Microsite\Base\ReadModel\MicrositeCollections; | |
use Prooph\EventStore\Projection\AbstractReadModel; | |
use RuntimeException; | |
final class CombinedReadModel extends AbstractReadModel | |
{ | |
/** @var CombinedReadModelInterface[] */ | |
private $readModels; | |
public function __construct(... $readModels) | |
{ | |
foreach ($readModels as $readModel) { | |
if (!$readModel instanceof CombinedReadModelInterface) { | |
throw new RuntimeException('Read model must implement CombinedReadModelInterface'); | |
} | |
} | |
$this->readModels = $readModels; | |
} | |
public function init(): void | |
{ | |
foreach ($this->readModels as $readModel) { | |
if (!$readModel->isInitialized()) { | |
$readModel->init(); | |
} | |
} | |
} | |
public function isInitialized(): bool | |
{ | |
foreach ($this->readModels as $readModel) { | |
if (!$readModel->isInitialized()) { | |
return false; | |
} | |
} | |
return true; | |
} | |
public function reset(): void | |
{ | |
foreach ($this->readModels as $readModel) { | |
$readModel->reset(); | |
} | |
} | |
public function delete(): void | |
{ | |
foreach ($this->readModels as $readModel) { | |
$readModel->delete(); | |
} | |
} | |
public function apply($event): void | |
{ | |
foreach ($this->readModels as $readModel) { | |
$readModel->apply($event); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bruno Wowk @bwowk Feb 05 17:59
Hey there. I was wondering how would you guys go about extending a projector?
I'm using the PdoEventStoreProjector and wish to add a pass over every projected event on multiple projections, mainly to collect some metrics
Are there any built-in extension points, hooks or something like that?
Darryl Hein @darrylhein Feb 05 18:02
Could you run another projection?
Bruno Wowk @bwowk Feb 05 18:07
Could do so for the metrics part, but actually I'd also like to collect some data before running events through my read model so I can add more info to my error handler and make debugging easier during development
I'm using Sentry/Raven, so I'd like to add more context to the errors
Darryl Hein @darrylhein Feb 05 18:08
Seems like creating another class that you extend would be a good option.
Fritz Gerneth @fritz-gerneth Feb 05 18:22
@bwowk the easiest way is probably to write a custom read model that just delegates to a set of read models ( https://gist.github.com/fritz-gerneth/64ab31cbea25b2f99268b166ba8dfa33 ) we're using this in some occassions to keep the individual read models simpler.