-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathEnumeratedNode.php
More file actions
123 lines (104 loc) · 3.7 KB
/
EnumeratedNode.php
File metadata and controls
123 lines (104 loc) · 3.7 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
namespace Flowpack\DecoupledContentStore\NodeEnumeration\Domain\Dto;
use Neos\ContentRepository\Domain\Utility\NodePaths;
use Neos\Flow\Annotations as Flow;
use Neos\ContentRepository\Domain\Model\NodeInterface;
/**
* @Flow\Proxy(false)
*/
final class EnumeratedNode implements \JsonSerializable
{
/**
* We extract the to-be-rendered dimensions and the current site from the context path. Other than that,
* it is used NOT for rendering.
*
* You are NOT ALLOWED to rely on this stored context path as a whole during rendering, because it might have changed because of a move.
*
* @var string
*/
protected $contextPath;
/**
* We identify the node by its identifier
*
* @var string
*/
protected $nodeIdentifier;
/**
* @var array
*/
protected $arguments;
/**
* The node type name
*
* @var string
*/
protected $nodeTypeName;
/**
* The renderer implementation to use for this EnumeratedNode;
* a key from Settings at Flowpack.DecoupledContentStore.extensions.documentRenderers.[key]
*/
public readonly string $rendererId;
private function __construct(string $contextPath, string $nodeIdentifier, string $nodeTypeName, array $arguments, string $rendererId = '')
{
$this->contextPath = $contextPath;
$this->nodeIdentifier = $nodeIdentifier;
$this->nodeTypeName = $nodeTypeName;
$this->arguments = $arguments;
$this->rendererId = $rendererId;
}
static public function fromNode(NodeInterface $node, array $arguments = []): self
{
return new self($node->getContextPath(), $node->getIdentifier(), $node->getNodeType()->getName(), $arguments, '');
}
static public function fromJsonString(string $enumeratedNodeString): self
{
$tmp = json_decode($enumeratedNodeString, true);
if (!is_array($tmp)) {
throw new \Exception('EnumeratedNode cannot be constructed from: ' . $enumeratedNodeString);
}
return new self($tmp['contextPath'], $tmp['nodeIdentifier'], $tmp['nodeTypeName'] ?? '', $tmp['arguments'], $tmp['rendererId']);
}
public function jsonSerialize()
{
return [
'contextPath' => $this->contextPath,
'nodeIdentifier' => $this->nodeIdentifier,
'nodeTypeName' => $this->nodeTypeName,
'arguments' => $this->arguments,
'rendererId' => $this->rendererId,
];
}
public function getSiteNodeNameFromContextPath(): string
{
if (preg_match('#^/sites/([^/@]*)#', $this->contextPath, $matches)) {
return $matches[1];
} else {
throw new \Exception('Could not get site node name from context path "' . $this->contextPath . '"', 1495535171);
}
}
public function getDimensionsFromContextPath(): array
{
$nodePathAndContext = NodePaths::explodeContextPath($this->contextPath);
return $nodePathAndContext['dimensions'];
}
public function getNodeIdentifier(): string
{
return $this->nodeIdentifier;
}
public function getNodeTypeName(): string
{
return $this->nodeTypeName;
}
public function getArguments(): array
{
return $this->arguments;
}
public function debugString(): string
{
return sprintf('%s %s %s(%s) - %s', $this->nodeTypeName, $this->nodeIdentifier, $this->arguments ? http_build_query($this->arguments) . ' ' : '', $this->contextPath, $this->rendererId);
}
public function withRendererId(string $rendererId): self
{
return new self($this->contextPath, $this->nodeIdentifier, $this->nodeTypeName, $this->arguments, $rendererId);
}
}