Skip to content

Commit ad835f8

Browse files
committed
[HttpKernel] added purge() in the profiler storage interface
1 parent afa8bfc commit ad835f8

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,33 @@ public function loadFromToken($token)
8989
return $profiler;
9090
}
9191

92+
/**
93+
* Purges all data from the storage.
94+
*/
95+
public function purge()
96+
{
97+
$this->storage->purge();
98+
}
99+
100+
/**
101+
* Exports the current profiler data.
102+
*
103+
* @return string The exported data
104+
*/
92105
public function export()
93106
{
94107
$unpack = unpack('H*', serialize(array($this->token, $this->collectors, $this->ip, $this->url, $this->time)));
95108

96109
return $unpack[1];
97110
}
98111

112+
/**
113+
* Imports data into the profiler storage.
114+
*
115+
* @param string $data A data string as exported by the export() method
116+
*
117+
* @return string The token associated with the imported data
118+
*/
99119
public function import($data)
100120
{
101121
list($token, $collectors, $ip, $url, $time) = unserialize(pack('H*', $data));

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,9 @@ function read($token);
5050
* @param integer $time The time of the data
5151
*/
5252
function write($token, $data, $ip, $url, $time);
53+
54+
/**
55+
* Purges all data from the database.
56+
*/
57+
function purge();
5358
}

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,21 +89,24 @@ public function write($token, $data, $ip, $url, $time)
8989
':time' => $time,
9090
);
9191
$this->exec($db, 'INSERT INTO data (token, data, ip, url, time) VALUES (:token, :data, :ip, :url, :time)', $args);
92-
$this->purge();
92+
$this->cleanup();
9393
$this->close($db);
9494
}
9595

96-
public function purge($all = false)
96+
/**
97+
* {@inheritdoc}
98+
*/
99+
public function purge()
97100
{
98101
$db = $this->initDb();
102+
$this->exec($db, 'DELETE FROM data');
103+
$this->close($db);
104+
}
99105

100-
if (true === $all) {
101-
$this->exec($db, 'DELETE FROM data');
102-
} else {
103-
$args = array(':time' => time() - $this->lifetime);
104-
$this->exec($db, 'DELETE FROM data WHERE time < :time', $args);
105-
}
106-
106+
protected function cleanup()
107+
{
108+
$db = $this->initDb();
109+
$this->exec($db, 'DELETE FROM data WHERE time < :time', array(':time' => time() - $this->lifetime));
107110
$this->close($db);
108111
}
109112

0 commit comments

Comments
 (0)