-
-
Notifications
You must be signed in to change notification settings - Fork 223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
9.0 Discuss Node.nodeName
#4311
Comments
Node.nodeName
not nullableNode.nodeName
not nullable
Okay we discussed a lot of points regarding the nodeName, but we agreed to keep the behavior as is for now. I would like to close this, but maybe first further elaborate why we wont make it nullable? (i dont have all the points in my head anymore ^^) |
Also related: #4313 (comment) Where i wrote down that there is currently no future in sight were we totally get rid of the node name. |
Node.nodeName
not nullableNode.nodeName
Thanks for all the discussions and documentations. I'll close this one for now, we have the comments for reference |
I think i had this idea a few times to attach the tethered node name to the Currently code like the following doesnt look that nice due to the outside made invariant check: if ($childNode->classification->isTethered()) {
assert($childNode->name !== null); // it's tethered!
$actualTetheredChildNodes[$childNode->name->value] = $childNode;
} And phpstan doesnt support yet this invariant:
So i thought why not turn the final class NodeAggregateClassification implements \JsonSerializable
{
const CLASSIFICATION_REGULAR = 'regular';
const CLASSIFICATION_ROOT = 'root';
const CLASSIFICATION_TETHERED = 'tethered';
/** @var array<string, self> */
private static array $instances;
private function __construct(
public readonly string $value,
public readonly ?NodeName $tetheredNodeName = null
) {
}
public static function from(string $value, ...?): self
{
return $instances[$value] ??= match ($value) {
self::CLASSIFICATION_ROOT => self::CLASSIFICATION_ROOT(),
self::CLASSIFICATION_REGULAR => self::CLASSIFICATION_REGULAR(),
self::CLASSIFICATION_TETHERED => self::CLASSIFICATION_TETHERED($nodeName ... ????),
default => throw new \InvalidArgumentException('Invalid node aggregate classification "' . $value . '", must be one of the defined constants.', 1719739959),
};
}
public static function CLASSIFICATION_ROOT(): self
{
return new self(self::CLASSIFICATION_ROOT);
}
public static function CLASSIFICATION_REGULAR(): self
{
return new self(self::CLASSIFICATION_REGULAR);
}
public static function CLASSIFICATION_TETHERED($nodeName ???): self
{
return new self(self::CLASSIFICATION_TETHERED, $nodeName );
}
public function isRoot(): bool
{
return $this->value === self::CLASSIFICATION_ROOT;
}
public function isRegular(): bool
{
return $this->value === self::CLASSIFICATION_REGULAR;
}
public function isTethered(): bool
{
return $this->value === self::CLASSIFICATION_TETHERED;
}
public function getValue(): string
{
return $this->value;
}
public function equals(self $other): bool
{
return $this->value === $other->value;
}
} That seems as long fun until you have to think about if a classification In the end i came to the conclusion that this behaviour is best kept part of the node. And maybe - as there is a feature request for this: phpstan/phpstan#10463 - we will get phpstan support some point. in the meantime the compromise is that we just document it inline and assert the correct behaviour see #4469 |
Currently Node::nodeName is nullable because nodes don't require an explicit name.
This is error prone because it can lead to invalid node paths (see https://neos-project.slack.com/archives/C3MCBK6S2/p1685647511878619).
I would suggest to make the name default to the node aggregate id (and to rename the field to just "name" while we're at it):
The text was updated successfully, but these errors were encountered: