Skip to content

Commit

Permalink
Revert PR 50403 (#50482)
Browse files Browse the repository at this point in the history
  • Loading branch information
driesvints authored Mar 12, 2024
1 parent 40c32ce commit 199193a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 84 deletions.
33 changes: 2 additions & 31 deletions src/Illuminate/View/Compilers/ComponentTagCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,11 @@ protected function componentString(string $component, array $attributes)
$parameters = $data->all();
}

return "##BEGIN-COMPONENT-CLASS##@component('{$class}', '{$component}', \$componentData = [".$this->attributesToString($parameters, $escapeBound = false).'])
return "##BEGIN-COMPONENT-CLASS##@component('{$class}', '{$component}', [".$this->attributesToString($parameters, $escapeBound = false).'])
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag && $constructor = (new ReflectionClass('.$class.'::class))->getConstructor()): ?>
<?php $attributes = $attributes->except(collect($constructor->getParameters())->map->getName()->all()); ?>
<?php endif; ?>
<?php $component->withAttributes(['.$this->attributesToStringWithExistingComponentData($attributes->all(), $escapeAttributes = $class !== DynamicComponent::class && ! is_subclass_of($class, DynamicComponent::class)).']); ?>';
<?php $component->withAttributes(['.$this->attributesToString($attributes->all(), $escapeAttributes = $class !== DynamicComponent::class).']); ?>';
}

/**
Expand Down Expand Up @@ -783,35 +783,6 @@ protected function attributesToString(array $attributes, $escapeBound = true)
->implode(',');
}

/**
* Convert an array of attributes to a string using existing component data that has already been evaluated.
*
* @param array $attributes
* @param bool $escapeBound
* @return string
*/
protected function attributesToStringWithExistingComponentData(array $attributes, $escapeBound = true)
{
$results = [];

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);
}

/**
* Strip any quotes from the given string.
*
Expand Down
5 changes: 0 additions & 5 deletions src/Illuminate/View/Compilers/Concerns/CompilesComponents.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public static function compileClassComponentOpening(string $component, string $a
{
return implode("\n", [
'<?php if (isset($component)) { $__componentOriginal'.$hash.' = $component; } ?>',
'<?php if (isset($componentData)) { $__componentDataOriginal'.$hash.' = $componentData; } ?>',
'<?php if (isset($attributes)) { $__attributesOriginal'.$hash.' = $attributes; } ?>',
'<?php $component = '.$component.'::resolve('.($data ?: '[]').' + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? (array) $attributes->getIterator() : [])); ?>',
'<?php $component->withName('.$alias.'); ?>',
Expand Down Expand Up @@ -101,10 +100,6 @@ public function compileEndComponentClass()
'<?php $attributes = $__attributesOriginal'.$hash.'; ?>',
'<?php unset($__attributesOriginal'.$hash.'); ?>',
'<?php endif; ?>',
'<?php if (isset($__componentDataOriginal'.$hash.')): ?>',
'<?php $componentData = $__componentDataOriginal'.$hash.'; ?>',
'<?php unset($__componentDataOriginal'.$hash.'); ?>',
'<?php endif; ?>',
'<?php if (isset($__componentOriginal'.$hash.')): ?>',
'<?php $component = $__componentOriginal'.$hash.'; ?>',
'<?php unset($__componentOriginal'.$hash.'); ?>',
Expand Down
Loading

0 comments on commit 199193a

Please sign in to comment.