From 0d8ec989f58c3f4aa70ae2043a8a23187743892e Mon Sep 17 00:00:00 2001 From: Adrien Dupuis <61695653+adriendupuis@users.noreply.github.com> Date: Fri, 8 Aug 2025 16:05:34 +0200 Subject: [PATCH 1/7] DebugConfigResolverCommand.php: Add sort option --- .../Command/DebugConfigResolverCommand.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/bundle/Core/Command/DebugConfigResolverCommand.php b/src/bundle/Core/Command/DebugConfigResolverCommand.php index 8062d34248..f39d2cea6f 100644 --- a/src/bundle/Core/Command/DebugConfigResolverCommand.php +++ b/src/bundle/Core/Command/DebugConfigResolverCommand.php @@ -69,6 +69,18 @@ public function configure(): void InputOption::VALUE_REQUIRED, 'Set a different namespace than the default "ibexa.site_access.config" used by SiteAccess settings.' ); + $this->addOption( + 'sort', + null, + InputOption::VALUE_REQUIRED, + 'Sort list of hashes by this key, ascending. For example: --sort template' + ); + $this->addOption( + 'reverse-sort', + null, + InputOption::VALUE_NONE, + 'Reverse the sorting to descending. For example: --sort priority --reverse-sort' + ); $this->setHelp( <<getOption('scope'); $parameterData = $this->configResolver->getParameter($parameter, $namespace, $scope); + if (null !== ($sort = $input->getOption('sort')) && is_array($parameterData) && is_array($parameterData[0])) { + if ($input->getOption('reverse-sort')) { + usort($parameterData, function ($a, $b) use ($sort) { + return $b[$sort] <=> $a[$sort]; + }); + } else { + usort($parameterData, function ($a, $b) use ($sort) { + return $a[$sort] <=> $b[$sort]; + }); + } + } + // In case of json output return early with no newlines and only the parameter data if ($input->getOption('json')) { $output->write(json_encode($parameterData)); From 9e3d91aefa26704f04997f1e56946521254600c0 Mon Sep 17 00:00:00 2001 From: Adrien Dupuis <61695653+adriendupuis@users.noreply.github.com> Date: Fri, 8 Aug 2025 16:10:00 +0200 Subject: [PATCH 2/7] DebugConfigResolverCommand.php: Add sort option --- src/bundle/Core/Command/DebugConfigResolverCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bundle/Core/Command/DebugConfigResolverCommand.php b/src/bundle/Core/Command/DebugConfigResolverCommand.php index f39d2cea6f..9b2e622da4 100644 --- a/src/bundle/Core/Command/DebugConfigResolverCommand.php +++ b/src/bundle/Core/Command/DebugConfigResolverCommand.php @@ -107,7 +107,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $scope = $input->getOption('scope'); $parameterData = $this->configResolver->getParameter($parameter, $namespace, $scope); - if (null !== ($sort = $input->getOption('sort')) && is_array($parameterData) && is_array($parameterData[0])) { + if (null !== ($sort = $input->getOption('sort')) && is_array($parameterData) && is_array($parameterData[0]) && key_exists($sort, $parameterData[0]) && is_scalar($parameterData[0][$sort])) { if ($input->getOption('reverse-sort')) { usort($parameterData, function ($a, $b) use ($sort) { return $b[$sort] <=> $a[$sort]; From 0fa06228354d2739b5be677680833b35287f92ec Mon Sep 17 00:00:00 2001 From: Adrien Dupuis <61695653+adriendupuis@users.noreply.github.com> Date: Mon, 11 Aug 2025 16:17:33 +0200 Subject: [PATCH 3/7] DebugConfigResolverCommand.php: Fix code style --- src/bundle/Core/Command/DebugConfigResolverCommand.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bundle/Core/Command/DebugConfigResolverCommand.php b/src/bundle/Core/Command/DebugConfigResolverCommand.php index 9b2e622da4..663db38aa0 100644 --- a/src/bundle/Core/Command/DebugConfigResolverCommand.php +++ b/src/bundle/Core/Command/DebugConfigResolverCommand.php @@ -107,13 +107,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int $scope = $input->getOption('scope'); $parameterData = $this->configResolver->getParameter($parameter, $namespace, $scope); - if (null !== ($sort = $input->getOption('sort')) && is_array($parameterData) && is_array($parameterData[0]) && key_exists($sort, $parameterData[0]) && is_scalar($parameterData[0][$sort])) { + if (null !== ($sort = $input->getOption('sort')) && is_array($parameterData) && is_array($parameterData[0]) && array_key_exists($sort, $parameterData[0]) && is_scalar($parameterData[0][$sort])) { if ($input->getOption('reverse-sort')) { - usort($parameterData, function ($a, $b) use ($sort) { + usort($parameterData, static function ($a, $b) use ($sort) { return $b[$sort] <=> $a[$sort]; }); } else { - usort($parameterData, function ($a, $b) use ($sort) { + usort($parameterData, static function ($a, $b) use ($sort) { return $a[$sort] <=> $b[$sort]; }); } From 0b3ce1d48023146212d08aef7d1b3bc2968242dd Mon Sep 17 00:00:00 2001 From: Adrien Dupuis <61695653+adriendupuis@users.noreply.github.com> Date: Wed, 20 Aug 2025 11:27:21 +0200 Subject: [PATCH 4/7] DebugConfigResolverCommand.php: Enhance error handling --- .../Command/DebugConfigResolverCommand.php | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/bundle/Core/Command/DebugConfigResolverCommand.php b/src/bundle/Core/Command/DebugConfigResolverCommand.php index 663db38aa0..90f19ea5b2 100644 --- a/src/bundle/Core/Command/DebugConfigResolverCommand.php +++ b/src/bundle/Core/Command/DebugConfigResolverCommand.php @@ -8,6 +8,7 @@ namespace Ibexa\Bundle\Core\Command; use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface; +use Ibexa\Core\Base\Exceptions\InvalidArgumentException; use Ibexa\Core\MVC\Symfony\SiteAccess; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; @@ -73,7 +74,7 @@ public function configure(): void 'sort', null, InputOption::VALUE_REQUIRED, - 'Sort list of hashes by this key, ascending. For example: --sort template' + 'Sort list of hashes by this key, ascending. For example: --sort position' ); $this->addOption( 'reverse-sort', @@ -105,17 +106,26 @@ protected function execute(InputInterface $input, OutputInterface $output): int $parameter = $input->getArgument('parameter'); $namespace = $input->getOption('namespace'); $scope = $input->getOption('scope'); + $sort = $input->getOption('sort'); $parameterData = $this->configResolver->getParameter($parameter, $namespace, $scope); - if (null !== ($sort = $input->getOption('sort')) && is_array($parameterData) && is_array($parameterData[0]) && array_key_exists($sort, $parameterData[0]) && is_scalar($parameterData[0][$sort])) { + if (null !== $sort && !empty($parameterData)) { + if (!is_array($parameterData)) { + throw new InvalidArgumentException('--sort', "'$parameter' isn't a list. Sort can be used only on list."); + } + if (!array_is_list($parameterData)) { + throw new InvalidArgumentException('--sort', "'$parameter' is a hash or an object. Sort can be used only on list."); + } + if (!array_key_exists($sort, $parameterData[0])) { + throw new InvalidArgumentException('--sort', "'$sort' property doesn't exist on '$parameter' list items."); + } + if (!is_scalar($parameterData[0][$sort])) { + throw new InvalidArgumentException('--sort', "'{$parameter}[n][{$sort}]' properties aren't scalar and can't be sorted."); + } if ($input->getOption('reverse-sort')) { - usort($parameterData, static function ($a, $b) use ($sort) { - return $b[$sort] <=> $a[$sort]; - }); + usort($parameterData, static fn (array $a, array $b): int => $b[$sort] <=> $a[$sort]); } else { - usort($parameterData, static function ($a, $b) use ($sort) { - return $a[$sort] <=> $b[$sort]; - }); + usort($parameterData, static fn (array $a, array $b): int => $a[$sort] <=> $b[$sort]); } } From 907d61702e46650e7a08ee86e1c56019a78ca85d Mon Sep 17 00:00:00 2001 From: Adrien Dupuis <61695653+adriendupuis@users.noreply.github.com> Date: Tue, 14 Oct 2025 09:57:40 +0200 Subject: [PATCH 5/7] DebugConfigResolverCommand.php: Enhance error handling --- .../Core/Command/DebugConfigResolverCommand.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/bundle/Core/Command/DebugConfigResolverCommand.php b/src/bundle/Core/Command/DebugConfigResolverCommand.php index 90f19ea5b2..0187576e3b 100644 --- a/src/bundle/Core/Command/DebugConfigResolverCommand.php +++ b/src/bundle/Core/Command/DebugConfigResolverCommand.php @@ -111,16 +111,18 @@ protected function execute(InputInterface $input, OutputInterface $output): int if (null !== $sort && !empty($parameterData)) { if (!is_array($parameterData)) { - throw new InvalidArgumentException('--sort', "'$parameter' isn't a list. Sort can be used only on list."); + throw new InvalidArgumentException('--sort', "'$parameter' isn't a list. Sort can be used only on a list."); } if (!array_is_list($parameterData)) { - throw new InvalidArgumentException('--sort', "'$parameter' is a hash or an object. Sort can be used only on list."); + throw new InvalidArgumentException('--sort', "'$parameter' is a hash but sort can be used only on a list (an array with numeral keys incremented from zero)."); } - if (!array_key_exists($sort, $parameterData[0])) { - throw new InvalidArgumentException('--sort', "'$sort' property doesn't exist on '$parameter' list items."); - } - if (!is_scalar($parameterData[0][$sort])) { - throw new InvalidArgumentException('--sort', "'{$parameter}[n][{$sort}]' properties aren't scalar and can't be sorted."); + for ($i=0, $count = count($parameterData); $i < $count; $i++) { + if (!array_key_exists($sort, $parameterData[$i])) { + throw new InvalidArgumentException('--sort', "'$sort' property doesn't exist on each '$parameter' list item."); + } + if (!is_scalar($parameterData[$i][$sort])) { + throw new InvalidArgumentException('--sort', "'$sort' properties aren't always scalar and can't be sorted."); + } } if ($input->getOption('reverse-sort')) { usort($parameterData, static fn (array $a, array $b): int => $b[$sort] <=> $a[$sort]); From 7202bcd4c4b7e923af57e74cd06039d6f2c9e04b Mon Sep 17 00:00:00 2001 From: Adrien Dupuis <61695653+adriendupuis@users.noreply.github.com> Date: Tue, 14 Oct 2025 12:13:11 +0200 Subject: [PATCH 6/7] DebugConfigResolverCommand.php: PHP CS Fixer --- src/bundle/Core/Command/DebugConfigResolverCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bundle/Core/Command/DebugConfigResolverCommand.php b/src/bundle/Core/Command/DebugConfigResolverCommand.php index 0187576e3b..b542ed83aa 100644 --- a/src/bundle/Core/Command/DebugConfigResolverCommand.php +++ b/src/bundle/Core/Command/DebugConfigResolverCommand.php @@ -116,7 +116,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int if (!array_is_list($parameterData)) { throw new InvalidArgumentException('--sort', "'$parameter' is a hash but sort can be used only on a list (an array with numeral keys incremented from zero)."); } - for ($i=0, $count = count($parameterData); $i < $count; $i++) { + for ($i = 0, $count = count($parameterData); $i < $count; ++$i) { if (!array_key_exists($sort, $parameterData[$i])) { throw new InvalidArgumentException('--sort', "'$sort' property doesn't exist on each '$parameter' list item."); } From 5ea5d4d956f57a4223ad7a35476a32e56d69f08e Mon Sep 17 00:00:00 2001 From: Adrien Dupuis <61695653+adriendupuis@users.noreply.github.com> Date: Wed, 15 Oct 2025 15:20:34 +0200 Subject: [PATCH 7/7] DebugConfigResolverCommand.php: better list item check --- src/bundle/Core/Command/DebugConfigResolverCommand.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/bundle/Core/Command/DebugConfigResolverCommand.php b/src/bundle/Core/Command/DebugConfigResolverCommand.php index b542ed83aa..8cfc5f0948 100644 --- a/src/bundle/Core/Command/DebugConfigResolverCommand.php +++ b/src/bundle/Core/Command/DebugConfigResolverCommand.php @@ -116,11 +116,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int if (!array_is_list($parameterData)) { throw new InvalidArgumentException('--sort', "'$parameter' is a hash but sort can be used only on a list (an array with numeral keys incremented from zero)."); } - for ($i = 0, $count = count($parameterData); $i < $count; ++$i) { - if (!array_key_exists($sort, $parameterData[$i])) { + foreach ($parameterData as $item) { + if (!is_array($item) || array_is_list($item)) { + throw new InvalidArgumentException('--sort', "'$parameter' list items aren't all hashes. Sort can be used only on a list of hashes."); + } + if (!array_key_exists($sort, $item)) { throw new InvalidArgumentException('--sort', "'$sort' property doesn't exist on each '$parameter' list item."); } - if (!is_scalar($parameterData[$i][$sort])) { + if (!is_scalar($item[$sort])) { throw new InvalidArgumentException('--sort', "'$sort' properties aren't always scalar and can't be sorted."); } }