ParseContentExecutor::getContentParser()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * Lichtenwallner  (https://lichtenwallner.at)
4
 *
5
 * @see https://github.com/jolicht/markdown-cms for the canonical source repository
6
 * @license https://github.com/jolicht/markdown-cms/blob/master/LICENSE MIT
7
 * @copyright Copyright (c) Johannes Lichtenwallner
8
 */
9
declare(strict_types = 1);
10
namespace Jolicht\MarkdownCms\Parser;
11
12
use Jolicht\MarkdownCms\Parser\Observer\ParsedContentObserverInterface;
13
14
class ParseContentExecutor
15
{
16
    /**
17
     * Content parser
18
     *
19
     * @var ContentParser
20
     */
21
    private $contentParser;
22
23
    /**
24
     * Observers
25
     *
26
     * @var array
27
     */
28
    private $observers = [];
29
30
    /**
31
     * Constructor
32
     *
33
     * @param ContentParser $contentParser
34
     */
35
    public function __construct(ContentParser $contentParser)
36
    {
37
        $this->contentParser = $contentParser;
38
    }
39
40
    public function __invoke()
41
    {
42
        $config = ($this->getContentParser())();
43
        foreach ($this->getObservers() as $observer) {
44
            $observer($config);
45
        }
46
    }
47
48
    /**
49
     * Get content parser
50
     *
51
     * @return ContentParser
52
     */
53
    public function getContentParser() : ContentParser
54
    {
55
        return $this->contentParser;
56
    }
57
58
    /**
59
     * Get observers
60
     *
61
     * @return array
62
     */
63
    public function getObservers() : array
64
    {
65
        return $this->observers;
66
    }
67
68
    /**
69
     * Add observer
70
     *
71
     * @param ParsedContentObserverInterface $observer
72
     */
73
    public function addObserver(ParsedContentObserverInterface $observer)
74
    {
75
        $this->observers[] = $observer;
76
    }
77
}