1 | <?php |
||
19 | class RequestListener |
||
20 | { |
||
21 | protected $collector; |
||
22 | private $container; |
||
23 | |||
24 | 12 | public function __construct(XhprofCollector $collector, ContainerInterface $container) |
|
25 | { |
||
26 | 12 | $this->collector = $collector; |
|
27 | 12 | $this->container = $container; |
|
28 | 12 | } |
|
29 | |||
30 | /** |
||
31 | * Start the profiler if |
||
32 | * - this is not a sub-request but the master request |
||
33 | * - we are not on the _wdt or _profiler url |
||
34 | * - if the query argument name is configured, only if it is present in the request |
||
35 | * - if the url does not match one of the exclude patterns |
||
36 | * |
||
37 | * @param GetResponseEvent $event |
||
38 | */ |
||
39 | 8 | public function onCoreRequest(GetResponseEvent $event) |
|
40 | { |
||
41 | 8 | if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { |
|
42 | 1 | return; |
|
43 | } |
||
44 | |||
45 | 7 | $request = $event->getRequest(); |
|
46 | 7 | $requestQueryArgument = $this->container->getParameter('jns_xhprof.request_query_argument'); |
|
47 | 7 | if ($requestQueryArgument && is_null($request->query->get($requestQueryArgument))) { |
|
48 | 1 | return; |
|
49 | 6 | } elseif ($requestQueryArgument) { |
|
50 | 1 | $request->query->remove($requestQueryArgument); |
|
51 | 1 | } |
|
52 | |||
53 | 6 | $uri = $request->getRequestUri(); |
|
54 | |||
55 | 6 | if (false !== strpos($uri, "_wdt") || false !== strpos($uri, "_profiler")) { |
|
56 | 4 | return; |
|
57 | } |
||
58 | |||
59 | 2 | if ($excludePatterns = $this->container->getParameter('jns_xhprof.exclude_patterns')) { |
|
60 | 2 | foreach ($excludePatterns as $exclude) { |
|
61 | 2 | if (preg_match('@' . $exclude . '@', $uri)) { |
|
62 | 1 | return; |
|
63 | } |
||
64 | 1 | } |
|
65 | 1 | } |
|
66 | |||
67 | 1 | $this->collector->startProfiling($request); |
|
68 | 1 | } |
|
69 | |||
70 | /** |
||
71 | * Trigger ending the profiling if we end the master request. If the debug |
||
72 | * toolbar is active, this happens after XhprofCollector::collect, and thus |
||
73 | * the collector will return false. |
||
74 | * |
||
75 | * If the collector returns something, we put that into the special header |
||
76 | * to let the user identify the profiler run. |
||
77 | * |
||
78 | * @param FilterResponseEvent $event |
||
79 | */ |
||
80 | 4 | public function onCoreResponse(FilterResponseEvent $event) |
|
97 | } |
||
98 |