Skip to content

Instantly share code, notes, and snippets.

@fritz-gerneth
Created February 5, 2019 17:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fritz-gerneth/64ab31cbea25b2f99268b166ba8dfa33 to your computer and use it in GitHub Desktop.
Save fritz-gerneth/64ab31cbea25b2f99268b166ba8dfa33 to your computer and use it in GitHub Desktop.
<?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