|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Dallgoot\Yaml; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* |
|
7
|
|
|
* @author Stéphane Rebai <[email protected]> |
|
8
|
|
|
* @license Apache 2.0 |
|
9
|
|
|
* @link TODO : url to specific online doc |
|
10
|
|
|
*/ |
|
11
|
|
|
class NodeDocStart extends Node |
|
12
|
|
|
{ |
|
13
|
|
|
public function __construct(string $nodeString, int $line) |
|
14
|
|
|
{ |
|
15
|
|
|
parent::__construct($nodeString, $line); |
|
16
|
|
|
$rest = substr(ltrim($nodeString), 3); |
|
17
|
|
|
if (!empty($rest)) { |
|
18
|
|
|
$n = NodeFactory::get($rest, $line); |
|
19
|
|
|
$n->indent = null; |
|
20
|
|
|
$this->add($n); |
|
21
|
|
|
} |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function add(Node $child):Node |
|
25
|
|
|
{ |
|
26
|
|
|
if ($this->value instanceof Node) { |
|
27
|
|
|
return $this->value->add($child); |
|
28
|
|
|
} else { |
|
29
|
|
|
return parent::add($child); |
|
30
|
|
|
} |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function build(&$parent = null) |
|
34
|
|
|
{ |
|
35
|
|
|
if (is_null($parent)) { |
|
36
|
|
|
throw new Exception(__METHOD__." expects a YamlObject as parent", 1); |
|
|
|
|
|
|
37
|
|
|
} |
|
38
|
|
|
if (is_null($this->value)) { |
|
39
|
|
|
return null; |
|
40
|
|
|
} else { |
|
41
|
|
|
if ($this->value instanceof NodeTag){ |
|
42
|
|
|
$parent->addTag($this->value->_tag); |
|
43
|
|
|
$this->value->build($parent); |
|
44
|
|
|
} else { |
|
45
|
|
|
$text = $this->value->build($parent); |
|
46
|
|
|
!is_null($text) && $parent->setText($text); |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function isAwaitingChild(Node $node):bool |
|
52
|
|
|
{ |
|
53
|
|
|
return $this->value && isOneOf($this->value, ['NodeRefDef', 'NodeLit', 'NodeLitFolded']); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function getTargetOnEqualIndent(Node &$node):Node |
|
57
|
|
|
{ |
|
58
|
|
|
if ($this->value && $this->value->isAwaitingChild($node)) { |
|
|
|
|
|
|
59
|
|
|
return $this->value; |
|
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
return $this->getParent(); |
|
62
|
|
|
} |
|
63
|
|
|
} |