Created
February 5, 2019 17:20
-
-
Save fritz-gerneth/64ab31cbea25b2f99268b166ba8dfa33 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