From c64d9bcd3eeaf8237c47a5f8a819ffba4e2cc6c1 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Sun, 15 Oct 2023 10:31:08 +0200 Subject: [PATCH 1/4] BUGFIX: `NodeTypesCommandController` check if node type or configuration exists --- .../Classes/Command/NodeTypesCommandController.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Neos.ContentRepository/Classes/Command/NodeTypesCommandController.php b/Neos.ContentRepository/Classes/Command/NodeTypesCommandController.php index 9460c8ab2f3..2c5f4c86c14 100644 --- a/Neos.ContentRepository/Classes/Command/NodeTypesCommandController.php +++ b/Neos.ContentRepository/Classes/Command/NodeTypesCommandController.php @@ -31,9 +31,15 @@ class NodeTypesCommandController extends CommandController */ public function showCommand(string $nodeTypeName, ?string $path = null): void { + if (!$this->nodeTypeManager->hasNodeType($nodeTypeName)) { + $this->outputLine('NodeType "%s" was not found!', [$nodeTypeName]); + $this->quit(); + } + $nodeType = $this->nodeTypeManager->getNodeType($nodeTypeName); - if (!$nodeType) { - $this->outputLine('NodeType "%s" was not found!', [$nodeTypeName]); + + if ($path && !$nodeType->hasConfiguration($path)) { + $this->outputLine('NodeType "%s" does not have configuration "%s".', [$nodeTypeName, $path]); $this->quit(); } $yaml = Yaml::dump( From b1bb41d9942ae8c059d729f35a7a409ae27fba68 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Sun, 15 Oct 2023 10:32:08 +0200 Subject: [PATCH 2/4] BUGFIX: `NodeTypesCommandController` add "level" option to truncate to deep input Use it like ``` flow nodeTypes:show Neos.Demo:Document.Homepage --path properties --level 1 ``` to show only the property keys --- .../Command/NodeTypesCommandController.php | 42 +++++++++++++++---- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/Neos.ContentRepository/Classes/Command/NodeTypesCommandController.php b/Neos.ContentRepository/Classes/Command/NodeTypesCommandController.php index 2c5f4c86c14..d6c45863ae2 100644 --- a/Neos.ContentRepository/Classes/Command/NodeTypesCommandController.php +++ b/Neos.ContentRepository/Classes/Command/NodeTypesCommandController.php @@ -27,9 +27,10 @@ class NodeTypesCommandController extends CommandController * Shows the merged configuration (including supertypes) of a NodeType * * @param string $nodeTypeName The name of the NodeType to show + * @param ?int $level Truncate the configuration at this depth and show '...' (Usefully for only seeing the keys of the properties) * @param ?string $path Path of the NodeType-configuration which will be shown */ - public function showCommand(string $nodeTypeName, ?string $path = null): void + public function showCommand(string $nodeTypeName, ?string $path = null, ?int $level = 0): void { if (!$this->nodeTypeManager->hasNodeType($nodeTypeName)) { $this->outputLine('NodeType "%s" was not found!', [$nodeTypeName]); @@ -42,13 +43,14 @@ public function showCommand(string $nodeTypeName, ?string $path = null): void $this->outputLine('NodeType "%s" does not have configuration "%s".', [$nodeTypeName, $path]); $this->quit(); } - $yaml = Yaml::dump( - $path - ? $nodeType->getConfiguration($path) - : [$nodeTypeName => $nodeType->getFullConfiguration()], - 99 - ); - $this->outputLine('NodeType Configuration "%s":', [$nodeTypeName . ($path ? ("." . $path) : "")]); + + $configuration = $path + ? self::truncateArrayAtLevel($nodeType->getConfiguration($path), $level) + : [$nodeTypeName => self::truncateArrayAtLevel($nodeType->getFullConfiguration(), $level)]; + + $yaml = Yaml::dump($configuration, 99); + + $this->outputLine('NodeType configuration "%s":', [$nodeTypeName . ($path ? ("." . $path) : "")]); $this->outputLine(); $this->outputLine($yaml); $this->outputLine(); @@ -84,4 +86,28 @@ public function listCommand(?string $filter = null, bool $includeAbstract = true } } } + + /** + * @param int $truncateLevel 0 for no truncation and 1 to only show the first keys of the array + * @param int $currentLevel 1 for the start and will be incremented recursively + */ + private static function truncateArrayAtLevel(array $array, int $truncateLevel, int $currentLevel = 1): array + { + if ($truncateLevel <= 0) { + return $array; + } + $truncatedArray = []; + foreach ($array as $key => $value) { + if ($currentLevel >= $truncateLevel) { + $truncatedArray[$key] = '...'; // truncated + continue; + } + if (!is_array($value)) { + $truncatedArray[$key] = $value; + continue; + } + $truncatedArray[$key] = self::truncateArrayAtLevel($value, $truncateLevel, $currentLevel + 1); + } + return $truncatedArray; + } } From 85f811c4dc47ad93f3c9c4dfb4c6a40b91dfd826 Mon Sep 17 00:00:00 2001 From: Marc Henry Schultz <85400359+mhsdesign@users.noreply.github.com> Date: Fri, 3 Nov 2023 00:34:48 +0100 Subject: [PATCH 3/4] Task add suggestion from review Co-authored-by: Karsten Dambekalns --- .../Classes/Command/NodeTypesCommandController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Neos.ContentRepository/Classes/Command/NodeTypesCommandController.php b/Neos.ContentRepository/Classes/Command/NodeTypesCommandController.php index d6c45863ae2..97208c7406a 100644 --- a/Neos.ContentRepository/Classes/Command/NodeTypesCommandController.php +++ b/Neos.ContentRepository/Classes/Command/NodeTypesCommandController.php @@ -30,7 +30,7 @@ class NodeTypesCommandController extends CommandController * @param ?int $level Truncate the configuration at this depth and show '...' (Usefully for only seeing the keys of the properties) * @param ?string $path Path of the NodeType-configuration which will be shown */ - public function showCommand(string $nodeTypeName, ?string $path = null, ?int $level = 0): void + public function showCommand(string $nodeTypeName, string $path = '', int $level = 0): void { if (!$this->nodeTypeManager->hasNodeType($nodeTypeName)) { $this->outputLine('NodeType "%s" was not found!', [$nodeTypeName]); From b7abfbcfa09e11514dfb7bfe6144ca45284477c6 Mon Sep 17 00:00:00 2001 From: Marc Henry Schultz <85400359+mhsdesign@users.noreply.github.com> Date: Sun, 5 Nov 2023 14:35:37 +0100 Subject: [PATCH 4/4] TASK: Fix order of doc comments --- .../Classes/Command/NodeTypesCommandController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Neos.ContentRepository/Classes/Command/NodeTypesCommandController.php b/Neos.ContentRepository/Classes/Command/NodeTypesCommandController.php index 97208c7406a..65d05f57711 100644 --- a/Neos.ContentRepository/Classes/Command/NodeTypesCommandController.php +++ b/Neos.ContentRepository/Classes/Command/NodeTypesCommandController.php @@ -27,8 +27,8 @@ class NodeTypesCommandController extends CommandController * Shows the merged configuration (including supertypes) of a NodeType * * @param string $nodeTypeName The name of the NodeType to show - * @param ?int $level Truncate the configuration at this depth and show '...' (Usefully for only seeing the keys of the properties) - * @param ?string $path Path of the NodeType-configuration which will be shown + * @param string $path Path of the NodeType-configuration which will be shown + * @param int $level Truncate the configuration at this depth and show '...' (Usefully for only seeing the keys of the properties) */ public function showCommand(string $nodeTypeName, string $path = '', int $level = 0): void {