10000 [Profiler] Add function to get parent token directly · mshtukin/symfony@9daa2a6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9daa2a6

Browse files
committed
[Profiler] Add function to get parent token directly
1 parent d635be4 commit 9daa2a6

File tree

5 files changed

+18
-8
lines changed

5 files changed

+18
-8
lines changed

src/Symfony/Component/HttpKernel/Profiler/FileProfilerStorage.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public function write(Profile $profile)
140140
// Store profile
141141
$data = array(
142142
'token' => $profile->getToken(),
143-
'parent' => $profile->getParent() ? $profile->getParent()->getToken() : null,
143+
'parent' => $profile->getParentToken(),
144144
'children' => array_map(function ($p) { return $p->getToken(); }, $profile->getChildren()),
145145
'data' => $profile->getCollectors(),
146146
'ip' => $profile->getIp(),
@@ -164,7 +164,7 @@ public function write(Profile $profile)
164164
$profile->getMethod(),
165165
$profile->getUrl(),
166166
$profile->getTime(),
167-
$profile->getParent() ? $profile->getParent()->getToken() : null,
167+
$profile->getParentToken(),
168168
));
169169
fclose($file);
170170

src/Symfony/Component/HttpKernel/Profiler/MongoDbProfilerStorage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function write(Profile $profile)
9090

9191
$record = array(
9292
'_id' => $profile->getToken(),
93-
'parent' => $profile->getParent() ? $profile->getParent()->getToken() : null,
93+
'parent' => $profile->getParentToken(),
9494
'data' => serialize($profile->getCollectors()),
9595
'ip' => $profile->getIp(),
9696
'method' => $profile->getMethod(),

src/Symfony/Component/HttpKernel/Profiler/PdoProfilerStorage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function write(Profile $profile)
8282
$db = $this->initDb();
8383
$args = array(
8484
':token' => $profile->getToken(),
85-
':parent' => $profile->getParent() ? $profile->getParent()->getToken() : '',
85+
':parent' => $profile->getParentToken(),
8686
':data' => base64_encode(serialize($profile->getCollectors())),
8787
':ip' => $profile->getIp(),
8888
':method' => $profile->getMethod(),

src/Symfony/Component/HttpKernel/Profiler/Profile.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function setParent(Profile $parent)
7272
}
7373

7474
/**
75-
* Returns the parent token.
75+
* Returns the parent profile.
7676
*
7777
* @return Profile The parent profile
7878
*/
@@ -81,6 +81,16 @@ public function getParent()
8181
return $this->parent;
8282
}
8383

84+
/**
85+
* Returns the parent token.
86+
*
87+
* @return null|string The parent token
88+
*/
89+
public function getParentToken()
90+
{
91+
return $this->parent ? $this->parent->getToken() : null;
92+
}
93+
8494
/**
8595
* Returns the IP.
8696
*

tests/Symfony/Tests/Component/HttpKernel/Profiler/FileProfilerStorageTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function testChildren()
8585

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

9090
// Check parent has child
9191
$children = $parentProfile->getChildren();
@@ -122,8 +122,8 @@ public function testStoreDuplicateToken()
122122
{
123123
$profile = new Profile('token');
124124

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

129129
public function testRetrieveByIp()

0 commit comments

Comments
 (0)
0