1 | <?php |
||
14 | class ReplaceShortcodesEvent |
||
15 | { |
||
16 | /** @var ShortcodeInterface|null */ |
||
17 | private $shortcode; |
||
18 | /** @var string */ |
||
19 | private $text; |
||
20 | /** @var ReplacedShortcode[] */ |
||
21 | private $replacements = array(); |
||
22 | /** @var string|null */ |
||
23 | private $result; |
||
24 | |||
25 | /** |
||
26 | * @param string $text |
||
27 | * @param ReplacedShortcode[] $replacements |
||
28 | */ |
||
29 | 57 | public function __construct($text, array $replacements, ShortcodeInterface $shortcode = null) |
|
30 | { |
||
31 | 57 | $this->shortcode = $shortcode; |
|
32 | 57 | $this->text = $text; |
|
33 | |||
34 | 57 | $this->setReplacements($replacements); |
|
35 | 57 | } |
|
36 | |||
37 | /** |
||
38 | * @param ReplacedShortcode[] $replacements |
||
39 | * |
||
40 | * @return void |
||
41 | */ |
||
42 | 57 | private function setReplacements(array $replacements) |
|
43 | { |
||
44 | 57 | foreach($replacements as $replacement) { |
|
45 | 57 | $this->addReplacement($replacement); |
|
46 | 57 | } |
|
47 | 57 | } |
|
48 | |||
49 | /** @return void */ |
||
50 | 57 | private function addReplacement(ReplacedShortcode $replacement) |
|
51 | { |
||
52 | 57 | $this->replacements[] = $replacement; |
|
53 | 57 | } |
|
54 | |||
55 | /** @return string */ |
||
56 | 1 | public function getText() |
|
60 | |||
61 | /** @return ReplacedShortcode[] */ |
||
62 | 2 | public function getReplacements() |
|
66 | |||
67 | /** @return ShortcodeInterface|null */ |
||
68 | 1 | public function getShortcode() |
|
72 | |||
73 | /** |
||
74 | * @param string $result |
||
75 | * |
||
76 | * @return void |
||
77 | */ |
||
78 | 2 | public function setResult($result) |
|
82 | |||
83 | /** @return string|null */ |
||
84 | 2 | public function getResult() |
|
88 | |||
89 | /** @return bool */ |
||
90 | 57 | public function hasResult() |
|
94 | } |
||
95 |