[HttpKernel] added purge() in the profiler storage interface
This commit is contained in:
parent
afa8bfcdd6
commit
ad835f8a16
@ -89,6 +89,19 @@ class Profiler
|
|||||||
return $profiler;
|
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()
|
public function export()
|
||||||
{
|
{
|
||||||
$unpack = unpack('H*', serialize(array($this->token, $this->collectors, $this->ip, $this->url, $this->time)));
|
$unpack = unpack('H*', serialize(array($this->token, $this->collectors, $this->ip, $this->url, $this->time)));
|
||||||
@ -96,6 +109,13 @@ class Profiler
|
|||||||
return $unpack[1];
|
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)
|
public function import($data)
|
||||||
{
|
{
|
||||||
list($token, $collectors, $ip, $url, $time) = unserialize(pack('H*', $data));
|
list($token, $collectors, $ip, $url, $time) = unserialize(pack('H*', $data));
|
||||||
|
@ -50,4 +50,9 @@ interface ProfilerStorageInterface
|
|||||||
* @param integer $time The time of the data
|
* @param integer $time The time of the data
|
||||||
*/
|
*/
|
||||||
function write($token, $data, $ip, $url, $time);
|
function write($token, $data, $ip, $url, $time);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Purges all data from the database.
|
||||||
|
*/
|
||||||
|
function purge();
|
||||||
}
|
}
|
||||||
|
@ -89,21 +89,24 @@ class SQLiteProfilerStorage implements ProfilerStorageInterface
|
|||||||
':time' => $time,
|
':time' => $time,
|
||||||
);
|
);
|
||||||
$this->exec($db, 'INSERT INTO data (token, data, ip, url, time) VALUES (:token, :data, :ip, :url, :time)', $args);
|
$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);
|
$this->close($db);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function purge($all = false)
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function purge()
|
||||||
{
|
{
|
||||||
$db = $this->initDb();
|
$db = $this->initDb();
|
||||||
|
|
||||||
if (true === $all) {
|
|
||||||
$this->exec($db, 'DELETE FROM data');
|
$this->exec($db, 'DELETE FROM data');
|
||||||
} else {
|
$this->close($db);
|
||||||
$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);
|
$this->close($db);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user