-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathComponentsCollector.php
More file actions
80 lines (68 loc) · 1.93 KB
/
Copy pathComponentsCollector.php
File metadata and controls
80 lines (68 loc) · 1.93 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php namespace Winter\Debugbar\Collectors;
use Cms\Classes\ComponentBase;
use Cms\Classes\Controller;
use Cms\Classes\Layout;
use Cms\Classes\Page;
use DebugBar\DataCollector\DataCollector;
use DebugBar\DataCollector\Renderable;
class ComponentsCollector extends DataCollector implements Renderable
{
/** @var Controller */
protected $controller;
/** @var Page */
protected $page;
/** @var Layout */
protected $layout;
public function __construct(Controller $controller, Page $page, Layout $layout)
{
$this->controller = $controller;
$this->page = $page;
$this->layout = $layout;
}
/**
* {@inheritDoc}
*/
public function collect(): array
{
/** @var ComponentBase[]|object $components */
$components = [];
foreach ($this->layout->components as $alias => $componentObj) {
$components[$alias] = $this->formatVar($this->makeComponentDetails($componentObj));
}
foreach ($this->page->components as $alias => $componentObj) {
$components[$alias] = $this->formatVar($this->makeComponentDetails($componentObj));
}
return $components;
}
/**
* makeComponentDetails builds a useful array to describe a component
*/
protected function makeComponentDetails($componentObj): array
{
return [
'class' => get_class($componentObj),
'props' => $componentObj->getProperties()
];
}
/**
* {@inheritDoc}
*/
public function getName(): string
{
return 'components';
}
/**
* {@inheritDoc}
*/
public function getWidgets(): array
{
return [
'components' => [
'icon' => 'puzzle-piece',
'widget' => 'PhpDebugBar.Widgets.VariableListWidget',
'map' => 'components',
'default' => '{}'
]
];
}
}