diff --git a/src/bundle/Core/Command/DebugConfigResolverCommand.php b/src/bundle/Core/Command/DebugConfigResolverCommand.php index 8062d34248..663db38aa0 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]) && array_key_exists($sort, $parameterData[0]) && is_scalar($parameterData[0][$sort])) { + if ($input->getOption('reverse-sort')) { + usort($parameterData, static function ($a, $b) use ($sort) { + return $b[$sort] <=> $a[$sort]; + }); + } else { + usort($parameterData, static 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));