Skip to content

Commit

Permalink
[10.x] Fixes artisan about --only should be case insensitive (#47955)
Browse files Browse the repository at this point in the history
* [10.x] Fixes `artisan about --only` should be case insensitive.

fixes #47950

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

* Apply fixes from StyleCI

* wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

* Update AboutCommand.php

---------

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Co-authored-by: StyleCI Bot <bot@styleci.io>
Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
3 people authored Aug 4, 2023
1 parent fad2aab commit 9d09c23
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/Illuminate/Foundation/Console/AboutCommand.php
Original file line number Diff line number Diff line change
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();
}
}

0 comments on commit 9d09c23

Please sign in to comment.