From a08a6cb800624ac32c6a0816a51aa570059c12ff Mon Sep 17 00:00:00 2001 From: Bastian Waidelich Date: Wed, 12 Apr 2023 10:09:47 +0200 Subject: [PATCH] TASK: Adjust code to stricter Value Objects (#3460) Related: https://github.com/neos/neos-development-collection/pull/4156 --- .../Service/WorkspaceService.php | 2 +- .../Changes/AbstractStructuralChange.php | 2 +- Classes/Domain/Model/Changes/Property.php | 2 +- Classes/Domain/Model/Changes/Remove.php | 2 +- .../Model/Feedback/Operations/NodeCreated.php | 4 ++-- .../Operations/RenderContentOutOfBand.php | 2 +- .../Feedback/Operations/UpdateNodeInfo.php | 2 +- .../Operations/UpdateWorkspaceInfo.php | 6 ++--- .../Service/NodePropertyConverterService.php | 2 +- .../NeosUiDefaultNodesOperation.php | 16 +++++++------- .../NeosUiFilteredChildrenOperation.php | 4 ++-- .../Fusion/Helper/ContentDimensionsHelper.php | 4 ++-- Classes/Fusion/Helper/NodeInfoHelper.php | 22 ++++++++----------- .../DocumentTitleNodeCreationHandler.php | 2 +- 14 files changed, 34 insertions(+), 38 deletions(-) diff --git a/Classes/ContentRepository/Service/WorkspaceService.php b/Classes/ContentRepository/Service/WorkspaceService.php index 08d6ce7867..7a55e24b05 100644 --- a/Classes/ContentRepository/Service/WorkspaceService.php +++ b/Classes/ContentRepository/Service/WorkspaceService.php @@ -135,7 +135,7 @@ public function getAllowedTargetWorkspaces(ContentRepository $contentRepository) continue; } // Skip own personal workspace - if ($workspace->workspaceName->name === $this->userService->getPersonalWorkspaceName()) { + if ($workspace->workspaceName->value === $this->userService->getPersonalWorkspaceName()) { continue; } diff --git a/Classes/Domain/Model/Changes/AbstractStructuralChange.php b/Classes/Domain/Model/Changes/AbstractStructuralChange.php index 129ac2c9db..32cdfde7d7 100644 --- a/Classes/Domain/Model/Changes/AbstractStructuralChange.php +++ b/Classes/Domain/Model/Changes/AbstractStructuralChange.php @@ -190,7 +190,7 @@ protected function isNodeTypeAllowedAsChildNode(Node $node, NodeType $nodeType): if (NodeInfoHelper::isAutoCreated($node, $subgraph)) { $parentNode = $subgraph->findParentNode($node->nodeAggregateId); return !$parentNode || $parentNode->nodeType->allowsGrandchildNodeType( - (string)$node->nodeName, + $node->nodeName->value, $nodeType ); } else { diff --git a/Classes/Domain/Model/Changes/Property.php b/Classes/Domain/Model/Changes/Property.php index 000aaed738..fc665ec8a0 100644 --- a/Classes/Domain/Model/Changes/Property.php +++ b/Classes/Domain/Model/Changes/Property.php @@ -260,7 +260,7 @@ public function apply(): void $node = $subgraph->findNodeById($originalNodeAggregateId); if (is_null($node)) { throw new \InvalidArgumentException( - 'Cannot apply Property on missing node ' . $originalNodeAggregateId, + 'Cannot apply Property on missing node ' . $originalNodeAggregateId->value, 1645560836 ); } diff --git a/Classes/Domain/Model/Changes/Remove.php b/Classes/Domain/Model/Changes/Remove.php index 6f6d9dc4db..c7719debca 100644 --- a/Classes/Domain/Model/Changes/Remove.php +++ b/Classes/Domain/Model/Changes/Remove.php @@ -59,7 +59,7 @@ public function apply(): void $parentNode = $this->findParentNode($subject); if (is_null($parentNode)) { throw new \InvalidArgumentException( - 'Cannot apply Remove without a parent on node ' . $subject->nodeAggregateId, + 'Cannot apply Remove without a parent on node ' . $subject->nodeAggregateId->value, 1645560717 ); } diff --git a/Classes/Domain/Model/Feedback/Operations/NodeCreated.php b/Classes/Domain/Model/Feedback/Operations/NodeCreated.php index e41c7e7b06..bbd8a4bcfd 100644 --- a/Classes/Domain/Model/Feedback/Operations/NodeCreated.php +++ b/Classes/Domain/Model/Feedback/Operations/NodeCreated.php @@ -62,7 +62,7 @@ public function getType(): string */ public function getDescription(): string { - return sprintf('Document Node "%s" created.', (string)$this->getNode()->nodeAggregateId); + return sprintf('Document Node "%s" created.', $this->getNode()->nodeAggregateId->value); } /** @@ -96,7 +96,7 @@ public function serializePayload(ControllerContext $controllerContext) $nodeAddressFactory = NodeAddressFactory::create($contentRepository); return [ 'contextPath' => $nodeAddressFactory->createFromNode($node)->serializeForUri(), - 'identifier' => (string)$node->nodeAggregateId, + 'identifier' => $node->nodeAggregateId->value, 'isDocument' => $node->nodeType->isOfType(NodeTypeNameFactory::NAME_DOCUMENT) ]; } diff --git a/Classes/Domain/Model/Feedback/Operations/RenderContentOutOfBand.php b/Classes/Domain/Model/Feedback/Operations/RenderContentOutOfBand.php index f865ad2707..c3f9539372 100644 --- a/Classes/Domain/Model/Feedback/Operations/RenderContentOutOfBand.php +++ b/Classes/Domain/Model/Feedback/Operations/RenderContentOutOfBand.php @@ -112,7 +112,7 @@ public function getType(): string public function getDescription(): string { - return sprintf('Rendering of node "%s" required.', $this->node?->nodeAggregateId); + return sprintf('Rendering of node "%s" required.', $this->node?->nodeAggregateId->value); } /** diff --git a/Classes/Domain/Model/Feedback/Operations/UpdateNodeInfo.php b/Classes/Domain/Model/Feedback/Operations/UpdateNodeInfo.php index 0d777fe8de..a5093bac59 100644 --- a/Classes/Domain/Model/Feedback/Operations/UpdateNodeInfo.php +++ b/Classes/Domain/Model/Feedback/Operations/UpdateNodeInfo.php @@ -76,7 +76,7 @@ public function getType(): string public function getDescription(): string { - return sprintf('Updated info for node "%s" is available.', $this->node?->nodeAggregateId); + return sprintf('Updated info for node "%s" is available.', $this->node?->nodeAggregateId->value); } /** diff --git a/Classes/Domain/Model/Feedback/Operations/UpdateWorkspaceInfo.php b/Classes/Domain/Model/Feedback/Operations/UpdateWorkspaceInfo.php index 9a3489e273..86c190cc9e 100644 --- a/Classes/Domain/Model/Feedback/Operations/UpdateWorkspaceInfo.php +++ b/Classes/Domain/Model/Feedback/Operations/UpdateWorkspaceInfo.php @@ -101,7 +101,7 @@ public function isSimilarTo(FeedbackInterface $feedback) return false; } - return (string)$this->getWorkspaceName() === (string)$feedback->getWorkspaceName(); + return $this->getWorkspaceName()?->value === $feedback->getWorkspaceName()?->value; } /** @@ -120,12 +120,12 @@ public function serializePayload(ControllerContext $controllerContext) $workspace = $contentRepository->getWorkspaceFinder()->findOneByName($this->workspaceName); return $workspace ? [ - 'name' => (string)$this->workspaceName, + 'name' => $this->workspaceName->value, 'publishableNodes' => $this->workspaceService->getPublishableNodeInfo( $this->workspaceName, $this->contentRepositoryId ), - 'baseWorkspace' => (string)$workspace->baseWorkspaceName + 'baseWorkspace' => $workspace->baseWorkspaceName->value ] : []; } } diff --git a/Classes/Domain/Service/NodePropertyConverterService.php b/Classes/Domain/Service/NodePropertyConverterService.php index 95eb8947cd..b4b21a19a8 100644 --- a/Classes/Domain/Service/NodePropertyConverterService.php +++ b/Classes/Domain/Service/NodePropertyConverterService.php @@ -182,7 +182,7 @@ private function toNodeIdentifierStrings(References $references): array { $identifiers = []; foreach ($references as $reference) { - $identifiers[] = (string)$reference->node->nodeAggregateId; + $identifiers[] = $reference->node->nodeAggregateId->value; } return $identifiers; } diff --git a/Classes/FlowQueryOperations/NeosUiDefaultNodesOperation.php b/Classes/FlowQueryOperations/NeosUiDefaultNodesOperation.php index 78e8301aa1..65cd7e78a7 100644 --- a/Classes/FlowQueryOperations/NeosUiDefaultNodesOperation.php +++ b/Classes/FlowQueryOperations/NeosUiDefaultNodesOperation.php @@ -85,7 +85,7 @@ public function evaluate(FlowQuery $flowQuery, array $arguments) if ($currentNode) { $currentNodePath = $subgraph->retrieveNodePath($currentNode->nodeAggregateId); $siteNodePath = $subgraph->retrieveNodePath($siteNode->nodeAggregateId); - $parentNodeIsUnderneathSiteNode = str_starts_with((string)$currentNodePath, (string)$siteNodePath); + $parentNodeIsUnderneathSiteNode = str_starts_with($currentNodePath->value, $siteNodePath->value); while ($currentNode instanceof Node && !$currentNode->nodeAggregateId->equals($siteNode->nodeAggregateId) && $parentNodeIsUnderneathSiteNode @@ -96,7 +96,7 @@ public function evaluate(FlowQuery $flowQuery, array $arguments) } $nodes = [ - ((string)$siteNode->nodeAggregateId) => $siteNode + ($siteNode->nodeAggregateId->value) => $siteNode ]; $gatherNodesRecursively = function ( @@ -120,29 +120,29 @@ public function evaluate(FlowQuery $flowQuery, array $arguments) // load toggled nodes in_array($baseNodeAddress->serializeForUri(), $toggledNodes) || // load children of all parents of documentNode - in_array((string)$baseNode->nodeAggregateId, $parents) + in_array($baseNode->nodeAggregateId->value, $parents) ) { foreach ($subgraph->findChildNodes( $baseNode->nodeAggregateId, FindChildNodesFilter::nodeTypeConstraints($baseNodeTypeConstraints) ) as $childNode) { - $nodes[(string)$childNode->nodeAggregateId] = $childNode; + $nodes[$childNode->nodeAggregateId->value] = $childNode; $gatherNodesRecursively($nodes, $childNode, $level + 1); } } }; $gatherNodesRecursively($nodes, $siteNode); - if (!isset($nodes[(string)$documentNode->nodeAggregateId])) { - $nodes[(string)$documentNode->nodeAggregateId] = $documentNode; + if (!isset($nodes[$documentNode->nodeAggregateId->value])) { + $nodes[$documentNode->nodeAggregateId->value] = $documentNode; } foreach ($clipboardNodesContextPaths as $clipboardNodeContextPath) { // TODO: does not work across multiple CRs yet. $clipboardNodeAddress = $nodeAddressFactory->createFromUriString($clipboardNodeContextPath); $clipboardNode = $subgraph->findNodeById($clipboardNodeAddress->nodeAggregateId); - if ($clipboardNode && !array_key_exists((string)$clipboardNode->nodeAggregateId, $nodes)) { - $nodes[(string)$clipboardNode->nodeAggregateId] = $clipboardNode; + if ($clipboardNode && !array_key_exists($clipboardNode->nodeAggregateId->value, $nodes)) { + $nodes[$clipboardNode->nodeAggregateId->value] = $clipboardNode; } } diff --git a/Classes/FlowQueryOperations/NeosUiFilteredChildrenOperation.php b/Classes/FlowQueryOperations/NeosUiFilteredChildrenOperation.php index 801a06e4ed..8d354a3607 100644 --- a/Classes/FlowQueryOperations/NeosUiFilteredChildrenOperation.php +++ b/Classes/FlowQueryOperations/NeosUiFilteredChildrenOperation.php @@ -78,9 +78,9 @@ public function evaluate(FlowQuery $flowQuery, array $arguments) $contextNode->nodeAggregateId, FindChildNodesFilter::nodeTypeConstraints($arguments[0] ?? null) ) as $childNode) { - if (!isset($outputNodeIdentifiers[(string)$childNode->nodeAggregateId])) { + if (!isset($outputNodeIdentifiers[$childNode->nodeAggregateId->value])) { $output[] = $childNode; - $outputNodeIdentifiers[(string)$childNode->nodeAggregateId] = true; + $outputNodeIdentifiers[$childNode->nodeAggregateId->value] = true; } } } diff --git a/Classes/Fusion/Helper/ContentDimensionsHelper.php b/Classes/Fusion/Helper/ContentDimensionsHelper.php index 82bfa5dfa9..05095965d2 100644 --- a/Classes/Fusion/Helper/ContentDimensionsHelper.php +++ b/Classes/Fusion/Helper/ContentDimensionsHelper.php @@ -42,7 +42,7 @@ public function contentDimensionsByName(ContentRepositoryId $contentRepositoryId $result = []; foreach ($dimensions as $dimension) { - $result[(string)$dimension->id] = [ + $result[$dimension->id->value] = [ 'label' => $dimension->getConfigurationValue('label'), 'icon' => $dimension->getConfigurationValue('icon'), @@ -53,7 +53,7 @@ public function contentDimensionsByName(ContentRepositoryId $contentRepositoryId foreach ($dimension->values as $value) { // TODO: make certain values hidable - $result[(string)$dimension->id]['presets'][$value->value] = [ + $result[$dimension->id->value]['presets'][$value->value] = [ // TODO: name, uriSegment! 'values' => [$value->value], 'label' => $value->getConfigurationValue('label') diff --git a/Classes/Fusion/Helper/NodeInfoHelper.php b/Classes/Fusion/Helper/NodeInfoHelper.php index d43bc41f2e..06c748f49f 100644 --- a/Classes/Fusion/Helper/NodeInfoHelper.php +++ b/Classes/Fusion/Helper/NodeInfoHelper.php @@ -15,18 +15,14 @@ use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindChildNodesFilter; use Neos\ContentRepository\Core\Projection\ContentGraph\Node; use Neos\ContentRepository\Core\Projection\ContentGraph\Nodes; -use Neos\ContentRepository\Core\Projection\NodeHiddenState\NodeHiddenState; use Neos\ContentRepository\Core\Projection\NodeHiddenState\NodeHiddenStateFinder; -use Neos\ContentRepository\Core\Projection\NodeHiddenState\NodeHiddenStateProjection; -use Neos\Neos\FrontendRouting\NodeAddress; -use Neos\Neos\FrontendRouting\NodeAddressFactory; -use Neos\ContentRepository\Core\NodeType\NodeTypeConstraintParser; -use Neos\ContentRepository\Core\Projection\ContentGraph\NodeTypeConstraints; use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry; use Neos\Eel\ProtectedContextAwareInterface; use Neos\Flow\Annotations as Flow; use Neos\Flow\Mvc\Controller\ControllerContext; use Neos\Flow\Persistence\PersistenceManagerInterface; +use Neos\Neos\FrontendRouting\NodeAddress; +use Neos\Neos\FrontendRouting\NodeAddressFactory; use Neos\Neos\FrontendRouting\NodeUriBuilder; use Neos\Neos\TypeConverter\EntityToIdentityConverter; use Neos\Neos\Ui\Domain\Service\NodePropertyConverterService; @@ -250,7 +246,7 @@ public static function isAutoCreated(Node $node, ContentSubgraphInterface $subgr { $parent = $subgraph->findParentNode($node->nodeAggregateId); if ($parent) { - if (array_key_exists((string)$node->nodeName, $parent->nodeType->getAutoCreatedChildNodes())) { + if (array_key_exists($node->nodeName->value, $parent->nodeType->getAutoCreatedChildNodes())) { return true; } } @@ -328,15 +324,15 @@ public function renderNodesWithParents(array $nodes, ControllerContext $controll $subgraph = $this->contentRepositoryRegistry->subgraphForNode($node); $nodePath = $subgraph->retrieveNodePath($node->nodeAggregateId); - if (array_key_exists($nodePath->jsonSerialize(), $renderedNodes)) { - $renderedNodes[(string)$nodePath]['matched'] = true; + if (array_key_exists($nodePath->value, $renderedNodes)) { + $renderedNodes[$nodePath->value]['matched'] = true; } elseif ($renderedNode = $this->renderNodeWithMinimalPropertiesAndChildrenInformation( $node, $controllerContext, $baseNodeTypeOverride )) { $renderedNode['matched'] = true; - $renderedNodes[(string)$nodePath] = $renderedNode; + $renderedNodes[$nodePath->value] = $renderedNode; } else { continue; } @@ -350,8 +346,8 @@ public function renderNodesWithParents(array $nodes, ControllerContext $controll $parentNodePath = $subgraph->retrieveNodePath($parentNode->nodeAggregateId); while ($parentNode->nodeType->isOfType($baseNodeTypeOverride)) { - if (array_key_exists((string)$parentNodePath, $renderedNodes)) { - $renderedNodes[(string)$parentNodePath]['intermediate'] = true; + if (array_key_exists($parentNodePath->value, $renderedNodes)) { + $renderedNodes[$parentNodePath->value]['intermediate'] = true; } else { $renderedParentNode = $this->renderNodeWithMinimalPropertiesAndChildrenInformation( $parentNode, @@ -360,7 +356,7 @@ public function renderNodesWithParents(array $nodes, ControllerContext $controll ); if ($renderedParentNode) { $renderedParentNode['intermediate'] = true; - $renderedNodes[(string)$parentNodePath] = $renderedParentNode; + $renderedNodes[$parentNodePath->value] = $renderedParentNode; } } $parentNode = $subgraph->findParentNode($parentNode->nodeAggregateId); diff --git a/Classes/NodeCreationHandler/DocumentTitleNodeCreationHandler.php b/Classes/NodeCreationHandler/DocumentTitleNodeCreationHandler.php index d076612a34..1bba052b23 100644 --- a/Classes/NodeCreationHandler/DocumentTitleNodeCreationHandler.php +++ b/Classes/NodeCreationHandler/DocumentTitleNodeCreationHandler.php @@ -60,7 +60,7 @@ public function handle(CreateNodeAggregateWithNode $command, array $data, Conten // otherwise, we fall back to the node name if ($uriPathSegment === null && $command->nodeName !== null) { - $uriPathSegment = (string)$command->nodeName; + $uriPathSegment = $command->nodeName->value; } // if not empty, we transliterate the uriPathSegment according to the language of the new node