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