-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathProcessedShortcode.php
More file actions
163 lines (140 loc) · 3.61 KB
/
Copy pathProcessedShortcode.php
File metadata and controls
163 lines (140 loc) · 3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
namespace Thunder\Shortcode\Shortcode;
use Thunder\Shortcode\Processor\ProcessorContext;
use Thunder\Shortcode\Processor\ProcessorInterface;
/**
* @author Tomasz Kowalczyk <[email protected]>
*/
final class ProcessedShortcode extends AbstractShortcode implements ParsedShortcodeInterface
{
/** @var ProcessedShortcode|null */
private $parent;
/** @var int */
private $position;
/** @var int */
private $namePosition;
/** @var string */
private $text;
/** @var string */
private $textContent;
/** @var int */
private $offset;
/** @var int */
private $baseOffset;
/** @var string */
private $shortcodeText;
/** @var int */
private $iterationNumber;
/** @var int */
private $recursionLevel;
/** @var ProcessorInterface */
private $processor;
private function __construct(ProcessorContext $context)
{
// basic properties
$this->name = $context->shortcode->getName();
$this->parameters = $context->shortcode->getParameters();
$this->content = $context->shortcode->getContent();
$this->bbCode = $context->shortcode->getBbCode();
$this->textContent = $context->textContent;
// runtime context
$this->parent = $context->parent;
$this->position = $context->position;
$this->namePosition = $context->namePosition[$this->name];
$this->text = $context->text;
$this->shortcodeText = $context->shortcodeText;
// processor state
$this->iterationNumber = $context->iterationNumber;
$this->recursionLevel = $context->recursionLevel;
$this->processor = $context->processor;
// text context
$this->offset = $context->offset;
$this->baseOffset = $context->baseOffset;
}
/** @return self */
public static function createFromContext(ProcessorContext $context)
{
return new self($context);
}
/**
* @param string|null $content
*
* @return self
*/
public function withContent($content)
{
$self = clone $this;
$self->content = $content;
return $self;
}
/**
* @param string $name
*
* @return bool
*/
public function hasAncestor($name)
{
$self = $this;
while($self = $self->getParent()) {
if($self->getName() === $name) {
return true;
}
}
return false;
}
/** @return ProcessedShortcode|null */
public function getParent()
{
return $this->parent;
}
/** @return string */
public function getTextContent()
{
return $this->textContent;
}
/** @return int */
public function getPosition()
{
return $this->position;
}
/** @return int */
public function getNamePosition()
{
return $this->namePosition;
}
/** @return string */
public function getText()
{
return $this->text;
}
/** @return string */
public function getShortcodeText()
{
return $this->shortcodeText;
}
/** @return int */
public function getOffset()
{
return $this->offset;
}
/** @return int */
public function getBaseOffset()
{
return $this->baseOffset;
}
/** @return int */
public function getIterationNumber()
{
return $this->iterationNumber;
}
/** @return int */
public function getRecursionLevel()
{
return $this->recursionLevel;
}
/** @return ProcessorInterface */
public function getProcessor()
{
return $this->processor;
}
}