forked from GwendolenLynch/msgphp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectionDocument.php
More file actions
64 lines (50 loc) · 1.42 KB
/
ProjectionDocument.php
File metadata and controls
64 lines (50 loc) · 1.42 KB
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
<?php
declare(strict_types=1);
namespace MsgPhp\Domain\Projection;
/**
* @author Roland Franssen <[email protected]>
*/
final class ProjectionDocument
{
public const STATUS_UNKNOWN = 1;
public const STATUS_SYNCHRONIZED = 2;
public const STATUS_FAILED_TRANSFORMATION = 3;
public const STATUS_FAILED_SAVING = 4;
/** @var int */
public $status = self::STATUS_UNKNOWN;
/** @var object|null */
public $source;
/** @var \Throwable|null $error */
public $error;
private $type;
private $id;
private $body;
public function __construct(string $type = null, string $id = null, array $body = [])
{
$this->type = $type;
$this->id = $id;
$this->body = $body;
}
public function getType(): ?string
{
return $this->type;
}
public function getId(): ?string
{
return $this->id;
}
public function getBody(): array
{
return $this->body;
}
public function toProjection(): ProjectionInterface
{
if (null === $this->type) {
throw new \LogicException('Document type not set.');
}
if (!is_subclass_of($this->type, ProjectionInterface::class)) {
throw new \LogicException(sprintf('Document type must be a sub class of "%s", got "%s".', ProjectionInterface::class, $this->type));
}
return $this->type::fromDocument($this->body);
}
}