Skip to content

Commit 9d09c23

Browse files
crynoboneStyleCIBottaylorotwell
authored
[10.x] Fixes artisan about --only should be case insensitive (#47955)
* [10.x] Fixes `artisan about --only` should be case insensitive. fixes #47950 Signed-off-by: Mior Muhammad Zaki <[email protected]> * Apply fixes from StyleCI * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * Update AboutCommand.php --------- Signed-off-by: Mior Muhammad Zaki <[email protected]> Co-authored-by: StyleCI Bot <[email protected]> Co-authored-by: Taylor Otwell <[email protected]>
1 parent fad2aab commit 9d09c23

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/Illuminate/Foundation/Console/AboutCommand.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function handle()
9191
return $index === false ? 99 : $index;
9292
})
9393
->filter(function ($data, $key) {
94-
return $this->option('only') ? in_array(Str::of($key)->lower()->snake(), $this->sections()) : true;
94+
return $this->option('only') ? in_array($this->toSearchKeyword($key), $this->sections()) : true;
9595
})
9696
->pipe(fn ($data) => $this->display($data));
9797

@@ -141,7 +141,11 @@ protected function displayDetail($data)
141141
protected function displayJson($data)
142142
{
143143
$output = $data->flatMap(function ($data, $section) {
144-
return [(string) Str::of($section)->snake() => $data->mapWithKeys(fn ($item, $key) => [(string) Str::of($item[0])->lower()->snake() => value($item[1])])];
144+
return [
145+
(string) Str::of($section)->snake() => $data->mapWithKeys(fn ($item, $key) => [
146+
$this->toSearchKeyword($item[0]) => value($item[1]),
147+
]),
148+
];
145149
});
146150

147151
$this->output->writeln(strip_tags(json_encode($output)));
@@ -250,6 +254,20 @@ protected static function addToSection(string $section, $data, string $value = n
250254
*/
251255
protected function sections()
252256
{
253-
return array_filter(explode(',', $this->option('only') ?? ''));
257+
return collect(explode(',', $this->option('only') ?? ''))
258+
->filter()
259+
->map(fn ($only) => $this->toSearchKeyword($only))
260+
->all();
261+
}
262+
263+
/**
264+
* Format the given string for searching.
265+
*
266+
* @param string $value
267+
* @return string
268+
*/
269+
protected function toSearchKeyword(string $value)
270+
{
271+
return (string) Str::of($value)->lower()->snake();
254272
}
255273
}

0 commit comments

Comments
 (0)