From 9daa2a6cc8e073a22c7954994183bf00e02cc353 Mon Sep 17 00:00:00 2001 From: Joseph Bielawski Date: Fri, 23 Dec 2011 09:39:25 +0100 Subject: [PATCH] [Profiler] Add function to get parent token directly --- .../HttpKernel/Profiler/FileProfilerStorage.php | 4 ++-- .../HttpKernel/Profiler/MongoDbProfilerStorage.php | 2 +- .../HttpKernel/Profiler/PdoProfilerStorage.php | 2 +- .../Component/HttpKernel/Profiler/Profile.php | 12 +++++++++++- .../HttpKernel/Profiler/FileProfilerStorageTest.php | 6 +++--- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Profiler/FileProfilerStorage.php b/src/Symfony/Component/HttpKernel/Profiler/FileProfilerStorage.php index 33a1ac49109a..5099205a952f 100644 --- a/src/Symfony/Component/HttpKernel/Profiler/FileProfilerStorage.php +++ b/src/Symfony/Component/HttpKernel/Profiler/FileProfilerStorage.php @@ -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(), @@ -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); diff --git a/src/Symfony/Component/HttpKernel/Profiler/MongoDbProfilerStorage.php b/src/Symfony/Component/HttpKernel/Profiler/MongoDbProfilerStorage.php index 4769b0cf2c9a..8328d8363444 100644 --- a/src/Symfony/Component/HttpKernel/Profiler/MongoDbProfilerStorage.php +++ b/src/Symfony/Component/HttpKernel/Profiler/MongoDbProfilerStorage.php @@ -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(), diff --git a/src/Symfony/Component/HttpKernel/Profiler/PdoProfilerStorage.php b/src/Symfony/Component/HttpKernel/Profiler/PdoProfilerStorage.php index 1322c0343d09..c87b8711f4f8 100644 --- a/src/Symfony/Component/HttpKernel/Profiler/PdoProfilerStorage.php +++ b/src/Symfony/Component/HttpKernel/Profiler/PdoProfilerStorage.php @@ -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(), diff --git a/src/Symfony/Component/HttpKernel/Profiler/Profile.php b/src/Symfony/Component/HttpKernel/Profiler/Profile.php index 0c5c866f3ea7..5caf97b71eef 100644 --- a/src/Symfony/Component/HttpKernel/Profiler/Profile.php +++ b/src/Symfony/Component/HttpKernel/Profiler/Profile.php @@ -72,7 +72,7 @@ public function setParent(Profile $parent) } /** - * Returns the parent token. + * Returns the parent profile. * * @return Profile The parent profile */ @@ -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. * diff --git a/tests/Symfony/Tests/Component/HttpKernel/Profiler/FileProfilerStorageTest.php b/tests/Symfony/Tests/Component/HttpKernel/Profiler/FileProfilerStorageTest.php index 3af6800eb758..06df6e9e9216 100644 --- a/tests/Symfony/Tests/Component/HttpKernel/Profiler/FileProfilerStorageTest.php +++ b/tests/Symfony/Tests/Component/HttpKernel/Profiler/FileProfilerStorageTest.php @@ -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(); @@ -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()