-
Notifications
You must be signed in to change notification settings - Fork 5
/
BoardProjector.php
88 lines (79 loc) · 2.36 KB
/
BoardProjector.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
/**
* This file is part of list-maker.
* (c) Renan Taranto <renantaranto@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Taranto\ListMaker\Board\Infrastructure\Persistence\Projection;
use MongoDB\Collection;
use Taranto\ListMaker\Board\Domain\Event\BoardClosed;
use Taranto\ListMaker\Board\Domain\Event\BoardCreated;
use Taranto\ListMaker\Board\Domain\Event\BoardReopened;
use Taranto\ListMaker\Board\Domain\Event\BoardTitleChanged;
use Taranto\ListMaker\Shared\Infrastructure\Persistence\Projection\Projector;
/**
* Class BoardProjector
* @package Taranto\ListMaker\Board\Infrastructure\Persistence\Projection
* @author Renan Taranto <renantaranto@gmail.com>
*/
final class BoardProjector extends Projector
{
/**
* @var Collection
*/
private $boardsCollection;
/**
* BoardProjector constructor.
* @param Collection $boardsCollection
*/
public function __construct(Collection $boardsCollection)
{
$this->boardsCollection = $boardsCollection;
}
/**
* @param BoardCreated $event
*/
protected function projectBoardCreated(BoardCreated $event): void
{
$this->boardsCollection->insertOne([
'id' => (string) $event->aggregateId(),
'title' => (string) $event->title(),
'open' => true,
'lists' => [],
'archivedLists' => []
]);
}
/**
* @param BoardTitleChanged $event
*/
protected function projectBoardTitleChanged(BoardTitleChanged $event): void
{
$this->boardsCollection->updateOne(
['id' => (string) $event->aggregateId()],
['$set' => ['title' => (string) $event->title()]]
);
}
/**
* @param BoardClosed $event
*/
protected function projectBoardClosed(BoardClosed $event): void
{
$this->boardsCollection->updateOne(
['id' => (string) $event->aggregateId()],
['$set' => ['open' => false]]
);
}
/**
* @param BoardReopened $event
*/
protected function projectBoardReopened(BoardReopened $event): void
{
$this->boardsCollection->updateOne(
['id' => (string) $event->aggregateId()],
['$set' => ['open' => true]]
);
}
}