Skip to content

Commit

Permalink
[HttpKernel] added purge() in the profiler storage interface
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Sep 1, 2010
1 parent afa8bfc commit ad835f8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
20 changes: 20 additions & 0 deletions src/Symfony/Component/HttpKernel/Profiler/Profiler.php
Expand Up @@ -89,13 +89,33 @@ public function loadFromToken($token)
return $profiler;
}

/**
* Purges all data from the storage.
*/
public function purge()
{
$this->storage->purge();
}

/**
* Exports the current profiler data.
*
* @return string The exported data
*/
public function export()
{
$unpack = unpack('H*', serialize(array($this->token, $this->collectors, $this->ip, $this->url, $this->time)));

return $unpack[1];
}

/**
* Imports data into the profiler storage.
*
* @param string $data A data string as exported by the export() method
*
* @return string The token associated with the imported data
*/
public function import($data)
{
list($token, $collectors, $ip, $url, $time) = unserialize(pack('H*', $data));
Expand Down
Expand Up @@ -50,4 +50,9 @@ function read($token);
* @param integer $time The time of the data
*/
function write($token, $data, $ip, $url, $time);

/**
* Purges all data from the database.
*/
function purge();
}
Expand Up @@ -89,21 +89,24 @@ public function write($token, $data, $ip, $url, $time)
':time' => $time,
);
$this->exec($db, 'INSERT INTO data (token, data, ip, url, time) VALUES (:token, :data, :ip, :url, :time)', $args);
$this->purge();
$this->cleanup();
$this->close($db);
}

public function purge($all = false)
/**
* {@inheritdoc}
*/
public function purge()
{
$db = $this->initDb();
$this->exec($db, 'DELETE FROM data');
$this->close($db);
}

if (true === $all) {
$this->exec($db, 'DELETE FROM data');
} else {
$args = array(':time' => time() - $this->lifetime);
$this->exec($db, 'DELETE FROM data WHERE time < :time', $args);
}

protected function cleanup()
{
$db = $this->initDb();
$this->exec($db, 'DELETE FROM data WHERE time < :time', array(':time' => time() - $this->lifetime));
$this->close($db);
}

Expand Down

0 comments on commit ad835f8

Please sign in to comment.