1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/* |
4
|
|
|
* citeproc-php |
5
|
|
|
* |
6
|
|
|
* @link http://github.com/seboettg/citeproc-php for the source repository |
7
|
|
|
* @copyright Copyright (c) 2020 Sebastian Böttger. |
8
|
|
|
* @license https://opensource.org/licenses/MIT |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Seboettg\CiteProc\Rendering\Observer; |
12
|
|
|
|
13
|
|
|
use Seboettg\CiteProc\Config\RenderingMode; |
14
|
|
|
use Seboettg\CiteProc\Config\RenderingState; |
15
|
|
|
use Seboettg\CiteProc\Context; |
16
|
|
|
use Seboettg\CiteProc\Data\DataList; |
17
|
|
|
use Seboettg\Collection\ArrayList; |
18
|
|
|
use Seboettg\Collection\ArrayList\ArrayListInterface; |
19
|
|
|
|
20
|
|
|
trait RenderingObserverTrait |
21
|
|
|
{ |
22
|
|
|
/** @var RenderingMode */ |
23
|
|
|
private $mode; |
24
|
|
|
|
25
|
|
|
/** @var ArrayListInterface */ |
26
|
|
|
private $citationItems; |
27
|
|
|
|
28
|
|
|
/** @var RenderingState */ |
29
|
|
|
private $state; |
30
|
|
|
|
31
|
|
|
/** @var DataList */ |
32
|
|
|
private $citationData; |
33
|
|
|
|
34
|
|
|
/** @var ArrayListInterface */ |
35
|
|
|
private $citedItems; |
36
|
|
|
|
37
|
|
|
/** @var Context */ |
38
|
|
|
private $context; |
39
|
|
|
|
40
|
177 |
|
public function initObserver(): void |
41
|
|
|
{ |
42
|
177 |
|
$this->mode = RenderingMode::BIBLIOGRAPHY(); |
43
|
177 |
|
$this->state = RenderingState::RENDERING(); |
44
|
177 |
|
$this->citationItems = new ArrayList(); |
45
|
177 |
|
$this->citationData = new DataList(); |
46
|
177 |
|
$this->citationItems = new ArrayList(); |
47
|
177 |
|
$this->citedItems = new ArrayList(); |
48
|
177 |
|
} |
49
|
|
|
|
50
|
169 |
|
public function notify(RenderingEvent $event): void |
51
|
|
|
{ |
52
|
169 |
|
if ($event instanceof ModeChangedEvent) { |
53
|
169 |
|
$this->mode = $event->getMode(); |
54
|
|
|
} |
55
|
169 |
|
if ($event instanceof CitationItemsChangedEvent) { |
56
|
138 |
|
$this->citationItems = $event->getCitationItems(); |
57
|
|
|
} |
58
|
169 |
|
if ($event instanceof StateChangedEvent) { |
59
|
60 |
|
$this->state = $event->getRenderingState(); |
60
|
|
|
} |
61
|
169 |
|
if ($event instanceof CitationDataChangedEvent) { |
62
|
169 |
|
$this->citationData = $event->getCitationData(); |
63
|
|
|
} |
64
|
169 |
|
if ($event instanceof CitedItemsChangedEvent) { |
65
|
103 |
|
$this->citedItems = $event->getCitedItems(); |
66
|
|
|
} |
67
|
169 |
|
} |
68
|
|
|
|
69
|
177 |
|
public function setContext(Context $context): void |
70
|
|
|
{ |
71
|
177 |
|
$this->context = $context; |
72
|
177 |
|
} |
73
|
|
|
|
74
|
169 |
|
public function notifyAll(RenderingEvent $event): void |
75
|
|
|
{ |
76
|
169 |
|
$this->context->notifyObservers($event); |
77
|
169 |
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param RenderingState $state |
81
|
|
|
*/ |
82
|
50 |
|
public function setState(RenderingState $state): void |
83
|
|
|
{ |
84
|
50 |
|
$this->state = $state; |
85
|
50 |
|
$this->notifyAll(new StateChangedEvent($state)); |
86
|
50 |
|
} |
87
|
|
|
|
88
|
169 |
|
protected function setMode(RenderingMode $mode) |
89
|
|
|
{ |
90
|
169 |
|
$this->mode = $mode; |
91
|
169 |
|
$this->notifyAll(new ModeChangedEvent($mode)); |
92
|
169 |
|
} |
93
|
|
|
|
94
|
169 |
|
protected function setCitationData(DataList $citationData) |
95
|
|
|
{ |
96
|
169 |
|
$this->citationData = $citationData; |
97
|
169 |
|
$this->notifyAll(new CitationDataChangedEvent($citationData)); |
98
|
169 |
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param ArrayListInterface $citedItems |
102
|
|
|
*/ |
103
|
|
|
public function setCitedItems(ArrayListInterface $citedItems): void |
104
|
|
|
{ |
105
|
|
|
$this->citedItems = $citedItems; |
106
|
|
|
$this->notifyAll(new CitedItemsChangedEvent($citedItems)); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @param ArrayListInterface $citationItems |
111
|
|
|
*/ |
112
|
138 |
|
public function setCitationItems(ArrayListInterface $citationItems): void |
113
|
|
|
{ |
114
|
138 |
|
$this->citationItems = $citationItems; |
115
|
138 |
|
$this->notifyAll(new CitationItemsChangedEvent($citationItems)); |
116
|
138 |
|
} |
117
|
|
|
} |
118
|
|
|
|