forked from jonaswouters/XhprofBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRequestListener.php
45 lines (39 loc) · 1.28 KB
/
RequestListener.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
namespace Jns\Bundle\XhprofBundle;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
/**
* RequestListener.
*
* The handle method must be connected to the core.request event.
*
* @author Jonas Wouters <[email protected]>
*/
class RequestListener
{
protected $collector;
protected $request;
public function __construct(DataCollector\XhprofCollector $collector, Request $request)
{
$this->collector = $collector;
$this->request = $request;
}
public function onCoreRequest(GetResponseEvent $event)
{
if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
$this->collector->startProfiling();
}
}
public function onCoreResponse(FilterResponseEvent $event)
{
if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
$this->collector->stopProfiling();
}
}
}