-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathNodeMutatorCollection.php
More file actions
58 lines (48 loc) · 1.29 KB
/
NodeMutatorCollection.php
File metadata and controls
58 lines (48 loc) · 1.29 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
<?php
declare(strict_types=1);
namespace Flowpack\NodeTemplates\Domain\NodeCreation;
use Neos\ContentRepository\Domain\Model\NodeInterface;
use Neos\Flow\Annotations as Flow;
/**
* Collection of {@see NodeMutator}
*
* To apply the mutators: {@see self::executeWithStartingNode()}
*
* @Flow\Proxy(false)
*/
class NodeMutatorCollection
{
private array $items;
private function __construct(
NodeMutator ...$items
) {
$this->items = $items;
}
public static function from(NodeMutator ...$items): self
{
return new self(...$items);
}
public static function createEmpty(): self
{
return new self();
}
public function append(NodeMutator ...$items): self
{
return new self(...$this->items, ...$items);
}
public function merge(self $other): self
{
return new self(...$this->items, ...$other->items);
}
/**
* Applies all child operations on the initial node pointer
*
* @param NodeInterface $nodePointer being the current node for the first operation
*/
public function executeWithStartingNode(NodeInterface $nodePointer): void
{
foreach ($this->items as $mutator) {
$nodePointer = $mutator->executeWithNodePointer($nodePointer);
}
}
}