Skip to content
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

[10.x] Fixes artisan about --only should be case insensitive #47955

Merged
merged 4 commits into from Aug 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 21 additions & 3 deletions src/Illuminate/Foundation/Console/AboutCommand.php
Expand Up @@ -91,7 +91,7 @@ public function handle()
return $index === false ? 99 : $index;
})
->filter(function ($data, $key) {
return $this->option('only') ? in_array(Str::of($key)->lower()->snake(), $this->sections()) : true;
return $this->option('only') ? in_array($this->toSearchKeyword($key), $this->sections()) : true;
})
->pipe(fn ($data) => $this->display($data));

Expand Down Expand Up @@ -141,7 +141,11 @@ protected function displayDetail($data)
protected function displayJson($data)
{
$output = $data->flatMap(function ($data, $section) {
return [(string) Str::of($section)->snake() => $data->mapWithKeys(fn ($item, $key) => [(string) Str::of($item[0])->lower()->snake() => value($item[1])])];
return [
(string) Str::of($section)->snake() => $data->mapWithKeys(fn ($item, $key) => [
$this->toSearchKeyword($item[0]) => value($item[1]),
]),
];
});

$this->output->writeln(strip_tags(json_encode($output)));
Expand Down Expand Up @@ -250,6 +254,20 @@ protected static function addToSection(string $section, $data, string $value = n
*/
protected function sections()
{
return array_filter(explode(',', $this->option('only') ?? ''));
return collect(explode(',', $this->option('only') ?? ''))
->filter()
->map(fn ($only) => $this->toSearchKeyword($only))
->all();
}

/**
* Format the given string for searching.
*
* @param string $value
* @return string
*/
protected function toSearchKeyword(string $value)
{
return (string) Str::of($value)->lower()->snake();
}
}