Skip to content

Commit 0b4fb88

Browse files
xelarisfabpot
authored andcommitted
[HttpKernel] [WebProfilerBundle] added HTTP status to profiler search result
1 parent 5f96581 commit 0b4fb88

12 files changed

+66
-11
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
2.7.0
5+
-----
6+
7+
* added the HTTP status code to profiles
8+
49
2.6.0
510
-----
611

Profiler/BaseMemcacheProfilerStorage.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ public function find($ip, $url, $limit, $method, $start = null, $end = null)
6161
continue;
6262
}
6363

64-
list($itemToken, $itemIp, $itemMethod, $itemUrl, $itemTime, $itemParent) = explode("\t", $item, 6);
64+
$values = explode("\t", $item, 7);
65+
list($itemToken, $itemIp, $itemMethod, $itemUrl, $itemTime, $itemParent) = $values;
66+
$statusCode = isset($values[6]) ? $values[6] : null;
6567

6668
$itemTime = (int) $itemTime;
6769

@@ -84,6 +86,7 @@ public function find($ip, $url, $limit, $method, $start = null, $end = null)
8486
'url' => $itemUrl,
8587
'time' => $itemTime,
8688
'parent' => $itemParent,
89+
'status_code' => $statusCode,
8790
);
8891
--$limit;
8992
}
@@ -176,6 +179,7 @@ public function write(Profile $profile)
176179
$profile->getUrl(),
177180
$profile->getTime(),
178181
$profile->getParentToken(),
182+
$profile->getStatusCode(),
179183
))."\n";
180184

181185
return $this->appendValue($indexName, $indexRow, $this->lifetime);

Profiler/FileProfilerStorage.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ public function find($ip, $url, $limit, $method, $start = null, $end = null)
6161

6262
$result = array();
6363
while (count($result) < $limit && $line = $this->readLineFromFile($file)) {
64-
list($csvToken, $csvIp, $csvMethod, $csvUrl, $csvTime, $csvParent) = str_getcsv($line);
64+
$values = str_getcsv($line);
65+
list($csvToken, $csvIp, $csvMethod, $csvUrl, $csvTime, $csvParent) = $values;
66+
$csvStatusCode = isset($values[6]) ? $values[6] : null;
6567

6668
$csvTime = (int) $csvTime;
6769

@@ -84,6 +86,7 @@ public function find($ip, $url, $limit, $method, $start = null, $end = null)
8486
'url' => $csvUrl,
8587
'time' => $csvTime,
8688
'parent' => $csvParent,
89+
'status_code' => $csvStatusCode,
8790
);
8891
}
8992

@@ -167,6 +170,7 @@ public function write(Profile $profile)
167170
$profile->getUrl(),
168171
$profile->getTime(),
169172
$profile->getParentToken(),
173+
$profile->getStatusCode(),
170174
));
171175
fclose($file);
172176
}

Profiler/MongoDbProfilerStorage.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct($dsn, $username = '', $password = '', $lifetime = 86
3636
*/
3737
public function find($ip, $url, $limit, $method, $start = null, $end = null)
3838
{
39-
$cursor = $this->getMongo()->find($this->buildQuery($ip, $url, $method, $start, $end), array('_id', 'parent', 'ip', 'method', 'url', 'time'))->sort(array('time' => -1))->limit($limit);
39+
$cursor = $this->getMongo()->find($this->buildQuery($ip, $url, $method, $start, $end), array('_id', 'parent', 'ip', 'method', 'url', 'time', 'status_code'))->sort(array('time' => -1))->limit($limit);
4040

4141
$tokens = array();
4242
foreach ($cursor as $profile) {
@@ -83,6 +83,7 @@ public function write(Profile $profile)
8383
'method' => $profile->getMethod(),
8484
'url' => $profile->getUrl(),
8585
'time' => $profile->getTime(),
86+
'status_code' => $profile->getStatusCode(),
8687
);
8788

8889
$result = $this->getMongo()->update(array('_id' => $profile->getToken()), array_filter($record, function ($v) { return !empty($v); }), array('upsert' => true));
@@ -212,6 +213,7 @@ private function getData(array $data)
212213
'url' => isset($data['url']) ? $data['url'] : null,
213214
'time' => isset($data['time']) ? $data['time'] : null,
214215
'data' => isset($data['data']) ? $data['data'] : null,
216+
'status_code' => isset($data['status_code']) ? $data['status_code'] : null,
215217
);
216218
}
217219

Profiler/MysqlProfilerStorage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ protected function initDb()
3333
}
3434

3535
$db = new \PDO($this->dsn, $this->username, $this->password);
36-
$db->exec('CREATE TABLE IF NOT EXISTS sf_profiler_data (token VARCHAR(255) PRIMARY KEY, data LONGTEXT, ip VARCHAR(64), method VARCHAR(6), url VARCHAR(255), time INTEGER UNSIGNED, parent VARCHAR(255), created_at INTEGER UNSIGNED, KEY (created_at), KEY (ip), KEY (method), KEY (url), KEY (parent))');
36+
$db->exec('CREATE TABLE IF NOT EXISTS sf_profiler_data (token VARCHAR(255) PRIMARY KEY, data LONGTEXT, ip VARCHAR(64), method VARCHAR(6), url VARCHAR(255), time INTEGER UNSIGNED, parent VARCHAR(255), created_at INTEGER UNSIGNED, status_code SMALLINT UNSIGNED, KEY (created_at), KEY (ip), KEY (method), KEY (url), KEY (parent))');
3737

