fixed coding standard

This commit is contained in:
Jan Schumann 2011-03-14 15:53:03 +01:00
parent d1ebc8da9f
commit bbfb1ffb53
3 changed files with 66 additions and 51 deletions

View File

@ -23,14 +23,12 @@ class MysqlProfilerStorage extends PdoProfilerStorage
*/
protected function initDb()
{
if (is_null($this->db))
{
if ('mysql' !== substr($this->dsn, 0, 5))
{
throw new \RuntimeException('Please check your configuration. You are trying to use Mysql with a wrong dsn. "' . $this->dsn . '"');
}
if (is_null($this->db)) {
if ('mysql' !== substr($this->dsn, 0, 5)) {
throw new \RuntimeException('Please check your configuration. You are trying to use Mysql with a wrong dsn. "' . $this->dsn . '"');
}
if (!class_exists('PDO') || !in_array('mysql', \PDO::getAvailableDrivers(), true)) {
if ( ! class_exists('PDO') || ! in_array('mysql', \PDO::getAvailableDrivers(), true)) {
throw new \RuntimeException('You need to enable PDO_Mysql extension for the profiler to run properly.');
}
@ -42,4 +40,25 @@ class MysqlProfilerStorage extends PdoProfilerStorage
return $this->db;
}
/**
* {@inheritdoc}
*/
protected function buildCriteria($ip, $url, $limit)
{
$criteria = array();
$args = array();
if ($ip = preg_replace('/[^\d\.]/', '', $ip)) {
$criteria[] = 'ip LIKE :ip';
$args[':ip'] = '%' . $ip . '%';
}
if ($url) {
$criteria[] = 'url LIKE :url';
$args[':url'] = '%' . addcslashes($url, '%_\\') . '%';
}
return array($criteria, $args);
}
}

View File

@ -16,6 +16,7 @@ use Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface;
/**
* Base PDO storage for profiling information in a PDO database.
*
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @author Jan Schumann <js@schumann-it.com>
*/
abstract class PdoProfilerStorage implements ProfilerStorageInterface
@ -58,24 +59,6 @@ abstract class PdoProfilerStorage implements ProfilerStorageInterface
return $tokens;
}
protected function buildCriteria($ip, $url, $limit)
{
$criteria = array();
$args = array();
if ($ip = preg_replace('/[^\d\.]/', '', $ip)) {
$criteria[] = 'ip LIKE :ip';
$args[':ip'] = '%'.$ip.'%';
}
if ($url) {
$criteria[] = 'url LIKE :url';
$args[':url'] = '%'.addcslashes($url, '%_\\').'%';
}
return array($criteria, $args);
}
/**
* {@inheritdoc}
*/
@ -129,6 +112,24 @@ abstract class PdoProfilerStorage implements ProfilerStorageInterface
$this->close($db);
}
/**
* Build SQL criteria to fetch records by ip and url
*
* @param string $ip The IP
* @param string $url The URL
* @param string $limit The maximum number of tokens to return
*
* @return array An array with (creteria, args)
*/
abstract protected function buildCriteria($ip, $url, $limit);
/**
* Initializes the database
*
* @throws \RuntimeException When the requeted database driver is not installed
*/
abstract protected function initDb();
protected function cleanup()
{
$db = $this->initDb();
@ -136,11 +137,6 @@ abstract class PdoProfilerStorage implements ProfilerStorageInterface
$this->close($db);
}
/**
* @throws \RuntimeException When the requeted database driver is not installed
*/
abstract protected function initDb();
protected function exec($db, $query, array $args = array())
{
$stmt = $this->prepareStatement($db, $query);
@ -187,8 +183,5 @@ abstract class PdoProfilerStorage implements ProfilerStorageInterface
protected function close($db)
{
if ($db instanceof \SQLite3) {
$db->close();
}
}
}

View File

@ -20,24 +20,6 @@ use Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface;
*/
class SqliteProfilerStorage extends PdoProfilerStorage
{
protected function buildCriteria($ip, $url, $limit)
{
$criteria = array();
$args = array();
if ($ip = preg_replace('/[^\d\.]/', '', $ip)) {
$criteria[] = 'ip LIKE :ip';
$args[':ip'] = '%'.$ip.'%';
}
if ($url) {
$criteria[] = 'url LIKE :url ESCAPE "\"';
$args[':url'] = '%'.addcslashes($url, '%_\\').'%';
}
return array($criteria, $args);
}
/**
* @throws \RuntimeException When neither of SQLite or PDO_SQLite extension is enabled
*/
@ -108,6 +90,27 @@ class SqliteProfilerStorage extends PdoProfilerStorage
return $return;
}
/**
* {@inheritdoc}
*/
protected function buildCriteria($ip, $url, $limit)
{
$criteria = array();
$args = array();
if ($ip = preg_replace('/[^\d\.]/', '', $ip)) {
$criteria[] = 'ip LIKE :ip';
$args[':ip'] = '%'.$ip.'%';
}
if ($url) {
$criteria[] = 'url LIKE :url ESCAPE "\"';
$args[':url'] = '%'.addcslashes($url, '%_\\').'%';
}
return array($criteria, $args);
}
protected function close($db)
{
if ($db instanceof \SQLite3) {