|
1
|
|
|
<?php |
|
2
|
|
|
namespace Thunder\Shortcode\Shortcode; |
|
3
|
|
|
|
|
4
|
|
|
use Thunder\Shortcode\Processor\ProcessorContext; |
|
5
|
|
|
use Thunder\Shortcode\Processor\ProcessorInterface; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* @author Tomasz Kowalczyk <[email protected]> |
|
9
|
|
|
*/ |
|
10
|
|
|
final class ProcessedShortcode extends AbstractShortcode implements ParsedShortcodeInterface |
|
11
|
|
|
{ |
|
12
|
|
|
/** @var ShortcodeInterface */ |
|
13
|
|
|
private $parent; |
|
14
|
|
|
private $position; |
|
15
|
|
|
private $namePosition; |
|
16
|
|
|
private $text; |
|
17
|
|
|
private $textContent; |
|
18
|
|
|
private $offset; |
|
19
|
|
|
private $shortcodeText; |
|
20
|
|
|
private $iterationNumber; |
|
21
|
|
|
private $recursionLevel; |
|
22
|
|
|
/** @var ProcessorInterface */ |
|
23
|
|
|
private $processor; |
|
24
|
|
|
|
|
25
|
38 |
|
private function __construct() |
|
26
|
|
|
{ |
|
27
|
38 |
|
} |
|
28
|
|
|
|
|
29
|
38 |
|
public static function createFromContext(ProcessorContext $context) |
|
30
|
|
|
{ |
|
31
|
38 |
|
$self = new self(); |
|
32
|
|
|
|
|
33
|
|
|
// basic properties |
|
34
|
38 |
|
$self->name = $context->shortcode->getName(); |
|
35
|
38 |
|
$self->parameters = $context->shortcode->getParameters(); |
|
36
|
38 |
|
$self->content = $context->shortcode->getContent(); |
|
37
|
38 |
|
$self->bbCode = $context->shortcode->getBbCode(); |
|
38
|
38 |
|
$self->textContent = $context->textContent; |
|
39
|
|
|
|
|
40
|
|
|
// runtime context |
|
41
|
38 |
|
$self->parent = $context->parent; |
|
42
|
38 |
|
$self->position = $context->position; |
|
43
|
38 |
|
$self->namePosition = $context->namePosition[$self->name]; |
|
44
|
38 |
|
$self->text = $context->text; |
|
45
|
38 |
|
$self->shortcodeText = $context->shortcodeText; |
|
46
|
|
|
|
|
47
|
|
|
// processor state |
|
48
|
38 |
|
$self->iterationNumber = $context->iterationNumber; |
|
49
|
38 |
|
$self->recursionLevel = $context->recursionLevel; |
|
50
|
38 |
|
$self->processor = $context->processor; |
|
51
|
|
|
|
|
52
|
|
|
// text context |
|
53
|
38 |
|
$self->offset = $context->offset; |
|
54
|
|
|
|
|
55
|
38 |
|
return $self; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
36 |
|
public function withContent($content) |
|
59
|
|
|
{ |
|
60
|
36 |
|
$self = clone $this; |
|
61
|
36 |
|
$self->content = $content; |
|
62
|
|
|
|
|
63
|
36 |
|
return $self; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
2 |
|
public function hasAncestor($name) |
|
67
|
|
|
{ |
|
68
|
2 |
|
$self = $this; |
|
69
|
|
|
|
|
70
|
2 |
|
while($self = $self->getParent()) { |
|
71
|
1 |
|
if($self->getName() === $name) { |
|
72
|
1 |
|
return true; |
|
73
|
|
|
} |
|
74
|
1 |
|
} |
|
75
|
|
|
|
|
76
|
2 |
|
return false; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
5 |
|
public function getParent() |
|
80
|
|
|
{ |
|
81
|
5 |
|
return $this->parent; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
2 |
|
public function getTextContent() |
|
85
|
|
|
{ |
|
86
|
2 |
|
return $this->textContent; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
2 |
|
public function getPosition() |
|
90
|
|
|
{ |
|
91
|
2 |
|
return $this->position; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
2 |
|
public function getNamePosition() |
|
95
|
|
|
{ |
|
96
|
2 |
|
return $this->namePosition; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
1 |
|
public function getText() |
|
100
|
|
|
{ |
|
101
|
1 |
|
return $this->text; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
1 |
|
public function getShortcodeText() |
|
105
|
|
|
{ |
|
106
|
1 |
|
return $this->shortcodeText; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
1 |
|
public function getOffset() |
|
110
|
|
|
{ |
|
111
|
1 |
|
return $this->offset; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
1 |
|
public function getIterationNumber() |
|
115
|
|
|
{ |
|
116
|
1 |
|
return $this->iterationNumber; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
1 |
|
public function getRecursionLevel() |
|
120
|
|
|
{ |
|
121
|
1 |
|
return $this->recursionLevel; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
1 |
|
public function getProcessor() |
|
125
|
|
|
{ |
|
126
|
1 |
|
return $this->processor; |
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
|