/**
  * {@inheritdoc}
  */
 protected function createProfileFromData($token, $data, $parent = NULL)
 {
     $profile = new Profile($token);
     $profile->setIp($data['ip']);
     $profile->setMethod($data['method']);
     $profile->setUrl($data['url']);
     $profile->setTime($data['time']);
     $profile->setCollectors($data['data']);
     return $profile;
 }
 public function testCleanup()
 {
     $dt = new \DateTime('-2 day');
     for ($i = 0; $i < 3; ++$i) {
         $dt->modify('-1 day');
         $profile = new Profile('time_' . $i);
         $profile->setTime($dt->getTimestamp());
         $profile->setMethod('GET');
         self::$storage->write($profile);
     }
     $records = self::$storage->find('', '', 3, 'GET');
     $this->assertCount(1, $records, '->find() returns only one record');
     $this->assertEquals($records[0]['token'], 'time_2', '->find() returns the latest added record');
     self::$storage->purge();
 }
 /**
  * @param boolean $secure
  * @dataProvider getSecureInsecure
  */
 public function testOk($secure)
 {
     $listener = new DebugResponseListener(['enabled' => true, 'key_name' => '_debug']);
     $listener->setProfilerListener($this->profileListener);
     $listener->addConverter(new FooConverter());
     $response = new Response(json_encode(['some' => ['data']]), 200, ['Content-Type' => 'application/json', 'X-Debug-Token-Link' => '/token']);
     $request = new Request([], [], [], [], [], ['SERVER_NAME' => 'foobar.test', 'SERVER_PORT' => $secure ? 443 : 80, 'HTTPS' => $secure ? 'on' : 'off']);
     $profile = new Profile('token');
     $profile->addCollector(new TimeDataCollector());
     $profile->setIp('8.8.8.8');
     $profile->setMethod(Request::METHOD_HEAD);
     $profile->setUrl('/some/url');
     $profile->setStatusCode(Response::HTTP_I_AM_A_TEAPOT);
     $profile->setTime(1000000);
     $this->profiles[$request] = $profile;
     $listener->onKernelResponse($this->getEvent($request, $response));
     $debugResponse = json_decode($response->getContent(), true);
     $this->assertEquals(['some' => ['data'], '_debug' => ['tokenUrl' => $secure ? 'https://foobar.test/token' : 'http://foobar.test/token', 'ip' => '8.8.8.8', 'method' => Request::METHOD_HEAD, 'url' => '/some/url', 'time' => date('c', 1000000), 'statusCode' => Response::HTTP_I_AM_A_TEAPOT, 'foo' => 'bar']], $debugResponse);
 }
 public function testStoreTime()
 {
     $dt = new \DateTime('now');
     $start = $dt->getTimestamp();
     for ($i = 0; $i < 3; $i++) {
         $dt->modify('+1 minute');
         $profile = new Profile('time_' . $i);
         $profile->setIp('127.0.0.1');
         $profile->setUrl('http://foo.bar');
         $profile->setTime($dt->getTimestamp());
         $profile->setMethod('GET');
         $this->getStorage()->write($profile);
     }
     $records = $this->getStorage()->find('', '', 3, 'GET', $start, time() + 3 * 60);
     $this->assertCount(3, $records, '->find() returns all previously added records');
     $this->assertEquals($records[0]['token'], 'time_2', '->find() returns records ordered by time in descendant order');
     $this->assertEquals($records[1]['token'], 'time_1', '->find() returns records ordered by time in descendant order');
     $this->assertEquals($records[2]['token'], 'time_0', '->find() returns records ordered by time in descendant order');
     $records = $this->getStorage()->find('', '', 3, 'GET', $start, time() + 2 * 60);
     $this->assertCount(2, $records, '->find() should return only first two of the previously added records');
 }
