1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LeKoala\DebugBar\Collector; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Core\Kernel; |
6
|
|
|
use LeKoala\DebugBar\DebugBar; |
7
|
|
|
use SilverStripe\Control\Director; |
8
|
|
|
use DebugBar\DataCollector\Renderable; |
9
|
|
|
use SilverStripe\Core\Injector\Injector; |
10
|
|
|
use DebugBar\DataCollector\AssetProvider; |
11
|
|
|
use DebugBar\DataCollector\DataCollector; |
12
|
|
|
use LeKoala\DebugBar\Proxy\ProxyConfigCollectionInterface; |
13
|
|
|
use SilverStripe\Config\Collections\ConfigCollectionInterface; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Collects data about the config usage during a SilverStripe request |
17
|
|
|
*/ |
18
|
|
|
class ConfigCollector extends DataCollector implements Renderable, AssetProvider |
19
|
|
|
{ |
20
|
|
|
public function getName() |
21
|
|
|
{ |
22
|
|
|
return 'config'; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @return ConfigCollectionInterface|ProxyConfigCollectionInterface |
27
|
|
|
*/ |
28
|
|
|
public function getConfigManifest() |
29
|
|
|
{ |
30
|
|
|
$configLoader = Injector::inst()->get(Kernel::class)->getConfigLoader(); |
31
|
|
|
$manifest = $configLoader->getManifest(); |
32
|
|
|
return $manifest; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function collect() |
36
|
|
|
{ |
37
|
|
|
$manifest = $this->getConfigManifest(); |
38
|
|
|
$result = []; |
39
|
|
|
if (method_exists($manifest, 'getConfigCalls')) { |
40
|
|
|
$result = $manifest->getConfigCalls(); |
41
|
|
|
} |
42
|
|
|
return [ |
43
|
|
|
'count' => count($result), |
44
|
|
|
'calls' => $result |
45
|
|
|
]; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function getWidgets() |
49
|
|
|
{ |
50
|
|
|
$widgets = [ |
51
|
|
|
'config' => [ |
52
|
|
|
'icon' => 'gear', |
53
|
|
|
'widget' => 'PhpDebugBar.Widgets.ConfigWidget', |
54
|
|
|
'map' => 'config.calls', |
55
|
|
|
'default' => '{}' |
56
|
|
|
] |
57
|
|
|
]; |
58
|
|
|
|
59
|
|
|
$widgets['config:badge'] = [ |
60
|
|
|
'map' => 'config.count', |
61
|
|
|
'default' => 0 |
62
|
|
|
]; |
63
|
|
|
|
64
|
|
|
return $widgets; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function getAssets() |
68
|
|
|
{ |
69
|
|
|
$name = $this->getName(); |
70
|
|
|
|
71
|
|
|
return [ |
72
|
|
|
'base_path' => '/' . DebugBar::moduleResource('javascript')->getRelativePath(), |
73
|
|
|
'base_url' => Director::makeRelative(DebugBar::moduleResource('javascript')->getURL()), |
74
|
|
|
'css' => $name . '/widget.css', |
75
|
|
|
'js' => $name . '/widget.js' |
76
|
|
|
]; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|