Skip to content

Commit

Permalink
Merge pull request #4489 from neos/feature/4375-overhaul-command-cons…
Browse files Browse the repository at this point in the history
…tructors

FEATURE: Overhaul command constructors
  • Loading branch information
bwaidelich authored Sep 14, 2023
2 parents 8cb03d5 + 05a9a8c commit 020a0e0
Show file tree
Hide file tree
Showing 75 changed files with 704 additions and 381 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ private function whenRootNodeAggregateWithNodeWasCreated(RootNodeAggregateWithNo
$event->nodeAggregateId,
$originDimensionSpacePoint->coordinates,
$originDimensionSpacePoint->hash,
SerializedPropertyValues::fromArray([]),
SerializedPropertyValues::createEmpty(),
$event->nodeTypeName,
$event->nodeAggregateClassification,
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private function whenRootNodeAggregateWithNodeWasCreated(RootNodeAggregateWithNo
$event->nodeAggregateId,
$originDimensionSpacePoint,
$originDimensionSpacePoint->hash,
SerializedPropertyValues::fromArray([]),
SerializedPropertyValues::createEmpty(),
$event->nodeTypeName,
$event->nodeAggregateClassification,
null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function removeEverything(): void

public function createNodesForPerformanceTest(int $nodesPerLevel, int $levels): void
{
$this->contentRepository->handle(new CreateRootWorkspace(
$this->contentRepository->handle(CreateRootWorkspace::create(
WorkspaceName::forLive(),
WorkspaceTitle::fromString('live'),
WorkspaceDescription::fromString(''),
Expand Down Expand Up @@ -135,7 +135,7 @@ private function createHierarchy(
$this->dimensionSpacePoints,
$parentNodeAggregateId,
null,
SerializedPropertyValues::fromArray([]),
SerializedPropertyValues::createEmpty(),
NodeAggregateClassification::CLASSIFICATION_REGULAR,
);
$sumSoFar++;
Expand All @@ -153,7 +153,7 @@ private function createHierarchy(

public function forkContentStream(): void
{
$this->contentRepository->handle(new ForkContentStream(
$this->contentRepository->handle(ForkContentStream::create(
ContentStreamId::create(),
$this->contentStreamId,
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,19 @@
*/
final class CreateContentStream implements CommandInterface
{
public function __construct(
/**
* @param ContentStreamId $contentStreamId The id of the content stream to create
*/
private function __construct(
public readonly ContentStreamId $contentStreamId,
) {
}

/**
* @param ContentStreamId $contentStreamId The id of the content stream to create
*/
public static function create(ContentStreamId $contentStreamId): self
{
return new self($contentStreamId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

use Neos\ContentRepository\Core\CommandHandler\CommandInterface;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\Core\SharedModel\User\UserId;

/**
* ForkContentStream for creating a new fork of a content stream.
Expand All @@ -25,17 +24,25 @@
*/
final class ForkContentStream implements CommandInterface
{
public function __construct(
/**
* Content stream id for the new content stream
*
* @var ContentStreamId
*/
/**
* @param ContentStreamId $newContentStreamId The id of the new content stream
* @param ContentStreamId $sourceContentStreamId The id of the content stream to fork
*/
private function __construct(
public readonly ContentStreamId $newContentStreamId,
public readonly ContentStreamId $sourceContentStreamId,
) {
}

/**
* @param ContentStreamId $newContentStreamId The id of the new content stream
* @param ContentStreamId $sourceContentStreamId The id of the content stream to fork
*/
public static function create(ContentStreamId $newContentStreamId, ContentStreamId $sourceContentStreamId): self
{
return new self($newContentStreamId, $sourceContentStreamId);
}

/**
* @param array<string,string> $array
* @internal only used for testcases
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,19 @@
*/
final class RemoveContentStream implements CommandInterface
{
public function __construct(
/**
* @param ContentStreamId $contentStreamId The id of the content stream to remove
*/
private function __construct(
public readonly ContentStreamId $contentStreamId,
) {
}

/**
* @param ContentStreamId $contentStreamId The id of the content stream to remove
*/
public static function create(ContentStreamId $contentStreamId): self
{
return new self($contentStreamId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,28 @@ final class AddDimensionShineThrough implements
\JsonSerializable,
RebasableToOtherContentStreamsInterface
{
public function __construct(
/**
* @param ContentStreamId $contentStreamId The id of the content stream to perform the operation in
* @param DimensionSpacePoint $source source dimension space point
* @param DimensionSpacePoint $target target dimension space point
*/
private function __construct(
public readonly ContentStreamId $contentStreamId,
public readonly DimensionSpacePoint $source,
public readonly DimensionSpacePoint $target
) {
}

/**
* @param ContentStreamId $contentStreamId The id of the content stream to perform the operation in
* @param DimensionSpacePoint $source source dimension space point
* @param DimensionSpacePoint $target target dimension space point
*/
public static function create(ContentStreamId $contentStreamId, DimensionSpacePoint $source, DimensionSpacePoint $target): self
{
return new self($contentStreamId, $source, $target);
}

/**
* @param array<string,mixed> $array
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,28 @@ final class MoveDimensionSpacePoint implements
CommandInterface,
RebasableToOtherContentStreamsInterface
{
public function __construct(
/**
* @param ContentStreamId $contentStreamId The id of the content stream to perform the operation in
* @param DimensionSpacePoint $source source dimension space point
* @param DimensionSpacePoint $target target dimension space point
*/
private function __construct(
public readonly ContentStreamId $contentStreamId,
public readonly DimensionSpacePoint $source,
public readonly DimensionSpacePoint $target
) {
}

/**
* @param ContentStreamId $contentStreamId The id of the content stream to perform the operation in
* @param DimensionSpacePoint $source source dimension space point
* @param DimensionSpacePoint $target target dimension space point
*/
public static function create(ContentStreamId $contentStreamId, DimensionSpacePoint $source, DimensionSpacePoint $target): self
{
return new self($contentStreamId, $source, $target);
}

/**
* @param array<string,mixed> $array
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,53 +36,42 @@
final class CreateNodeAggregateWithNode implements CommandInterface
{
/**
* Node aggregate id of the node's succeeding sibling (optional)
* If not given, the node will be added as the parent's first child
* @param ContentStreamId $contentStreamId The content stream in which the create operation is to be performed
* @param NodeAggregateId $nodeAggregateId The unique identifier of the node aggregate to create
* @param NodeTypeName $nodeTypeName Name of the node type of the new node
* @param OriginDimensionSpacePoint $originDimensionSpacePoint Origin of the new node in the dimension space. Will also be used to calculate a set of dimension points where the new node will cover from the configured specializations.
* @param NodeAggregateId $parentNodeAggregateId The id of the node aggregate underneath which the new node is added
* @param PropertyValuesToWrite $initialPropertyValues The node's initial property values. Will be merged over the node type's default property values
* @param NodeAggregateId|null $succeedingSiblingNodeAggregateId Node aggregate id of the node's succeeding sibling (optional). If not given, the node will be added as the parent's first child
* @param NodeName|null $nodeName The node's optional name. Set if there is a meaningful relation to its parent that should be named.
* @param NodeAggregateIdsByNodePaths $tetheredDescendantNodeAggregateIds Predefined aggregate ids of tethered child nodes per path. For any tethered node that has no matching entry in this set, the node aggregate id is generated randomly. Since tethered nodes may have tethered child nodes themselves, this works for multiple levels ({@see self::withTetheredDescendantNodeAggregateIds()})
*/
public readonly ?NodeAggregateId $succeedingSiblingNodeAggregateId;

/**
* The node's optional name. Set if there is a meaningful relation to its parent that should be named.
*/
public readonly ?NodeName $nodeName;

/**
* The node's initial property values. Will be merged over the node type's default property values
*/
public readonly PropertyValuesToWrite $initialPropertyValues;

/**
* NodeAggregateIds for tethered descendants (optional).
*
* If the given node type declares tethered child nodes, you may predefine their node aggregate ids
* using this assignment registry.
* Since tethered child nodes may have tethered child nodes themselves,
* this registry is indexed using relative node paths to the node to create in the first place.
*/
public readonly NodeAggregateIdsByNodePaths $tetheredDescendantNodeAggregateIds;

// TODO: CREATE METHODS FÜR ALLE COMMANDS
public function __construct(
private function __construct(
public readonly ContentStreamId $contentStreamId,
public readonly NodeAggregateId $nodeAggregateId,
public readonly NodeTypeName $nodeTypeName,
/**
* Origin of the new node in the dimension space.
* Will also be used to calculate a set of dimension points where the new node will cover
* from the configured specializations.
*/
public readonly OriginDimensionSpacePoint $originDimensionSpacePoint,
public readonly NodeAggregateId $parentNodeAggregateId,
?NodeAggregateId $succeedingSiblingNodeAggregateId = null,
?NodeName $nodeName = null,
?PropertyValuesToWrite $initialPropertyValues = null,
?NodeAggregateIdsByNodePaths $tetheredDescendantNodeAggregateIds = null
public readonly PropertyValuesToWrite $initialPropertyValues,
public readonly ?NodeAggregateId $succeedingSiblingNodeAggregateId,
public readonly ?NodeName $nodeName,
public readonly NodeAggregateIdsByNodePaths $tetheredDescendantNodeAggregateIds,
) {
$this->succeedingSiblingNodeAggregateId = $succeedingSiblingNodeAggregateId;
$this->nodeName = $nodeName;
$this->initialPropertyValues = $initialPropertyValues ?: PropertyValuesToWrite::fromArray([]);
$this->tetheredDescendantNodeAggregateIds = $tetheredDescendantNodeAggregateIds
?: new NodeAggregateIdsByNodePaths([]);
}

/**
* @param ContentStreamId $contentStreamId The content stream in which the create operation is to be performed
* @param NodeAggregateId $nodeAggregateId The unique identifier of the node aggregate to create
* @param NodeTypeName $nodeTypeName Name of the node type of the new node
* @param OriginDimensionSpacePoint $originDimensionSpacePoint Origin of the new node in the dimension space. Will also be used to calculate a set of dimension points where the new node will cover from the configured specializations.
* @param NodeAggregateId $parentNodeAggregateId The id of the node aggregate underneath which the new node is added
* @param NodeAggregateId|null $succeedingSiblingNodeAggregateId Node aggregate id of the node's succeeding sibling (optional). If not given, the node will be added as the parent's first child
* @param NodeName|null $nodeName The node's optional name. Set if there is a meaningful relation to its parent that should be named.
* @param PropertyValuesToWrite|null $initialPropertyValues The node's initial property values. Will be merged over the node type's default property values
*/
public static function create(ContentStreamId $contentStreamId, NodeAggregateId $nodeAggregateId, NodeTypeName $nodeTypeName, OriginDimensionSpacePoint $originDimensionSpacePoint, NodeAggregateId $parentNodeAggregateId, ?NodeAggregateId $succeedingSiblingNodeAggregateId = null, ?NodeName $nodeName = null, ?PropertyValuesToWrite $initialPropertyValues = null): self
{
return new self($contentStreamId, $nodeAggregateId, $nodeTypeName, $originDimensionSpacePoint, $parentNodeAggregateId, $initialPropertyValues ?: PropertyValuesToWrite::createEmpty(), $succeedingSiblingNodeAggregateId, $nodeName, NodeAggregateIdsByNodePaths::createEmpty());
}

public function withInitialPropertyValues(PropertyValuesToWrite $newInitialPropertyValues): self
Expand All @@ -93,10 +82,25 @@ public function withInitialPropertyValues(PropertyValuesToWrite $newInitialPrope
$this->nodeTypeName,
$this->originDimensionSpacePoint,
$this->parentNodeAggregateId,
$newInitialPropertyValues,
$this->succeedingSiblingNodeAggregateId,
$this->nodeName,
$newInitialPropertyValues,
$this->tetheredDescendantNodeAggregateIds
$this->tetheredDescendantNodeAggregateIds,
);
}

public function withTetheredDescendantNodeAggregateIds(NodeAggregateIdsByNodePaths $tetheredDescendantNodeAggregateIds): self
{
return new self(
$this->contentStreamId,
$this->nodeAggregateId,
$this->nodeTypeName,
$this->originDimensionSpacePoint,
$this->parentNodeAggregateId,
$this->initialPropertyValues,
$this->succeedingSiblingNodeAggregateId,
$this->nodeName,
$tetheredDescendantNodeAggregateIds,
);
}
}
Loading

0 comments on commit 020a0e0

Please sign in to comment.