-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
EntityNode.php
57 lines (42 loc) 路 1.04 KB
/
EntityNode.php
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
<?php
/**
* This file is part of the Nette Framework (https://nette.org)
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/
declare(strict_types=1);
namespace Nette\Neon\Node;
use Nette\Neon\Entity;
use Nette\Neon\Node;
/** @internal */
final class EntityNode extends Node
{
/** @var Node */
public $value;
/** @var ArrayItemNode[] */
public $attributes = [];
public function __construct(Node $value, array $attributes, int $startPos = null, int $endPos = null)
{
$this->value = $value;
$this->attributes = $attributes;
$this->startPos = $startPos;
$this->endPos = $endPos ?? $startPos;
}
public function toValue(): Entity
{
return new Entity(
$this->value->toValue(),
ArrayItemNode::itemsToArray($this->attributes)
);
}
public function toString(): string
{
return $this->value->toString()
. '('
. ($this->attributes ? ArrayItemNode::itemsToInlineString($this->attributes) : '')
. ')';
}
public function getSubNodes(): array
{
return array_merge([$this->value], $this->attributes);
}
}