Skip to content

Commit bbb1a7c

Browse files
committed
DebugConfigResolverCommand.php: Add sort option
1 parent d7bd603 commit bbb1a7c

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/bundle/Core/Command/DebugConfigResolverCommand.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,18 @@ public function configure(): void
6969
InputOption::VALUE_REQUIRED,
7070
'Set a different namespace than the default "ibexa.site_access.config" used by SiteAccess settings.'
7171
);
72+
$this->addOption(
73+
'sort',
74+
null,
75+
InputOption::VALUE_REQUIRED,
76+
'Sort list of hashes by this key, ascending. For example: --sort template'
77+
);
78+
$this->addOption(
79+
'reverse-sort',
80+
null,
81+
InputOption::VALUE_NONE,
82+
'Reverse the sorting to descending. For example: --sort priority --reverse-sort'
83+
);
7284
$this->setHelp(
7385
<<<EOM
7486
Outputs a given config resolver parameter, more commonly known as a SiteAccess setting.
@@ -95,6 +107,18 @@ protected function execute(InputInterface $input, OutputInterface $output): int
95107
$scope = $input->getOption('scope');
96108
$parameterData = $this->configResolver->getParameter($parameter, $namespace, $scope);
97109

110+
if (null !== ($sort = $input->getOption('sort')) && is_array($parameterData) && is_array($parameterData[0])) {
111+
if ($input->getOption('reverse-sort')) {
112+
usort($parameterData, function ($a, $b) use ($sort) {
113+
return $b[$sort] <=> $a[$sort];
114+
});
115+
} else {
116+
usort($parameterData, function ($a, $b) use ($sort) {
117+
return $a[$sort] <=> $b[$sort];
118+
});
119+
}
120+
}
121+
98122
// In case of json output return early with no newlines and only the parameter data
99123
if ($input->getOption('json')) {
100124
$output->write(json_encode($parameterData));

0 commit comments

Comments
 (0)