Skip to content

Commit a00a201

Browse files
committed
backport changes
1 parent 196b5d5 commit a00a201

1 file changed

Lines changed: 19 additions & 19 deletions

File tree

src/Illuminate/View/Concerns/ManagesComponents.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ public function startComponent($name, array $data = [])
4646
if (ob_start()) {
4747
$this->componentStack[] = $name;
4848

49-
$this->componentData[$name] = $data;
49+
$this->componentData[$this->currentComponent()] = $data;
5050

51-
$this->slots[$name] = [];
51+
$this->slots[$this->currentComponent()] = [];
5252
}
5353
}
5454

@@ -61,9 +61,7 @@ public function renderComponent()
6161
{
6262
$name = array_pop($this->componentStack);
6363

64-
return tap($this->make($name, $this->componentData($name))->render(), function () use ($name) {
65-
$this->resetComponent($name);
66-
});
64+
return $this->make($name, $this->componentData($name))->render();
6765
}
6866

6967
/**
@@ -74,9 +72,11 @@ public function renderComponent()
7472
*/
7573
protected function componentData($name)
7674
{
77-
$slot = ['slot' => new HtmlString(trim(ob_get_clean()))];
78-
79-
return array_merge($this->componentData[$name], $slot, $this->slots[$name]);
75+
return array_merge(
76+
$this->componentData[count($this->componentStack)],
77+
['slot' => new HtmlString(trim(ob_get_clean()))],
78+
$this->slots[count($this->componentStack)]
79+
);
8080
}
8181

8282
/**
@@ -88,9 +88,9 @@ protected function componentData($name)
8888
public function slot($name)
8989
{
9090
if (ob_start()) {
91-
$this->slots[last($this->componentStack)][$name] = '';
91+
$this->slots[$this->currentComponent()][$name] = '';
9292

93-
$this->slotStack[last($this->componentStack)][] = $name;
93+
$this->slotStack[$this->currentComponent()][] = $name;
9494
}
9595
}
9696

@@ -103,21 +103,21 @@ public function endSlot()
103103
{
104104
$current = last($this->componentStack);
105105

106-
$currentSlot = array_pop($this->slotStack[$current]);
106+
$currentSlot = array_pop(
107+
$this->slotStack[$this->currentComponent()]
108+
);
107109

108-
$this->slots[$current][$currentSlot] = new HtmlString(trim(ob_get_clean()));
110+
$this->slots[$this->currentComponent()]
111+
[$currentSlot] = new HtmlString(trim(ob_get_clean()));
109112
}
110113

111114
/**
112-
* Reset the state for the given component.
115+
* Get the index for the current component.
113116
*
114-
* @param string $name
115-
* @return void
117+
* @return int
116118
*/
117-
protected function resetComponent($name)
119+
protected function currentComponent()
118120
{
119-
unset($this->slots[$name]);
120-
unset($this->slotStack[$name]);
121-
unset($this->componentData[$name]);
121+
return count($this->componentStack) - 1;
122122
}
123123
}

0 commit comments

Comments
 (0)