1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file has been created by developers from BitBag. |
5
|
|
|
* Feel free to contact us once you face any issues or want to start |
6
|
|
|
* You can find more information about us on https://bitbag.io and write us |
7
|
|
|
* an email on [email protected]. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace BitBag\SyliusCmsPlugin\DataCollector; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\HttpFoundation\Request; |
15
|
|
|
use Symfony\Component\HttpFoundation\Response; |
16
|
|
|
use Symfony\Component\HttpKernel\DataCollector\DataCollector as Collector; |
17
|
|
|
use Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface; |
18
|
|
|
|
19
|
|
|
class CMSDataCollector extends Collector implements DataCollectorInterface |
20
|
|
|
{ |
21
|
|
|
/** @var BlockRenderingEventRecorderInterface */ |
22
|
|
|
private $blockRenderingHistory; |
23
|
|
|
|
24
|
|
|
/** @var MediaRenderingEventRecorderInterface */ |
25
|
|
|
private $mediaRenderingHistory; |
26
|
|
|
|
27
|
|
|
/** @var PageRenderingEventRecorderInterface */ |
28
|
|
|
private $pageRenderingHistory; |
29
|
|
|
|
30
|
|
|
public function __construct( |
31
|
|
|
BlockRenderingEventRecorderInterface $blockRenderingHistory, |
32
|
|
|
MediaRenderingEventRecorderInterface $mediaRenderingHistory, |
33
|
|
|
PageRenderingEventRecorderInterface $pageRenderingHistory |
34
|
|
|
) { |
35
|
|
|
$this->blockRenderingHistory = $blockRenderingHistory; |
36
|
|
|
$this->mediaRenderingHistory = $mediaRenderingHistory; |
37
|
|
|
$this->pageRenderingHistory = $pageRenderingHistory; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function collect( |
41
|
|
|
Request $request, |
42
|
|
|
Response $response, |
43
|
|
|
\Throwable $exception = null |
44
|
|
|
): void { |
45
|
|
|
$this->data = [ |
46
|
|
|
'media' => $this->mediaRenderingHistory->getRecordedEvents(), |
47
|
|
|
'block' => $this->blockRenderingHistory->getRecordedEvents(), |
48
|
|
|
'page' => $this->pageRenderingHistory->getRecordedEvents(), |
49
|
|
|
]; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public static function getTemplate(): ?string |
53
|
|
|
{ |
54
|
|
|
return '@BitBagSyliusCmsPlugin/CMSDataCollector/block_collector.html.twig'; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function reset(): void |
58
|
|
|
{ |
59
|
|
|
$this->data = []; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function getMedia(): array |
63
|
|
|
{ |
64
|
|
|
return $this->data['media']; |
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function getBlock(): array |
68
|
|
|
{ |
69
|
|
|
return $this->data['block']; |
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function getPage(): array |
73
|
|
|
{ |
74
|
|
|
return $this->data['page']; |
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function getName(): string |
78
|
|
|
{ |
79
|
|
|
return 'bitbag_sylius_cms_plugin.data_collector.cms'; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|