33namespace M6Web \Bundle \StatsdBundle \Statsd ;
44
55use Symfony \Component \Console \Event \ConsoleTerminateEvent ;
6- use Symfony \Component \EventDispatcher \EventDispatcherInterface ;
7- use Symfony \Component \HttpKernel \Event \GetResponseForExceptionEvent ;
8- use Symfony \Component \HttpKernel \Event \PostResponseEvent ;
6+ use Symfony \Contracts \EventDispatcher \EventDispatcherInterface ;
7+ use Symfony \Component \HttpKernel \Event \ExceptionEvent ;
8+ use Symfony \Component \HttpKernel \Event \TerminateEvent ;
99use Symfony \Component \HttpKernel \Exception \HttpExceptionInterface ;
1010
1111use M6Web \Component \Statsd \Client ;
@@ -32,30 +32,30 @@ public function __construct(Client $statsdClient, EventDispatcherInterface $even
3232 /**
3333 * onKernelException
3434 *
35- * @param GetResponseForExceptionEvent $event
35+ * @param ExceptionEvent $event
3636 */
37- public function onKernelException (GetResponseForExceptionEvent $ event )
37+ public function onKernelException (ExceptionEvent $ event )
3838 {
39- $ exception = $ event ->getException ();
39+ $ exception = $ event ->getThrowable ();
4040 if ($ exception instanceof HttpExceptionInterface) {
41- $ code = $ event ->getException ()->getStatusCode ();
41+ $ code = $ event ->getThrowable ()->getStatusCode ();
4242 } else {
4343 $ code = 'unknown ' ;
4444 }
4545 $ this ->eventDispatcher ->dispatch (
46- ' statsd.exception ' ,
47- new StatsdEvent ( $ code )
46+ new StatsdEvent ( $ code ) ,
47+ ' statsd.exception '
4848 );
4949 }
5050
5151 /**
5252 * method called on the kernel.terminate event
5353 *
54- * @param PostResponseEvent $event event
54+ * @param TerminateEvent $event event
5555 *
5656 * @return void
5757 */
58- public function onKernelTerminate (PostResponseEvent $ event )
58+ public function onKernelTerminate (TerminateEvent $ event )
5959 {
6060 $ this ->statsdClient ->send ();
6161 }
@@ -76,9 +76,9 @@ public function onConsoleTerminate(ConsoleTerminateEvent $event)
7676 * method called if base_collectors = true in config to dispatch base events
7777 * (you still have to catch them)
7878 *
79- * @param PostResponseEvent $event
79+ * @param TerminateEvent $event
8080 */
81- public function dispatchBaseEvents (PostResponseEvent $ event )
81+ public function dispatchBaseEvents (TerminateEvent $ event )
8282 {
8383 $ this ->dispatchMemory ();
8484 $ this ->dispatchRequestTime ($ event );
@@ -93,8 +93,8 @@ private function dispatchMemory()
9393 $ memory = ($ memory > 1024 ? intval ($ memory / 1024 ) : 0 );
9494
9595 $ this ->eventDispatcher ->dispatch (
96- ' statsd.memory_usage ' ,
97- new StatsdEvent ( $ memory )
96+ new StatsdEvent ( $ memory ) ,
97+ ' statsd.memory_usage '
9898 );
9999 }
100100
@@ -103,18 +103,18 @@ private function dispatchMemory()
103103 * This time is a "fake" one, because some actions are performed before the initialization of the request
104104 * It is ~100ms smaller than the real kernel time.
105105 *
106- * @param PostResponseEvent $event
106+ * @param TerminateEvent $event
107107 */
108- private function dispatchRequestTime (PostResponseEvent $ event )
108+ private function dispatchRequestTime (TerminateEvent $ event )
109109 {
110110 $ request = $ event ->getRequest ();
111111 $ startTime = $ request ->server ->get ('REQUEST_TIME_FLOAT ' , $ request ->server ->get ('REQUEST_TIME ' ));
112112 $ time = microtime (true ) - $ startTime ;
113113 $ time = round ($ time * 1000 );
114114
115115 $ this ->eventDispatcher ->dispatch (
116- ' statsd. time' ,
117- new StatsdEvent ( $ time)
116+ new StatsdEvent ( $ time) ,
117+ ' statsd. time'
118118 );
119119 }
120120}
0 commit comments