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

Skip to content

Commit f7cd81d

Browse files
committed
bug symfony#31059 Show more accurate message in profiler when missing stopwatch (linaori)
This PR was squashed before being merged into the 3.4 branch (closes symfony#31059). Discussion ---------- Show more accurate message in profiler when missing stopwatch | Q | A | ------------- | --- | Branch? | 3.4+ | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#31056 | License | MIT | Doc PR | ~ This adds a message to the profiler if the stopwatch component is not installed, instead of suggesting to check if debug is enabled (even if it is enabled). I had to add a method in the collector to expose the value collected, which in theory adds a feature. Is there perhaps a way to expose this collected data _without_ a "BC break"? I don't think it breaks anything, though it does make the dependencies on the http-kernel a bit strict. The other solution is to ignore if it's null and only act if it's a boolean (feature detection). Commits ------- 326aa86 Show more accurate message in profiler when missing stopwatch
2 parents 84814be + 326aa86 commit f7cd81d

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/time.html.twig

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,11 @@
9595

9696
<h2>Execution timeline</h2>
9797

98-
{% if collector.events is empty %}
98+
{% if not collector.isStopwatchInstalled() %}
99+
<div class="empty">
100+
<p>The Stopwatch component is not installed. If you want to see timing events, run: <code>composer require symfony/stopwatch</code>.</p>
101+
</div>
102+
{% elseif collector.events is empty %}
99103
<div class="empty">
100104
<p>No timing events have been recorded. Are you sure that debugging is enabled in the kernel?</p>
101105
</div>

src/Symfony/Bundle/WebProfilerBundle/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
],
1818
"require": {
1919
"php": "^5.5.9|>=7.0.8",
20-
"symfony/http-kernel": "~3.3|~4.0",
20+
"symfony/http-kernel": "~3.4.25|^4.2.6",
2121
"symfony/polyfill-php70": "~1.0",
2222
"symfony/routing": "~2.8|~3.0|~4.0",
2323
"symfony/twig-bridge": "~2.8|~3.0|~4.0",

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public function collect(Request $request, Response $response, \Exception $except
4747
'token' => $response->headers->get('X-Debug-Token'),
4848
'start_time' => $startTime * 1000,
4949
'events' => [],
50+
'stopwatch_installed' => \class_exists(Stopwatch::class, false),
5051
];
5152
}
5253

@@ -139,6 +140,14 @@ public function getStartTime()
139140
return $this->data['start_time'];
140141
}
141142

143+
/**
144+
* @return bool whether or not the stopwatch component is installed
145+
*/
146+
public function isStopwatchInstalled()
147+
{
148+
return $this->data['stopwatch_installed'];
149+
}
150+
142151
/**
143152
* {@inheritdoc}
144153
*/

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\HttpFoundation\Request;
1616
use Symfony\Component\HttpFoundation\Response;
1717
use Symfony\Component\HttpKernel\DataCollector\TimeDataCollector;
18+
use Symfony\Component\Stopwatch\Stopwatch;
1819

1920
/**
2021
* @group time-sensitive
@@ -51,5 +52,6 @@ public function testCollect()
5152

5253
$c->collect($request, new Response());
5354
$this->assertEquals(123456000, $c->getStartTime());
55+
$this->assertSame(\class_exists(Stopwatch::class, false), $c->isStopwatchInstalled());
5456
}
5557
}

0 commit comments

Comments
 (0)