Skip to content

Commit

Permalink
[Profiler] Add function to get parent token directly
Browse files Browse the repository at this point in the history
  • Loading branch information
stloyd committed Dec 23, 2011
1 parent d635be4 commit 9daa2a6
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
Expand Up @@ -140,7 +140,7 @@ public function write(Profile $profile)
// Store profile
$data = array(
'token' => $profile->getToken(),
'parent' => $profile->getParent() ? $profile->getParent()->getToken() : null,
'parent' => $profile->getParentToken(),
'children' => array_map(function ($p) { return $p->getToken(); }, $profile->getChildren()),
'data' => $profile->getCollectors(),
'ip' => $profile->getIp(),
Expand All @@ -164,7 +164,7 @@ public function write(Profile $profile)
$profile->getMethod(),
$profile->getUrl(),
$profile->getTime(),
$profile->getParent() ? $profile->getParent()->getToken() : null,
$profile->getParentToken(),
));
fclose($file);

Expand Down
Expand Up @@ -90,7 +90,7 @@ public function write(Profile $profile)

$record = array(
'_id' => $profile->getToken(),
'parent' => $profile->getParent() ? $profile->getParent()->getToken() : null,
'parent' => $profile->getParentToken(),
'data' => serialize($profile->getCollectors()),
'ip' => $profile->getIp(),
'method' => $profile->getMethod(),
Expand Down
Expand Up @@ -82,7 +82,7 @@ public function write(Profile $profile)
$db = $this->initDb();
$args = array(
':token' => $profile->getToken(),
':parent' => $profile->getParent() ? $profile->getParent()->getToken() : '',
':parent' => $profile->getParentToken(),
':data' => base64_encode(serialize($profile->getCollectors())),
':ip' => $profile->getIp(),
':method' => $profile->getMethod(),
Expand Down
12 changes: 11 additions & 1 deletion src/Symfony/Component/HttpKernel/Profiler/Profile.php
Expand Up @@ -72,7 +72,7 @@ public function setParent(Profile $parent)
}

/**
* Returns the parent token.
* Returns the parent profile.
*
* @return Profile The parent profile
*/
Expand All @@ -81,6 +81,16 @@ public function getParent()
return $this->parent;
}

/**
* Returns the parent token.
*
* @return null|string The parent token
*/
public function getParentToken()
{
return $this->parent ? $this->parent->getToken() : null;
}

/**
* Returns the IP.
*
Expand Down
Expand Up @@ -85,7 +85,7 @@ public function testChildren()

// Check child has link to parent
$this->assertNotNull($childProfile->getParent());
$this->assertEquals($parentProfile->getToken(), $childProfile->getParent()->getToken());
$this->assertEquals($parentProfile->getToken(), $childProfile->getParentToken());

// Check parent has child
$children = $parentProfile->getChildren();
Expand Down Expand Up @@ -122,8 +122,8 @@ public function testStoreDuplicateToken()
{
$profile = new Profile('token');

$this->assertTrue(true === self::$storage->write($profile), '->write() returns true when the token is unique');
$this->assertTrue(true === self::$storage->write($profile), '->write() overwrites when the token is already present in the DB');
$this->assertTrue(self::$storage->write($profile), '->write() returns true when the token is unique');
$this->assertTrue(self::$storage->write($profile), '->write() overwrites when the token is already present in the DB');
}

public function testRetrieveByIp()
Expand Down

0 comments on commit 9daa2a6

Please sign in to comment.