Skip to content

Commit b802c98

Browse files
committed
initial pass at supporting dynamic blade components
1 parent ba217b9 commit b802c98

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

src/Illuminate/View/Compilers/ComponentTagCompiler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ protected function componentString(string $component, array $attributes)
231231
*
232232
* @throws \InvalidArgumentException
233233
*/
234-
protected function componentClass(string $component)
234+
public function componentClass(string $component)
235235
{
236236
$viewFactory = Container::getInstance()->make(Factory::class);
237237

@@ -288,7 +288,7 @@ public function guessClassName(string $component)
288288
* @param array $attributes
289289
* @return array
290290
*/
291-
protected function partitionDataAndAttributes($class, array $attributes)
291+
public function partitionDataAndAttributes($class, array $attributes)
292292
{
293293
// If the class doesn't exists, we'll assume it's a class-less component and
294294
// return all of the attributes as both data and attributes since we have

src/Illuminate/View/ComponentAttributeBag.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function merge(array $attributeDefaults = [])
111111
$attributes = [];
112112

113113
$attributeDefaults = array_map(function ($value) {
114-
if (is_null($value) || is_bool($value)) {
114+
if (is_object($value) || is_null($value) || is_bool($value)) {
115115
return $value;
116116
}
117117

@@ -133,6 +133,16 @@ public function merge(array $attributeDefaults = [])
133133
return new static(array_merge($attributeDefaults, $attributes));
134134
}
135135

136+
/**
137+
* Get all of the raw attributes.
138+
*
139+
* @return array
140+
*/
141+
public function getAttributes()
142+
{
143+
return $this->attributes;
144+
}
145+
136146
/**
137147
* Set the underlying attributes.
138148
*

src/Illuminate/View/Concerns/ManagesComponents.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,17 @@ public function renderComponent()
101101
*/
102102
protected function componentData()
103103
{
104+
$defaultSlot = new HtmlString(trim(ob_get_clean()));
105+
106+
$slots = array_merge([
107+
'__default' => $defaultSlot,
108+
], $this->slots[count($this->componentStack)]);
109+
104110
return array_merge(
105111
$this->componentData[count($this->componentStack)],
106-
['slot' => new HtmlString(trim(ob_get_clean()))],
107-
$this->slots[count($this->componentStack)]
112+
['slot' => $defaultSlot],
113+
$this->slots[count($this->componentStack)],
114+
['__laravel_slots' => $slots],
108115
);
109116
}
110117

0 commit comments

Comments
 (0)