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\Collection\ArrayList; |
17
|
|
|
use Seboettg\Collection\ArrayList\ArrayListInterface; |
18
|
|
|
|
19
|
|
|
trait RenderingObserverTrait |
20
|
|
|
{ |
21
|
|
|
/** @var RenderingMode */ |
22
|
|
|
private $mode; |
23
|
|
|
|
24
|
|
|
/** @var ArrayListInterface */ |
25
|
|
|
private $citationItems; |
26
|
|
|
|
27
|
|
|
/** @var RenderingState */ |
28
|
|
|
private $state; |
29
|
|
|
|
30
|
|
|
/** @var Context */ |
31
|
|
|
private $context; |
32
|
|
|
|
33
|
177 |
|
public function initObserver(): void |
34
|
|
|
{ |
35
|
177 |
|
$this->mode = RenderingMode::BIBLIOGRAPHY(); |
36
|
177 |
|
$this->state = RenderingState::RENDERING(); |
37
|
177 |
|
$this->citationItems = new ArrayList(); |
38
|
177 |
|
} |
39
|
|
|
|
40
|
169 |
|
public function notify(RenderingEvent $event): void |
41
|
|
|
{ |
42
|
169 |
|
if ($event instanceof ModeChangedEvent) { |
43
|
169 |
|
$this->mode = $event->getMode(); |
44
|
|
|
} |
45
|
169 |
|
if ($event instanceof CitationItemsChangedEvent) { |
46
|
103 |
|
$this->citationItems = $event->getCitationItems(); |
47
|
|
|
} |
48
|
169 |
|
if ($event instanceof StateChangedEvent) { |
49
|
60 |
|
$this->state = $event->getRenderingState(); |
50
|
|
|
} |
51
|
169 |
|
} |
52
|
|
|
|
53
|
60 |
|
public function notifyAll(RenderingEvent $event): void |
54
|
|
|
{ |
55
|
60 |
|
$this->context->notifyObservers($event); |
56
|
60 |
|
} |
57
|
|
|
|
58
|
177 |
|
public function setContext(Context $context): void |
59
|
|
|
{ |
60
|
177 |
|
$this->context = $context; |
61
|
177 |
|
} |
62
|
|
|
} |
63
|
|
|
|