Skip to content

Commit

Permalink
Use REQUEST_TIME_FLOAT if available.
Browse files Browse the repository at this point in the history
This will give a more correct initialization time when using the
DataCollectors without a KernelInterface implementation such as Silex.
  • Loading branch information
henrikbjorn committed Feb 5, 2013
1 parent 223cc6f commit bd0709c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
Expand Up @@ -35,8 +35,12 @@ public function __construct(KernelInterface $kernel = null)
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
{
if (null === $this->kernel) {
$requestTime = $request->server->get('REQUEST_TIME_FLOAT', $request->server->get('REQUEST_TIME'));
}

$this->data = array(
'start_time' => (null !== $this->kernel ? $this->kernel->getStartTime() : $_SERVER['REQUEST_TIME']) * 1000,
'start_time' => (isset($requestTime) ? $requestTime : $this->kernel->getStartTime()) * 1000,
'events' => array(),
);
}
Expand Down
@@ -0,0 +1,45 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\HttpKernel\Tests\DataCollector;

use Symfony\Component\HttpKernel\DataCollector\TimeDataCollector;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class TimeDataCollectorTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
if (!class_exists('Symfony\Component\HttpFoundation\Request')) {
$this->markTestSkipped('The "HttpFoundation" component is not available');
}
}

public function testCollectWithoutKernel()
{
$c = new TimeDataCollector;

$request = new Request();
$request->server->set('REQUEST_TIME', 1);

$c->collect($request, new Response());

$this->assertEquals(1000, $c->getStartTime());

$request->server->set('REQUEST_TIME_FLOAT', 2);

$c->collect($request, new Response());

$this->assertEquals(2000, $c->getStartTime());
}

}

0 comments on commit bd0709c

Please sign in to comment.