merged branch stloyd/profile_simplify (PR #2950)

Commits
-------

9daa2a6 [Profiler] Add function to get parent token directly

Discussion
----------

[Profiler] Add function to get parent token directly

```
Bug fix: no
Feature addition: kinda
Backwards compatibility break: no
Symfony2 tests pass: yes
This commit is contained in:
Fabien Potencier 2011-12-24 09:13:41 +01:00
commit d149aa7b2b
5 changed files with 18 additions and 8 deletions

View File

@ -140,7 +140,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
// Store profile // Store profile
$data = array( $data = array(
'token' => $profile->getToken(), 'token' => $profile->getToken(),
'parent' => $profile->getParent() ? $profile->getParent()->getToken() : null, 'parent' => $profile->getParentToken(),
'children' => array_map(function ($p) { return $p->getToken(); }, $profile->getChildren()), 'children' => array_map(function ($p) { return $p->getToken(); }, $profile->getChildren()),
'data' => $profile->getCollectors(), 'data' => $profile->getCollectors(),
'ip' => $profile->getIp(), 'ip' => $profile->getIp(),
@ -164,7 +164,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
$profile->getMethod(), $profile->getMethod(),
$profile->getUrl(), $profile->getUrl(),
$profile->getTime(), $profile->getTime(),
$profile->getParent() ? $profile->getParent()->getToken() : null, $profile->getParentToken(),
)); ));
fclose($file); fclose($file);

View File

@ -90,7 +90,7 @@ class MongoDbProfilerStorage implements ProfilerStorageInterface
$record = array( $record = array(
'_id' => $profile->getToken(), '_id' => $profile->getToken(),
'parent' => $profile->getParent() ? $profile->getParent()->getToken() : null, 'parent' => $profile->getParentToken(),
'data' => serialize($profile->getCollectors()), 'data' => serialize($profile->getCollectors()),
'ip' => $profile->getIp(), 'ip' => $profile->getIp(),
'method' => $profile->getMethod(), 'method' => $profile->getMethod(),

View File

@ -82,7 +82,7 @@ abstract class PdoProfilerStorage implements ProfilerStorageInterface
$db = $this->initDb(); $db = $this->initDb();
$args = array( $args = array(
':token' => $profile->getToken(), ':token' => $profile->getToken(),
':parent' => $profile->getParent() ? $profile->getParent()->getToken() : '', ':parent' => $profile->getParentToken(),
':data' => base64_encode(serialize($profile->getCollectors())), ':data' => base64_encode(serialize($profile->getCollectors())),
':ip' => $profile->getIp(), ':ip' => $profile->getIp(),
':method' => $profile->getMethod(), ':method' => $profile->getMethod(),

View File

@ -72,7 +72,7 @@ class Profile implements \Serializable
} }
/** /**
* Returns the parent token. * Returns the parent profile.
* *
* @return Profile The parent profile * @return Profile The parent profile
*/ */
@ -81,6 +81,16 @@ class Profile implements \Serializable
return $this->parent; 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. * Returns the IP.
* *

View File

@ -85,7 +85,7 @@ class FileProfilerStorageTest extends \PHPUnit_Framework_TestCase
// Check child has link to parent // Check child has link to parent
$this->assertNotNull($childProfile->getParent()); $this->assertNotNull($childProfile->getParent());
$this->assertEquals($parentProfile->getToken(), $childProfile->getParent()->getToken()); $this->assertEquals($parentProfile->getToken(), $childProfile->getParentToken());
// Check parent has child // Check parent has child
$children = $parentProfile->getChildren(); $children = $parentProfile->getChildren();
@ -122,8 +122,8 @@ class FileProfilerStorageTest extends \PHPUnit_Framework_TestCase
{ {
$profile = new Profile('token'); $profile = new Profile('token');
$this->assertTrue(true === self::$storage->write($profile), '->write() returns true when the token is unique'); $this->assertTrue(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() overwrites when the token is already present in the DB');
} }
public function testRetrieveByIp() public function testRetrieveByIp()