1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Sylius\Bundle\UiBundle\DataCollector; |
15
|
|
|
|
16
|
|
|
use Symfony\Component\HttpFoundation\Request; |
17
|
|
|
use Symfony\Component\HttpFoundation\Response; |
18
|
|
|
use Symfony\Component\HttpKernel\DataCollector\DataCollector; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @internal |
22
|
|
|
*/ |
23
|
|
|
final class TemplateBlockDataCollector extends DataCollector |
24
|
|
|
{ |
25
|
|
|
/** @var TemplateBlockRenderingHistory */ |
26
|
|
|
private $templateBlockRenderingHistory; |
27
|
|
|
|
28
|
|
|
public function __construct(TemplateBlockRenderingHistory $templateBlockRenderingHistory) |
29
|
|
|
{ |
30
|
|
|
$this->templateBlockRenderingHistory = $templateBlockRenderingHistory; |
31
|
|
|
$this->reset(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function collect(Request $request, Response $response): void |
35
|
|
|
{ |
36
|
|
|
$this->data['renderedEvents'] = $this->templateBlockRenderingHistory->getRenderedEvents(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function getRenderedEvents(): array |
40
|
|
|
{ |
41
|
|
|
return $this->data['renderedEvents']; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function getNumberOfRenderedEvents(): int |
45
|
|
|
{ |
46
|
|
|
return count($this->data['renderedEvents']); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function getNumberOfRenderedBlocks(): int |
50
|
|
|
{ |
51
|
|
|
return array_reduce($this->data['renderedEvents'], static function (int $accumulator, array $event): int { |
52
|
|
|
return $accumulator + count($event['blocks']); |
53
|
|
|
}, 0); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function getTotalDuration(): float |
57
|
|
|
{ |
58
|
|
|
return array_reduce($this->data['renderedEvents'], static function (float $accumulator, array $event): float { |
59
|
|
|
return $accumulator + $event['time']; |
60
|
|
|
}, 0.0); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function getName(): string |
64
|
|
|
{ |
65
|
|
|
return 'sylius_ui.template_block'; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function reset(): void |
69
|
|
|
{ |
70
|
|
|
$this->data['renderedEvents'] = []; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|