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 Sylius\Bundle\UiBundle\Registry\TemplateBlock; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @internal |
20
|
|
|
*/ |
21
|
|
|
final class TemplateBlockRenderingHistory |
22
|
|
|
{ |
23
|
|
|
/** @psalm-var list<array{name: string, start: float, stop: float, time: float, blocks: list<array{definition: TemplateBlock, start: float, stop: float, time: float}>}> */ |
24
|
|
|
private $renderedEvents = []; |
25
|
|
|
|
26
|
|
|
/** @psalm-var array{name: string, start: float, stop?: float, time?: float, blocks: list<array{definition: TemplateBlock, start: float, stop: float, time: float}>} */ |
27
|
|
|
private $currentlyRenderedEvent = []; |
28
|
|
|
|
29
|
|
|
/** @psalm-var array{definition: TemplateBlock, start: float, stop?: float, time?: float} */ |
30
|
|
|
private $currentlyRenderedBlock = []; |
31
|
|
|
|
32
|
|
|
public function startRenderingEvent(string $eventName, array $context): void |
|
|
|
|
33
|
|
|
{ |
34
|
|
|
$this->currentlyRenderedEvent = ['name' => $eventName, 'start' => microtime(true), 'blocks' => []]; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function startRenderingBlock(string $eventName, TemplateBlock $templateBlock, array $context): void |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
$this->currentlyRenderedBlock = ['definition' => $templateBlock, 'start' => microtime(true)]; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function stopRenderingBlock(string $eventName, TemplateBlock $templateBlock, array $context): void |
|
|
|
|
43
|
|
|
{ |
44
|
|
|
$this->currentlyRenderedBlock['stop'] = microtime(true); |
45
|
|
|
$this->currentlyRenderedBlock['time'] = $this->currentlyRenderedBlock['stop'] - $this->currentlyRenderedBlock['start']; |
46
|
|
|
$this->currentlyRenderedEvent['blocks'][] = $this->currentlyRenderedBlock; |
47
|
|
|
$this->currentlyRenderedBlock = []; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function stopRenderingEvent(string $eventName, array $context): void |
|
|
|
|
51
|
|
|
{ |
52
|
|
|
$this->currentlyRenderedEvent['stop'] = microtime(true); |
53
|
|
|
$this->currentlyRenderedEvent['time'] = $this->currentlyRenderedEvent['stop'] - $this->currentlyRenderedEvent['start']; |
54
|
|
|
$this->renderedEvents[] = $this->currentlyRenderedEvent; |
55
|
|
|
$this->currentlyRenderedEvent = []; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function getRenderedEvents(): array |
59
|
|
|
{ |
60
|
|
|
return $this->renderedEvents; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function reset(): void |
64
|
|
|
{ |
65
|
|
|
$this->renderedEvents = $this->currentlyRenderedEvent = $this->currentlyRenderedBlock = []; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.