1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dallgoot\Yaml\Nodes; |
4
|
|
|
|
5
|
|
|
use Dallgoot\Yaml\NodeFactory; |
6
|
|
|
use Dallgoot\Yaml\Regex; |
7
|
|
|
use Dallgoot\Yaml\Nodes\Generic\NodeGeneric; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* |
11
|
|
|
* @author Stéphane Rebai <[email protected]> |
12
|
|
|
* @license Apache 2.0 |
13
|
|
|
* @link https://github.com/dallgoot/yaml |
14
|
|
|
*/ |
15
|
|
|
class DocStart extends NodeGeneric |
16
|
|
|
{ |
17
|
5 |
|
public function __construct(string $nodeString, ?int $line) |
18
|
|
|
{ |
19
|
5 |
|
parent::__construct($nodeString, $line); |
20
|
5 |
|
$rest = substr(ltrim($nodeString), 3); |
21
|
5 |
|
if (!empty($rest)) { |
22
|
1 |
|
$n = NodeFactory::get($rest, (int) $line); |
23
|
1 |
|
$n->indent = null; |
24
|
1 |
|
$this->add($n); |
25
|
|
|
} |
26
|
|
|
} |
27
|
|
|
|
28
|
3 |
|
public function add(NodeGeneric $child): NodeGeneric |
29
|
|
|
{ |
30
|
3 |
|
if ($this->value instanceof NodeGeneric) { |
31
|
1 |
|
return $this->value->add($child); |
32
|
|
|
} else { |
33
|
3 |
|
return parent::add($child); |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
|
37
|
1 |
|
public function build(&$parent = null) |
38
|
|
|
{ |
39
|
1 |
|
if (is_null($parent)) { |
40
|
|
|
throw new \Exception(__METHOD__ . " expects a YamlObject as parent", 1); |
41
|
|
|
} |
42
|
1 |
|
if (!is_null($this->value)) { |
43
|
1 |
|
if ($this->value instanceof Tag) { |
44
|
1 |
|
preg_match(Regex::TAG_PARTS, $this->value->raw, $tagparts); |
45
|
1 |
|
if (preg_match("/(?(DEFINE)" . Regex::TAG_URI . ')(?&url)/', $tagparts['tagname'], $matches)) { |
46
|
1 |
|
$parent->addTag($tagparts['handle'], $tagparts['tagname']); |
47
|
|
|
} else { |
48
|
1 |
|
$this->value->build($parent); |
49
|
|
|
} |
50
|
|
|
} else { |
51
|
1 |
|
$text = $this->value->build($parent); |
52
|
1 |
|
!is_null($text) && $parent->setText($text); |
53
|
|
|
} |
54
|
|
|
} |
55
|
1 |
|
return null; |
56
|
|
|
} |
57
|
|
|
|
58
|
1 |
|
public function isAwaitingChild(NodeGeneric $node): bool |
59
|
|
|
{ |
60
|
1 |
|
return $this->value instanceof NodeGeneric && $this->value->isOneOf('Anchor', 'Literal', 'LiteralFolded'); |
61
|
|
|
} |
62
|
|
|
|
63
|
1 |
|
public function getTargetOnEqualIndent(NodeGeneric &$node): NodeGeneric |
64
|
|
|
{ |
65
|
1 |
|
if ($this->value instanceof NodeGeneric) { |
66
|
1 |
|
if ($this->value instanceof Tag) { |
67
|
|
|
if (!preg_match("/" . Regex::TAG_URI . "/", $this->value->raw)) { |
68
|
|
|
return $this->value; |
69
|
|
|
} |
70
|
1 |
|
} elseif ($this->value->isAwaitingChild($node)) { |
71
|
1 |
|
return $this->value; |
72
|
|
|
} |
73
|
|
|
} |
74
|
1 |
|
return $this->getParent(); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|