@@ -30,6 +30,7 @@ protected function beforeDispatch(string $eventName, $event)
3030 {
3131switch ($ eventName ) {
3232case KernelEvents::REQUEST :
33+ $ event ->getRequest ()->attributes ->set ('_stopwatch_token ' ,substr (hash ('sha256 ' ,uniqid (mt_rand (),true )),0 ,6 ));
3334$ this ->stopwatch ->openSection ();
3435break ;
3536case KernelEvents::VIEW :
@@ -40,8 +41,8 @@ protected function beforeDispatch(string $eventName, $event)
4041 }
4142break ;
4243case 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 ) {
4546break ;
4647 }
4748// 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)
5051// is equal to the [A] debug token. Trying to reopen section with the [B] token throws an exception
5152// which must be caught.
5253try {
53- $ this ->stopwatch ->openSection ($ token );
54+ $ this ->stopwatch ->openSection ($ sectionId );
5455 }catch (\LogicException $ e ) {
5556 }
5657break ;
@@ -67,21 +68,21 @@ protected function afterDispatch(string $eventName, $event)
6768$ this ->stopwatch ->start ('controller ' ,'section ' );
6869break ;
6970case 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 ) {
7273break ;
7374 }
74- $ this ->stopwatch ->stopSection ($ token );
75+ $ this ->stopwatch ->stopSection ($ sectionId );
7576break ;
7677case KernelEvents::TERMINATE :
7778// In the special case described in the `preDispatch` method above, the `$token` section
7879// 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 ) {
8182break ;
8283 }
8384try {
84- $ this ->stopwatch ->stopSection ($ token );
85+ $ this ->stopwatch ->stopSection ($ sectionId );
8586 }catch (\LogicException $ e ) {
8687 }
8788break ;