3838
$this->db = $db;
3939
}

Profiler/PdoProfilerStorage.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function find($ip, $url, $limit, $method, $start = null, $end = null)
5959
$criteria = $criteria ? 'WHERE '.implode(' AND ', $criteria) : '';
6060

6161
$db = $this->initDb();
62-
$tokens = $this->fetch($db, 'SELECT token, ip, method, url, time, parent FROM sf_profiler_data '.$criteria.' ORDER BY time DESC LIMIT '.((int) $limit), $args);
62+
$tokens = $this->fetch($db, 'SELECT token, ip, method, url, time, parent, status_code FROM sf_profiler_data '.$criteria.' ORDER BY time DESC LIMIT '.((int) $limit), $args);
6363
$this->close($db);
6464

6565
return $tokens;
@@ -94,13 +94,14 @@ public function write(Profile $profile)
9494
':url' => $profile->getUrl(),
9595
':time' => $profile->getTime(),
9696
':created_at' => time(),
97+
':status_code' => $profile->getStatusCode(),
9798
);
9899

99100
try {
100101
if ($this->has($profile->getToken())) {
101-
$this->exec($db, 'UPDATE sf_profiler_data SET parent = :parent, data = :data, ip = :ip, method = :method, url = :url, time = :time, created_at = :created_at WHERE token = :token', $args);
102+
$this->exec($db, 'UPDATE sf_profiler_data SET parent = :parent, data = :data, ip = :ip, method = :method, url = :url, time = :time, created_at = :created_at, status_code = :status_code WHERE token = :token', $args);
102103
} else {
103-
$this->exec($db, 'INSERT INTO sf_profiler_data (token, parent, data, ip, method, url, time, created_at) VALUES (:token, :parent, :data, :ip, :method, :url, :time, :created_at)', $args);
104+
$this->exec($db, 'INSERT INTO sf_profiler_data (token, parent, data, ip, method, url, time, created_at, status_code) VALUES (:token, :parent, :data, :ip, :method, :url, :time, :created_at, :status_code)', $args);
104105
}
105106
$this->cleanup();
106107
$status = true;

Profiler/Profile.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class Profile
3131
private $method;
3232
private $url;
3333
private $time;
34+
private $statusCode;
3435

3536
/**
3637
* @var Profile
@@ -171,6 +172,22 @@ public function setTime($time)
171172
$this->time = $time;
172173
}
173174

175+
/**
176+
* @param int $statusCode
177+
*/
178+
public function setStatusCode($statusCode)
179+
{
180+
$this->statusCode = $statusCode;
181+
}
182+
183+
/**
184+
* @return int
185+
*/
186+
public function getStatusCode()
187+
{
188+
return $this->statusCode;
189+
}
190+
174191
/**
175192
* Finds children profilers.
176193
*

Profiler/Profiler.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ public function collect(Request $request, Response $response, \Exception $except
202202
$profile->setUrl($request->getUri());
203203
$profile->setIp($request->getClientIp());
204204
$profile->setMethod($request->getMethod());
205+
$profile->setStatusCode($response->getStatusCode());
205206

206207
$response->headers->set('X-Debug-Token', $profile->getToken());
207208

Profiler/RedisProfilerStorage.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ public function find($ip, $url, $limit, $method, $start = null, $end = null)
7171
continue;
7272
}
7373

74-
list($itemToken, $itemIp, $itemMethod, $itemUrl, $itemTime, $itemParent) = explode("\t", $item, 6);
74+
$values = explode("\t", $item, 7);
75+
list($itemToken, $itemIp, $itemMethod, $itemUrl, $itemTime, $itemParent) = $values;
76+
$statusCode = isset($values[6]) ? $values[6] : null;
7577

7678
$itemTime = (int) $itemTime;
7779

@@ -94,6 +96,7 @@ public function find($ip, $url, $limit, $method, $start = null, $end = null)
9496
'url' => $itemUrl,
9597
'time' => $itemTime,
9698
'parent' => $itemParent,
99+
'status_code' => $statusCode,
97100
);
98101
--$limit;
99102
}
@@ -182,6 +185,7 @@ public function write(Profile $profile)
182185
$profile->getUrl(),
183186
$profile->getTime(),
184187
$profile->getParentToken(),
188+
$profile->getStatusCode(),
185189
))."\n";
186190

187191
return $this->appendValue($indexName, $indexRow, $this->lifetime);

Profiler/SqliteProfilerStorage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ protected function initDb()
4040
}
4141

4242
$db->exec('PRAGMA temp_store=MEMORY; PRAGMA journal_mode=MEMORY;');
43-
$db->exec('CREATE TABLE IF NOT EXISTS sf_profiler_data (token STRING, data STRING, ip STRING, method STRING, url STRING, time INTEGER, parent STRING, created_at INTEGER)');
43+
$db->exec('CREATE TABLE IF NOT EXISTS sf_profiler_data (token STRING, data STRING, ip STRING, method STRING, url STRING, time INTEGER, parent STRING, created_at INTEGER, status_code INTEGER)');
4444
$db->exec('CREATE INDEX IF NOT EXISTS data_created_at ON sf_profiler_data (created_at)');
4545
$db->exec('CREATE INDEX IF NOT EXISTS data_ip ON sf_profiler_data (ip)');
4646
$db->exec('CREATE INDEX IF NOT EXISTS data_method ON sf_profiler_data (method)');

0 commit comments

Comments
 (0)