AnonymousComponent.php
1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
namespace Illuminate\View;
class AnonymousComponent extends Component
{
/**
* The component view.
*
* @var string
*/
protected $view;
/**
* The component data.
*
* @var array
*/
protected $data = [];
/**
* Create a new anonymous component instance.
*
* @param string $view
* @param array $data
* @return void
*/
public function __construct($view, $data)
{
$this->view = $view;
$this->data = $data;
}
/**
* Get the view / view contents that represent the component.
*
* @return string
*/
public function render()
{
return $this->view;
}
/**
* Get the data that should be supplied to the view.
*
* @return array
*/
public function data()
{
$this->attributes = $this->attributes ?: $this->newAttributeBag();
return array_merge(
optional($this->data['attributes'] ?? null)->getAttributes() ?: [],
$this->attributes->getAttributes(),
$this->data,
['attributes' => $this->attributes]
);
}
}