forked from ezsystems/ezpublish-kernel
/
EzPublishCoreCollector.php
112 lines (99 loc) · 3.02 KB
/
EzPublishCoreCollector.php
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
/**
* File containing the EzPublishDataCollector class.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
* @version //autogentag//
*/
namespace eZ\Bundle\EzPublishDebugBundle\Collector;
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use InvalidArgumentException;
use Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface;
class EzPublishCoreCollector extends DataCollector
{
public function __construct()
{
$this->data = [
'collectors' => [],
'panelTemplates' => [],
'toolbarTemplates' => []
];
}
public function collect( Request $request, Response $response, \Exception $exception = null )
{
/** @var DataCollectorInterface $innerCollector */
foreach ( $this->data['collectors'] as $innerCollector )
{
$innerCollector->collect( $request, $response, $exception );
}
}
public function getName()
{
return 'ezpublish.debug.toolbar';
}
/**
* @param DataCollectorInterface $collector
*/
public function addCollector( DataCollectorInterface $collector, $panelTemplate = null, $toolbarTemplate = null )
{
$name = $collector->getName();
$this->data['collectors'][$name] = $collector;
$this->data['panelTemplates'][$name] = $panelTemplate;
$this->data['toolbarTemplates'][$name] = $toolbarTemplate;
}
/**
* @param string $name Name of the collector
*
* @return DataCollectorInterface
*
* @throws \InvalidArgumentException
*/
public function getCollector( $name )
{
if ( !isset( $this->data['collectors'][$name] ) )
{
throw new InvalidArgumentException( "Invalid debug collector '$name'" );
}
return $this->data['collectors'][$name];
}
/**
* @return DataCollectorInterface[]
*/
public function getAllCollectors()
{
return $this->data['collectors'];
}
/**
* Returns toolbar template for given collector name.
*
* @param string $collectorName Name of corresponding collector.
*
* @return string
*/
public function getToolbarTemplate( $collectorName )
{
if ( !isset( $this->data['toolbarTemplates'][$collectorName] ) )
{
return null;
}
return $this->data['toolbarTemplates'][$collectorName];
}
/**
* Returns panel template to use for given collector name.
*
* @param string $collectorName Name of corresponding collector.
*
* @return string
*/
public function getPanelTemplate( $collectorName )
{
if ( !isset( $this->data['panelTemplates'][$collectorName] ) )
{
return null;
}
return $this->data['panelTemplates'][$collectorName];
}
}