Esempio n. 5
0
 private function createProfileFromData($token, $data, $parent = null)
 {
     $profile = new Profile($token);
     $profile->setIp($data['ip']);
     $profile->setMethod($data['method']);
     $profile->setUrl($data['url']);
     $profile->setTime($data['time']);
     $profile->setCollectors($data['data']);
     if (!$parent && $data['parent']) {
         $parent = $this->read($data['parent']);
     }
     if ($parent) {
         $profile->setParent($parent);
     }
     foreach ($data['children'] as $token) {
         if (!$token) {
             continue;
         }
         if (!($childProfileData = $this->getValue($this->getItemName($token), self::REDIS_SERIALIZER_PHP))) {
             continue;
         }
         $profile->addChild($this->createProfileFromData($token, $childProfileData, $profile));
     }
     return $profile;
 }
 /**
  * Collects data for the given Response.
  *
  * @param Request    $request   A Request instance
  * @param Response   $response  A Response instance
  * @param \Exception $exception An exception instance if the request threw one
  *
  * @return Profile|null A Profile instance or null if the profiler is disabled
  */
 public function collect(Request $request, Response $response, \Exception $exception = null)
 {
     if (false === $this->enabled) {
         return;
     }
     $profile = new Profile(substr(sha1(uniqid(mt_rand(), true)), 0, 6));
     $profile->setTime(time());
     $profile->setUrl($request->getUri());
     $profile->setIp($request->getClientIp());
     $profile->setMethod($request->getMethod());
     $response->headers->set('X-Debug-Token', $profile->getToken());
     foreach ($this->collectors as $collector) {
         $collector->collect($request, $response, $exception);
         // forces collectors to become "read/only" (they loose their object dependencies)
         $profile->addCollector(unserialize(serialize($collector)));
     }
     return $profile;
 }
 /**
  * @param string $token
  * @param $data
  *
  * @return Profile
  */
 private function createProfileFromData($token, $data)
 {
     $profile = new Profile($token);
     $profile->setIp($data->ip);
     $profile->setMethod($data->method);
     $profile->setUrl($data->url);
     $profile->setTime($data->time);
     $profile->setCollectors(unserialize(base64_decode($data->data)));
     return $profile;
 }
Esempio n. 8
0
 /**
  * Collects data for the given Response.
  *
  * @param Request    $request   A Request instance
  * @param Response   $response  A Response instance
  * @param \Exception $exception An exception instance if the request threw one
  *
  * @return Profile|null A Profile instance or null if the profiler is disabled
  */
 public function collect(Request $request, Response $response, \Exception $exception = null)
 {
     if (false === $this->enabled) {
         return;
     }
     $profile = new Profile(substr(hash('sha256', uniqid(mt_rand(), true)), 0, 6));
     $profile->setTime(time());
     $profile->setUrl($request->getUri());
     $profile->setIp($request->getClientIp());
     $profile->setMethod($request->getMethod());
     $profile->setStatusCode($response->getStatusCode());
     $response->headers->set('X-Debug-Token', $profile->getToken());
     foreach ($this->collectors as $collector) {
         $collector->collect($request, $response, $exception);
         // we need to clone for sub-requests
         $profile->addCollector(clone $collector);
     }
     return $profile;
 }
 protected function createProfileFromData($token, $data, $parent = null)
 {
     $profile = new Profile($token);
     $profile->setIp($data['ip']);
     $profile->setUrl($data['url']);
     $profile->setTime($data['time']);
     $profile->setCollectors(unserialize(base64_decode($data['data'])));
     if (!$parent && isset($data['parent']) && $data['parent']) {
         $parent = $this->read($data['parent']);
     }
     if ($parent) {
         $profile->setParent($parent);
     }
     $profile->setChildren($this->readChildren($token, $profile));
     return $profile;
 }
Esempio n. 10
0
 /**
  * Collects data for the given Response.
  *
  * @param Request    $request   A Request instance
  * @param Response   $response  A Response instance
  * @param \Exception $exception An exception instance if the request threw one
  *
  * @return Profile|false A Profile instance or false if the profiler is disabled
  */
 public function collect(Request $request, Response $response, \Exception $exception = null)
 {
     if (false === $this->enabled) {
         return;
     }
     $profile = new Profile(uniqid());
     $profile->setTime(time());
     $profile->setUrl($request->getUri());
     $profile->setIp($request->server->get('REMOTE_ADDR'));
     $response->headers->set('X-Debug-Token', $profile->getToken());
     $collectors = array();
     foreach ($this->collectors as $name => $collector) {
         $collector->collect($request, $response, $exception);
         // forces collectors to become "read/only" (they loose their object dependencies)
         $profile->addCollector(unserialize(serialize($collector)));
     }
     return $profile;
 }