Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 780e6bd

Browse files
author
jelte
committed
Extract the profiler to a new component
1 parent 791e583 commit 780e6bd

File tree

92 files changed

+8141
-2349
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+8141
-2349
lines changed

src/Symfony/Component/HttpKernel/DataCollector/ConfigDataCollector.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
* ConfigDataCollector.
2121
*
2222
* @author Fabien Potencier <[email protected]>
23+
*
24+
* @deprecated since 2.8, to be removed in 3.0. Use Symfony\Component\Profiler\DataCollector\ConfigDataCollector instead.
2325
*/
2426
class ConfigDataCollector extends DataCollector
2527
{

src/Symfony/Component/HttpKernel/DataCollector/DataCollector.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\HttpKernel\DataCollector;
1313

1414
use Symfony\Component\HttpKernel\DataCollector\Util\ValueExporter;
15+
use Symfony\Component\Profiler\DataCollector\AbstractDataCollector;
1516

1617
/**
1718
* DataCollector.
@@ -20,8 +21,10 @@
2021
*
2122
* @author Fabien Potencier <[email protected]>
2223
* @author Bernhard Schussek <[email protected]>
24+
*
25+
* @deprecated since 2.8, to be removed in 3.0. Use Symfony\Component\Profiler\DataCollector\AbstractDataCollector instead.
2326
*/
24-
abstract class DataCollector implements DataCollectorInterface, \Serializable
27+
abstract class DataCollector extends AbstractDataCollector implements DataCollectorInterface, \Serializable
2528
{
2629
protected $data = array();
2730

src/Symfony/Component/HttpKernel/DataCollector/DataCollectorInterface.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,18 @@
1313

1414
use Symfony\Component\HttpFoundation\Request;
1515
use Symfony\Component\HttpFoundation\Response;
16+
use Symfony\Component\Profiler\DataCollector\DataCollectorInterface as BaseDataCollectorInterface;
1617

1718
/**
1819
* DataCollectorInterface.
1920
*
2021
* @author Fabien Potencier <[email protected]>
2122
*
2223
* @api
24+
*
25+
* @deprecated since 2.8, to be removed in 3.0. Use Symfony\Component\Profiler\DataCollector\DataCollectorInterface instead.
2326
*/
24-
interface DataCollectorInterface
27+
interface DataCollectorInterface extends BaseDataCollectorInterface
2528
{
2629
/**
2730
* Collects data for the given Request and Response.
@@ -33,13 +36,4 @@ interface DataCollectorInterface
3336
* @api
3437
*/
3538
public function collect(Request $request, Response $response, \Exception $exception = null);
36-
37-
/**
38-
* Returns the name of the collector.
39-
*
40-
* @return string The collector name
41-
*
42-
* @api
43-
*/
44-
public function getName();
4539
}

src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
/**
2525
* @author Nicolas Grekas <[email protected]>
26+
*
27+
* @deprecated since 2.8, to be removed in 3.0. Use Symfony\Component\Profiler\DataCollector\DumpDataCollector instead.
2628
*/
2729
class DumpDataCollector extends DataCollector implements DataDumperInterface
2830
{

src/Symfony/Component/HttpKernel/DataCollector/EventDataCollector.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
* EventDataCollector.
2121
*
2222
* @author Fabien Potencier <[email protected]>
23+
*
24+
* @deprecated since 2.8, to be removed in 3.0. Use Symfony\Component\Profiler\DataCollector\EventDataCollector instead.
2325
*/
2426
class EventDataCollector extends DataCollector implements LateDataCollectorInterface
2527
{
@@ -104,4 +106,4 @@ public function getName()
104106
{
105107
return 'events';
106108
}
107-
}
109+
}

src/Symfony/Component/HttpKernel/DataCollector/ExceptionDataCollector.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* ExceptionDataCollector.
2020
*
2121
* @author Fabien Potencier <[email protected]>
22+
*
23+
* @deprecated since 2.8, to be removed in 3.0. Use Symfony\Component\Profiler\DataCollector\ExceptionDataCollector instead.
2224
*/
2325
class ExceptionDataCollector extends DataCollector
2426
{

src/Symfony/Component/HttpKernel/DataCollector/LateDataCollectorInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* LateDataCollectorInterface.
1616
*
1717
* @author Fabien Potencier <[email protected]>
18+
*
19+
* @deprecated since 2.8, to be removed in 3.0. Use Symfony\Component\Profiler\DataCollector\LateDataCollectorInterface instead.
1820
*/
1921
interface LateDataCollectorInterface
2022
{

src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* LogDataCollector.
2020
*
2121
* @author Fabien Potencier <[email protected]>
22+
*
23+
* @deprecated since 2.8, to be removed in 3.0. Use Symfony\Component\Profiler\DataCollector\LoggerDataCollector instead.
2224
*/
2325
class LoggerDataCollector extends DataCollector implements LateDataCollectorInterface
2426
{

src/Symfony/Component/HttpKernel/DataCollector/MemoryDataCollector.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
* MemoryDataCollector.
1919
*
2020
* @author Fabien Potencier <[email protected]>
21+
*
22+
* @deprecated since 2.8, to be removed in 3.0. Use Symfony\Component\Profiler\DataCollector\MemoryDataCollector instead.
2123
*/
2224
class MemoryDataCollector extends DataCollector implements LateDataCollectorInterface
2325
{

src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
* RequestDataCollector.
2525
*
2626
* @author Fabien Potencier <[email protected]>
27+
*
28+
* @deprecated since 2.8, to be removed in 3.0. Use Symfony\Component\Profiler\DataCollector\RequestDataCollector instead.
2729
*/
2830
class RequestDataCollector extends DataCollector implements EventSubscriberInterface
2931
{

src/Symfony/Component/HttpKernel/DataCollector/RouterDataCollector.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
* RouterDataCollector.
2121
*
2222
* @author Fabien Potencier <[email protected]>
23+
*
24+
* @deprecated since 2.8, to be removed in 3.0. Use Symfony\Component\Profiler\DataCollector\RouterDataCollector instead.
2325
*/
2426
class RouterDataCollector extends DataCollector
2527
{

src/Symfony/Component/HttpKernel/DataCollector/TimeDataCollector.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* TimeDataCollector.
2020
*
2121
* @author Fabien Potencier <[email protected]>
22+
*
23+
* @deprecated since 2.8, to be removed in 3.0. Use Symfony\Component\Profiler\DataCollector\TimeDataCollector instead.
2224
*/
2325
class TimeDataCollector extends DataCollector implements LateDataCollectorInterface
2426
{

src/Symfony/Component/HttpKernel/DataCollector/Util/ValueExporter.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
/**
1515
* @author Bernhard Schussek <[email protected]>
16+
*
17+
* @deprecated since 2.8, to be removed in 3.0. Use Symfony\Component\Profiler\DataCollector\Util\ValueExporter instead.
1618
*/
1719
class ValueExporter
1820
{

src/Symfony/Component/HttpKernel/EventListener/ProfilerListener.php

Lines changed: 21 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -11,72 +11,45 @@
1111

1212
namespace Symfony\Component\HttpKernel\EventListener;
1313

14-
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
15-
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
14+
use Symfony\Component\HttpFoundation\RequestMatcherInterface;
15+
use Symfony\Component\HttpFoundation\RequestStack;
1616
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
17+
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
1718
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
1819
use Symfony\Component\HttpKernel\KernelEvents;
1920
use Symfony\Component\HttpKernel\Profiler\Profiler;
20-
use Symfony\Component\HttpFoundation\RequestMatcherInterface;
21-
use Symfony\Component\HttpFoundation\RequestStack;
22-
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
21+
use Symfony\Component\Profiler\EventListener\HttpProfilerListener;
2322

2423
/**
2524
* ProfilerListener collects data for the current request by listening to the kernel events.
2625
*
2726
* @author Fabien Potencier <[email protected]>
27+
*
28+
* @deprecated since 2.8, to be removed in 3.0. Use Symfony\Component\Profiler\EventListener\HttpProfileListener instead.
2829
*/
29-
class ProfilerListener implements EventSubscriberInterface
30+
class ProfilerListener extends HttpProfilerListener
3031
{
31-
protected $profiler;
32-
protected $matcher;
33-
protected $onlyException;
34-
protected $onlyMasterRequests;
35-
protected $exception;
3632
protected $requests = array();
37-
protected $profiles;
38-
protected $requestStack;
39-
protected $parents;
4033

4134
/**
4235
* Constructor.
4336
*
44-
* @param Profiler $profiler A Profiler instance
45-
* @param RequestMatcherInterface|null $matcher A RequestMatcher instance
46-
* @param bool $onlyException true if the profiler only collects data when an exception occurs, false otherwise
47-
* @param bool $onlyMasterRequests true if the profiler only collects data when the request is a master request, false otherwise
48-
* @param RequestStack|null $requestStack A RequestStack instance
37+
* @param Profiler $profiler A Profiler instance
38+
* @param RequestMatcherInterface|null $matcher A RequestMatcher instance
39+
* @param bool $onlyException true if the profiler only collects data when an exception occurs, false otherwise
40+
* @param bool $onlyMasterRequests true if the profiler only collects data when the request is a master request, false otherwise
41+
* @param RequestStack|null $requestStack A RequestStack instance
4942
*/
5043
public function __construct(Profiler $profiler, RequestMatcherInterface $matcher = null, $onlyException = false, $onlyMasterRequests = false, RequestStack $requestStack = null)
5144
{
5245
if (null === $requestStack) {
5346
// Prevent the deprecation notice to be triggered all the time.
5447
// The onKernelRequest() method fires some logic only when the
5548
// RequestStack instance is not provided as a dependency.
56-
trigger_error('Since version 2.4, the '.__METHOD__.' method must accept a RequestStack instance to get the request instead of using the '.__CLASS__.'::onKernelRequest method that will be removed in 3.0.', E_USER_DEPRECATED);
49+
trigger_error('Since version 2.4, the ' . __METHOD__ . ' method must accept a RequestStack instance to get the request instead of using the ' . __CLASS__ . '::onKernelRequest method that will be removed in 3.0.', E_USER_DEPRECATED);
5750
}
5851

59-
$this->profiler = $profiler;
60-
$this->matcher = $matcher;
61-
$this->onlyException = (bool) $onlyException;
62-
$this->onlyMasterRequests = (bool) $onlyMasterRequests;
63-
$this->profiles = new \SplObjectStorage();
64-
$this->parents = new \SplObjectStorage();
65-
$this->requestStack = $requestStack;
66-
}
67-
68-
/**
69-
* Handles the onKernelException event.
70-
*
71-
* @param GetResponseForExceptionEvent $event A GetResponseForExceptionEvent instance
72-
*/
73-
public function onKernelException(GetResponseForExceptionEvent $event)
74-
{
75-
if ($this->onlyMasterRequests && !$event->isMasterRequest()) {
76-
return;
77-
}
78-
79-
$this->exception = $event->getException();
52+
parent::__construct($profiler, $requestStack, $matcher, $onlyException, $onlyMasterRequests);
8053
}
8154

8255
/**
@@ -113,12 +86,15 @@ public function onKernelResponse(FilterResponseEvent $event)
11386
return;
11487
}
11588

89+
$this->profiler->addResponse($request, $event->getResponse());
90+
11691
if (!$profile = $this->profiler->collect($request, $event->getResponse(), $exception)) {
11792
return;
11893
}
11994

12095
$this->profiles[$request] = $profile;
12196

97+
// "if" to be removed when requestStack is required
12298
if (null !== $this->requestStack) {
12399
$this->parents[$request] = $this->requestStack->getParentRequest();
124100
} elseif (!$master) {
@@ -131,35 +107,16 @@ public function onKernelResponse(FilterResponseEvent $event)
131107

132108
public function onKernelTerminate(PostResponseEvent $event)
133109
{
134-
// attach children to parents
135-
foreach ($this->profiles as $request) {
136-
// isset call should be removed when requestStack is required
137-
if (isset($this->parents[$request]) && null !== $parentRequest = $this->parents[$request]) {
138-
if (isset($this->profiles[$parentRequest])) {
139-
$this->profiles[$parentRequest]->addChild($this->profiles[$request]);
140-
}
141-
}
142-
}
143-
144-
// save profiles
145-
foreach ($this->profiles as $request) {
146-
$this->profiler->saveProfile($this->profiles[$request]);
147-
}
148-
149-
$this->profiles = new \SplObjectStorage();
150-
$this->parents = new \SplObjectStorage();
110+
parent::onKernelTerminate($event);
151111
$this->requests = array();
152112
}
153113

154114
public static function getSubscribedEvents()
155115
{
156-
return array(
116+
return array_merge(array(
157117
// kernel.request must be registered as early as possible to not break
158118
// when an exception is thrown in any other kernel.request listener
159-
KernelEvents::REQUEST => array('onKernelRequest', 1024),
160-
KernelEvents::RESPONSE => array('onKernelResponse', -100),
161-
KernelEvents::EXCEPTION => 'onKernelException',
162-
KernelEvents::TERMINATE => array('onKernelTerminate', -1024),
163-
);
119+
KernelEvents::REQUEST => array('onKernelRequest', 1024)
120+
), parent::getSubscribedEvents());
164121
}
165122
}

0 commit comments

Comments
 (0)