@@ -30,6 +30,7 @@ protected function beforeDispatch(string $eventName, $event)
30
30
{
31
31
switch ($ eventName ) {
32
32
case KernelEvents::REQUEST :
33
+ $ event ->getRequest ()->attributes ->set ('_stopwatch_token ' , substr (hash ('sha256 ' , uniqid (mt_rand (), true )), 0 , 6 ));
33
34
$ this ->stopwatch ->openSection ();
34
35
break ;
35
36
case KernelEvents::VIEW :
@@ -40,8 +41,8 @@ protected function beforeDispatch(string $eventName, $event)
40
41
}
41
42
break ;
42
43
case KernelEvents::TERMINATE :
43
- $ token = $ event ->getResponse ()->headers ->get ('X-Debug-Token ' );
44
- if (null === $ token ) {
44
+ $ sectionId = $ event ->getRequest ()->attributes ->get ('_stopwatch_token ' );
45
+ if (null === $ sectionId ) {
45
46
break ;
46
47
}
47
48
// There is a very special case when using built-in AppCache class as kernel wrapper, in the case
@@ -50,7 +51,7 @@ protected function beforeDispatch(string $eventName, $event)
50
51
// is equal to the [A] debug token. Trying to reopen section with the [B] token throws an exception
51
52
// which must be caught.
52
53
try {
53
- $ this ->stopwatch ->openSection ($ token );
54
+ $ this ->stopwatch ->openSection ($ sectionId );
54
55
} catch (\LogicException $ e ) {
55
56
}
56
57
break ;
@@ -67,21 +68,21 @@ protected function afterDispatch(string $eventName, $event)
67
68
$ this ->stopwatch ->start ('controller ' , 'section ' );
68
69
break ;
69
70
case KernelEvents::RESPONSE :
70
- $ token = $ event ->getResponse ()->headers ->get ('X-Debug-Token ' );
71
- if (null === $ token ) {
71
+ $ sectionId = $ event ->getRequest ()->attributes ->get ('_stopwatch_token ' );
72
+ if (null === $ sectionId ) {
72
73
break ;
73
74
}
74
- $ this ->stopwatch ->stopSection ($ token );
75
+ $ this ->stopwatch ->stopSection ($ sectionId );
75
76
break ;
76
77
case KernelEvents::TERMINATE :
77
78
// In the special case described in the `preDispatch` method above, the `$token` section
78
79
// does not exist, then closing it throws an exception which must be caught.
79
- $ token = $ event ->getResponse ()->headers ->get ('X-Debug-Token ' );
80
- if (null === $ token ) {
80
+ $ sectionId = $ event ->getRequest ()->attributes ->get ('_stopwatch_token ' );
81
+ if (null === $ sectionId ) {
81
82
break ;
82
83
}
83
84
try {
84
- $ this ->stopwatch ->stopSection ($ token );
85
+ $ this ->stopwatch ->stopSection ($ sectionId );
85
86
} catch (\LogicException $ e ) {
86
87
}
87
88
break ;
0 commit comments