8000 merged branch henrikbjorn/time-collector (PR #6971) · 77web/symfony@eb2bcc5 · GitHub
[go: up one dir, main page]

Skip to content

Commit eb2bcc5

Browse files
committed
merged branch henrikbjorn/time-collector (PR symfony#6971)
This PR was merged into the master branch. Commits ------- bd0709c Use REQUEST_TIME_FLOAT if available. Discussion ---------- Use REQUEST_TIME_FLOAT if available. This will give a more correct initialization time when using the DataCollectors without a KernelInterface implementation such as Silex. `REQUEST_TIME_FLOAT` is available as of 5.4.0 --------------------------------------------------------------------------- by henrikbjorn at 2013-02-05T09:59:05Z @fabpot Should be good now with passing test :)
2 parents 223cc6f + bd0709c commit eb2bcc5

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@ public function __construct(KernelInterface $kernel = null)
3535
*/
3636
public function collect(Request $request, Response $response, \Exception $exception = null)
3737
{
38+
if (null === $this->kernel) {
39+
$requestTime = $request->server->get('REQUEST_TIME_FLOAT', $request->server->get('REQUEST_TIME'));
40+
}
41+
3842
$this->data = array(
39-
'start_time' => (null !== $this->kernel ? $this->kernel->getStartTime() : $_SERVER['REQUEST_TIME']) * 1000,
43+
'start_time' => (isset($requestTime) ? $requestTime : $this->kernel->getStartTime()) * 1000,
4044
'events' => array(),
4145
);
4246
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\HttpKernel\Tests\DataCollector;
13+
14+
use Symfony\Component\HttpKernel\DataCollector\TimeDataCollector;
15+
use Symfony\Component\HttpFoundation\Request;
16+
use Symfony\Component\HttpFoundation\Response;
17+
18+
class TimeDataCollectorTest extends \PHPUnit_Framework_TestCase
19+
{
20+
protected function setUp()
21+
{
22+
if (!class_exists('Symfony\Component\HttpFoundation\Request')) {
23+
$this->markTestSkipped('The "HttpFoundation" component is not available');
24+
}
25+
}
26+
27+
public function testCollectWithoutKernel()
28+
{
29+
$c = new TimeDataCollector;
30+
31+
$request = new Request();
32+
$request->server->set('REQUEST_TIME', 1);
33+
34+
$c->collect($request, new Response());
35+
36+
$this->assertEquals(1000, $c->getStartTime());
37+
38+
$request->server->set('REQUEST_TIME_FLOAT', 2);
39+
40+
$c->collect($request, new Response());
41+
42+
$this->assertEquals(2000, $c->getStartTime());
43+
}
44+
45+
}

0 commit comments

Comments
 (0)
0