dallgoot /
yaml
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Dallgoot\Yaml\Nodes\Generic; |
||
| 4 | |||
| 5 | use Dallgoot\Yaml\Nodes\Generic\NodeGeneric; |
||
| 6 | use Dallgoot\Yaml\NodeFactory; |
||
| 7 | use Dallgoot\Yaml\Nodes\Tag; |
||
| 8 | |||
| 9 | /** |
||
| 10 | * Common parent to NodeAnchor, NodeTag |
||
| 11 | * Extract identifier (tag or anchor) and attach its value (another Node) |
||
| 12 | * |
||
| 13 | * @author Stéphane Rebai <[email protected]> |
||
| 14 | * @license Apache 2.0 |
||
| 15 | * @link https://github.com/dallgoot/yaml |
||
| 16 | */ |
||
| 17 | abstract class Actions extends NodeGeneric |
||
| 18 | { |
||
| 19 | |||
| 20 | 2 | public function __construct(string $nodeString, int $line) |
|
| 21 | { |
||
| 22 | 2 | parent::__construct($nodeString, $line); |
|
| 23 | 2 | $trimmed = ltrim($nodeString); |
|
| 24 | 2 | $pos = strpos($trimmed, ' '); |
|
| 25 | 2 | $name = $trimmed; |
|
| 26 | 2 | if (is_int($pos)) { |
|
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 27 | 2 | $name = strstr($trimmed, ' ', true); |
|
| 28 | 2 | $value = trim(substr($trimmed, $pos + 1)); |
|
| 29 | 2 | if ($value !== '') { |
|
| 30 | 2 | $child = NodeFactory::get($value, $line); |
|
| 31 | 2 | $child->indent = null; |
|
| 32 | 2 | parent::add($child); |
|
| 33 | } |
||
| 34 | } |
||
| 35 | 2 | if ($this instanceof Tag) { |
|
| 36 | 1 | $this->tag = $name; |
|
| 37 | } else { |
||
| 38 | 2 | $this->anchor = $name; |
|
| 39 | } |
||
| 40 | } |
||
| 41 | } |
||
| 42 |