From bbb1a7cea016aed1aaaad7a5db342dd2d7bc0f23 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/3] 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 d6fb3753ed83b4aedc37cd168b6e6860bd4da49c 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/3] 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 1aad6d28dd6bb171c458cd4b534eae7653462fc2 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/3] 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]; }); }