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
|
|
|
* @todo implement Indentation indicator 8.1.1 |
11
|
|
|
*/ |
12
|
|
|
abstract class NodeLiterals extends Node |
13
|
|
|
{ |
14
|
|
|
/** @var NodeList */ |
15
|
|
|
public $value; |
16
|
|
|
abstract protected function getFinalString(NodeList $list, int $refIndent = null):string; |
17
|
|
|
|
18
|
|
|
public function __construct(string $nodeString, int $line) |
19
|
|
|
{ |
20
|
|
|
parent::__construct($nodeString, $line); |
21
|
|
|
if (isset($nodeString[1]) && in_array($nodeString[1], ['-', '+'])) { |
22
|
|
|
$this->identifier = $nodeString[1]; |
23
|
|
|
} |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function add(Node $child):Node |
27
|
|
|
{ |
28
|
|
|
if (is_null($this->value)) $this->value = new NodeList(); |
29
|
|
|
$candidate = $child; |
30
|
|
|
if (!isOneOf($child, ['NodeScalar', 'NodeBlank', 'NodeComment', 'NodeQuoted'])) { |
31
|
|
|
$candidate = new NodeScalar((string) $child->raw, $child->line); |
32
|
|
|
} |
33
|
|
|
return parent::add($candidate); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
protected static function litteralStripLeading(NodeList &$list) |
37
|
|
|
{ |
38
|
|
|
$list->rewind(); |
39
|
|
|
while ($list->bottom() instanceof NodeBlank) {//remove leading blank |
40
|
|
|
$list->shift(); |
41
|
|
|
$list->rewind(); |
42
|
|
|
} |
43
|
|
|
$list->rewind(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
protected static function litteralStripTrailing(NodeList &$list) |
47
|
|
|
{ |
48
|
|
|
$list->rewind(); |
49
|
|
|
while ($list->top() instanceof NodeBlank) {//remove trailing blank |
50
|
|
|
$list->pop(); |
51
|
|
|
} |
52
|
|
|
$list->rewind(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Builds a litteral (folded or not) |
57
|
|
|
* As per Documentation : 8.1.1.2. Block Chomping Indicator |
58
|
|
|
* Chomping controls how final line breaks and trailing empty lines are interpreted. |
59
|
|
|
* YAML provides three chomping methods: |
60
|
|
|
* Clip (default behavior) : FINAL_LINE_BREAK, NO TRAILING EMPTY LINES |
61
|
|
|
* Strip (“-” chomping indicator) NO FINAL_LINE_BREAK, NO TRAILING EMPTY LINES |
62
|
|
|
* Keep (“+” chomping indicator) FINAL_LINE_BREAK && TRAILING EMPTY LINES |
63
|
|
|
*/ |
64
|
|
|
public function build(&$parent = null) |
65
|
|
|
{ |
66
|
|
|
$result = ''; |
67
|
|
|
if (!is_null($this->_tag)) { |
68
|
|
|
return TagFactory::transform($this->_tag, $this->value)->build($parent); |
69
|
|
|
} |
70
|
|
|
if (!is_null($this->value)) { |
71
|
|
|
$tmp = $this->getFinalString($this->value->filterComment()); |
72
|
|
|
$result = $this->identifier === '-' ? $tmp : $tmp."\n"; |
73
|
|
|
} |
74
|
|
|
if ($this->_parent instanceof NodeRoot) { |
75
|
|
|
$this->getRoot()->getYamlObject()->setText($result); |
|
|
|
|
76
|
|
|
} else { |
77
|
|
|
return $result; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
protected function getChildValue(Node $child, int $refIndent):string |
82
|
|
|
{ |
83
|
|
|
$value = $child->value; |
84
|
|
|
if (is_null($value)) { |
85
|
|
|
return $child instanceof NodeQuoted ? $child->build() : ltrim($child->raw); |
86
|
|
|
} else { |
87
|
|
|
if ($value instanceof Node) { |
88
|
|
|
$value = new NodeList($value); |
89
|
|
|
} |
90
|
|
|
$start = ''; |
91
|
|
|
if ($child instanceof NodeKey || $child instanceof NodeItem) { |
92
|
|
|
$start = ltrim($child->raw)."\n"; |
93
|
|
|
} |
94
|
|
|
return $start.$this->getFinalString($value, $refIndent); |
95
|
|
|
} |
96
|
|
|
return ''; |
|
|
|
|
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function isAwaitingChild(Node $node):bool |
100
|
|
|
{ |
101
|
|
|
return true; |
102
|
|
|
} |
103
|
|
|
} |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.