|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
|
|
4
|
|
|
namespace PersonalGalaxy\RSS\Entity; |
|
5
|
|
|
|
|
6
|
|
|
use PersonalGalaxy\RSS\{ |
|
7
|
|
|
Event\ArticleWasFetched, |
|
8
|
|
|
Event\ArticleWasMarkedAsRead, |
|
9
|
|
|
Entity\Article\Author, |
|
10
|
|
|
Entity\Article\Description, |
|
11
|
|
|
Entity\Article\Title, |
|
12
|
|
|
Entity\Subscription\Identity, |
|
13
|
|
|
Exception\LogicException, |
|
14
|
|
|
}; |
|
15
|
|
|
use Innmind\Url\UrlInterface; |
|
16
|
|
|
use Innmind\EventBus\{ |
|
17
|
|
|
ContainsRecordedEventsInterface, |
|
18
|
|
|
EventRecorder, |
|
19
|
|
|
}; |
|
20
|
|
|
use Innmind\TimeContinuum\PointInTimeInterface; |
|
21
|
|
|
|
|
22
|
|
|
final class Article implements ContainsRecordedEventsInterface |
|
23
|
|
|
{ |
|
24
|
|
|
use EventRecorder; |
|
25
|
|
|
|
|
26
|
|
|
private $link; |
|
27
|
|
|
private $author; |
|
28
|
|
|
private $description; |
|
29
|
|
|
private $title; |
|
30
|
|
|
private $publicationDate; |
|
31
|
|
|
private $subscription; |
|
32
|
|
|
private $read = false; |
|
33
|
|
|
|
|
34
|
7 |
|
private function __construct( |
|
35
|
|
|
UrlInterface $link, |
|
36
|
|
|
Author $author, |
|
37
|
|
|
Description $description, |
|
38
|
|
|
Title $title, |
|
39
|
|
|
PointInTimeInterface $publicationDate |
|
40
|
|
|
) { |
|
41
|
7 |
|
$this->author = $author; |
|
42
|
7 |
|
$this->link = $link; |
|
43
|
7 |
|
$this->description = $description; |
|
44
|
7 |
|
$this->title = $title; |
|
45
|
7 |
|
$this->publicationDate = $publicationDate; |
|
46
|
7 |
|
} |
|
47
|
|
|
|
|
48
|
7 |
|
public static function fetch( |
|
49
|
|
|
UrlInterface $link, |
|
50
|
|
|
Author $author, |
|
51
|
|
|
Description $description, |
|
52
|
|
|
Title $title, |
|
53
|
|
|
PointInTimeInterface $publicationDate |
|
54
|
|
|
): self { |
|
55
|
7 |
|
$self = new self($link, $author, $description, $title, $publicationDate); |
|
56
|
7 |
|
$self->record(new ArticleWasFetched($link, $author, $description, $title, $publicationDate)); |
|
57
|
|
|
|
|
58
|
7 |
|
return $self; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
3 |
|
public function author(): Author |
|
62
|
|
|
{ |
|
63
|
3 |
|
return $this->author; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
4 |
|
public function link(): UrlInterface |
|
67
|
|
|
{ |
|
68
|
4 |
|
return $this->link; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
3 |
|
public function description(): Description |
|
72
|
|
|
{ |
|
73
|
3 |
|
return $this->description; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
3 |
|
public function title(): Title |
|
77
|
|
|
{ |
|
78
|
3 |
|
return $this->title; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
3 |
|
public function publicationDate(): PointInTimeInterface |
|
82
|
|
|
{ |
|
83
|
3 |
|
return $this->publicationDate; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
2 |
|
public function markAsRead(): void |
|
87
|
|
|
{ |
|
88
|
2 |
|
if (!$this->read) { |
|
89
|
2 |
|
$this->read = true; |
|
90
|
2 |
|
$this->record(new ArticleWasMarkedAsRead($this->link)); |
|
91
|
|
|
} |
|
92
|
2 |
|
} |
|
93
|
|
|
|
|
94
|
2 |
|
public function read(): bool |
|
95
|
|
|
{ |
|
96
|
2 |
|
return $this->read; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
2 |
|
public function bindTo(Identity $subscription): void |
|
100
|
|
|
{ |
|
101
|
2 |
|
if ($this->subscription) { |
|
102
|
1 |
|
throw new LogicException; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
2 |
|
$this->subscription = $subscription; |
|
106
|
2 |
|
} |
|
107
|
|
|
|
|
108
|
1 |
|
public function subscription(): Identity |
|
109
|
|
|
{ |
|
110
|
1 |
|
return $this->subscription; |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|