-
-
Notifications
You must be signed in to change notification settings - Fork 220
/
NodeAggregateIdentifier.php
78 lines (65 loc) · 2.09 KB
/
NodeAggregateIdentifier.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/*
* This file is part of the Neos.ContentRepository package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
declare(strict_types=1);
namespace Neos\ContentRepository\Domain\NodeAggregate;
use Neos\Cache\CacheAwareInterface;
use Neos\ContentRepository\Utility;
use Neos\Flow\Utility\Algorithms;
use Neos\Flow\Annotations as Flow;
/**
* The NodeAggregateIdentifier supersedes the Node Identifier from Neos <= 4.x.
*/
#[Flow\Proxy(false)]
final class NodeAggregateIdentifier implements \JsonSerializable, CacheAwareInterface, \Stringable
{
/**
* A preg pattern to match against node aggregate identifiers
*/
const PATTERN = '/^([a-z0-9\-]{1,255})$/';
private function __construct(
private string $value
) {
if (!preg_match(self::PATTERN, $value)) {
throw new \InvalidArgumentException('Invalid node aggregate identifier "' . $value . '" (a node aggregate identifier must only contain lowercase characters, numbers and the "-" sign).', 1505840197862);
}
}
public static function create(): self
{
return new self(Algorithms::generateUUID());
}
public static function fromString(string $value): self
{
return new self($value);
}
/**
* @throws \Exception
*/
public static function forAutoCreatedChildNode(NodeName $childNodeName, NodeAggregateIdentifier $nodeAggregateIdentifier): self
{
return new self(Utility::buildAutoCreatedChildNodeIdentifier((string)$childNodeName, (string)$nodeAggregateIdentifier));
}
public function equals(NodeAggregateIdentifier $other): bool
{
return $this->value === (string)$other;
}
public function jsonSerialize(): string
{
return $this->value;
}
public function __toString(): string
{
return $this->value;
}
public function getCacheEntryIdentifier(): string
{
return $this->value;
}
}