|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* File containing the EzPublishDataCollector class. |
|
5
|
|
|
* |
|
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
|
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
namespace eZ\Bundle\EzPublishDebugBundle\Collector; |
|
10
|
|
|
|
|
11
|
|
|
use Symfony\Component\HttpKernel\DataCollector\DataCollector; |
|
12
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
13
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
14
|
|
|
use InvalidArgumentException; |
|
15
|
|
|
use Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface; |
|
16
|
|
|
|
|
17
|
|
|
class EzPublishCoreCollector extends DataCollector |
|
18
|
|
|
{ |
|
19
|
|
|
public function __construct() |
|
20
|
|
|
{ |
|
21
|
|
|
$this->reset(); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function collect(Request $request, Response $response, \Exception $exception = null) |
|
25
|
|
|
{ |
|
26
|
|
|
/** @var DataCollectorInterface $innerCollector */ |
|
27
|
|
|
foreach ($this->data['collectors'] as $innerCollector) { |
|
28
|
|
|
$innerCollector->collect($request, $response, $exception); |
|
29
|
|
|
} |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function getName() |
|
33
|
|
|
{ |
|
34
|
|
|
return 'ezpublish.debug.toolbar'; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @param DataCollectorInterface $collector |
|
39
|
|
|
*/ |
|
40
|
|
|
public function addCollector(DataCollectorInterface $collector, $panelTemplate = null, $toolbarTemplate = null) |
|
41
|
|
|
{ |
|
42
|
|
|
$name = $collector->getName(); |
|
43
|
|
|
$this->data['collectors'][$name] = $collector; |
|
44
|
|
|
$this->data['panelTemplates'][$name] = $panelTemplate; |
|
45
|
|
|
$this->data['toolbarTemplates'][$name] = $toolbarTemplate; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @param string $name Name of the collector |
|
50
|
|
|
* |
|
51
|
|
|
* @return DataCollectorInterface |
|
52
|
|
|
* |
|
53
|
|
|
* @throws \InvalidArgumentException |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getCollector($name) |
|
56
|
|
|
{ |
|
57
|
|
|
if (!isset($this->data['collectors'][$name])) { |
|
58
|
|
|
throw new InvalidArgumentException("Invalid debug collector '$name'"); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
return $this->data['collectors'][$name]; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @return DataCollectorInterface[] |
|
66
|
|
|
*/ |
|
67
|
|
|
public function getAllCollectors() |
|
68
|
|
|
{ |
|
69
|
|
|
return $this->data['collectors']; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Returns toolbar template for given collector name. |
|
74
|
|
|
* |
|
75
|
|
|
* @param string $collectorName Name of corresponding collector. |
|
76
|
|
|
* |
|
77
|
|
|
* @return string |
|
78
|
|
|
*/ |
|
79
|
|
|
public function getToolbarTemplate($collectorName) |
|
80
|
|
|
{ |
|
81
|
|
|
if (!isset($this->data['toolbarTemplates'][$collectorName])) { |
|
82
|
|
|
return null; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
return $this->data['toolbarTemplates'][$collectorName]; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Returns panel template to use for given collector name. |
|
90
|
|
|
* |
|
91
|
|
|
* @param string $collectorName Name of corresponding collector. |
|
92
|
|
|
* |
|
93
|
|
|
* @return string |
|
94
|
|
|
*/ |
|
95
|
|
|
public function getPanelTemplate($collectorName) |
|
96
|
|
|
{ |
|
97
|
|
|
if (!isset($this->data['panelTemplates'][$collectorName])) { |
|
98
|
|
|
return null; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
return $this->data['panelTemplates'][$collectorName]; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* {@inheritdoc} |
|
106
|
|
|
*/ |
|
107
|
|
|
public function reset() |
|
108
|
|
|
{ |
|
109
|
|
|
$this->data = [ |
|
110
|
|
|
'collectors' => [], |
|
111
|
|
|
'panelTemplates' => [], |
|
112
|
|
|
'toolbarTemplates' => [], |
|
113
|
|
|
]; |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|