Skip to content

Commit

Permalink
use loop
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Mar 8, 2024
1 parent a5f933b commit b90a139
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/Illuminate/View/Compilers/ComponentTagCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -792,22 +792,24 @@ protected function attributesToString(array $attributes, $escapeBound = true)
*/
protected function attributesToStringWithExistingComponentData(array $attributes, $escapeBound = true)
{
return collect($attributes)
->map(function (string $value, string $attribute) use ($escapeBound) {
if (
(! $escapeBound) ||
(! isset($this->boundAttributes[$attribute])) ||
($value === 'true') ||
is_numeric($value)
) {
return "'{$attribute}' => {$value}";
}
$results = [];

return "'{$attribute}' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(".(
($attribute === 'attributes') ? $value : ('$componentData[\'data\'][\''.Str::camel($attribute).'\'] ?? null')
).')';
})
->implode(',');
foreach ($attributes as $attribute => $value) {
if (! $escapeBound ||
! isset($this->boundAttributes[$attribute]) ||
$value === 'true' ||
is_numeric($value)) {
$results[] = "'{$attribute}' => {$value}";

continue;
}

$results[] = "'{$attribute}' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(".(
($attribute === 'attributes') ? $value : ('$componentData[\'data\'][\''.Str::camel($attribute).'\'] ?? null')
).')';
}

return implode(',', $results);
}

/**
Expand Down

0 comments on commit b90a139

Please sign in to comment.