Skip to content

Added sorting options to ìbexa:debug:config` #631

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/bundle/Core/Command/DebugConfigResolverCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<<<EOM
Outputs a given config resolver parameter, more commonly known as a SiteAccess setting.
Expand All @@ -95,6 +107,18 @@ 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]) && array_key_exists($sort, $parameterData[0]) && is_scalar($parameterData[0][$sort])) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we somehow simplify this check ?

if ($input->getOption('reverse-sort')) {
usort($parameterData, static function ($a, $b) use ($sort) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
usort($parameterData, static function ($a, $b) use ($sort) {
usort($parameterData, static function ($a, $b): int use ($sort) {

Could you also please specify types for $a and $b ?

return $b[$sort] <=> $a[$sort];
});
} else {
usort($parameterData, static function ($a, $b) use ($sort) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
usort($parameterData, static function ($a, $b) use ($sort) {
usort($parameterData, static function ($a, $b): int use ($sort) {

Could you also please specify types for $a and $b ?

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));
Expand Down
Loading