Skip to content

Commit

Permalink
fixed coding standard
Browse files Browse the repository at this point in the history
  • Loading branch information
janschumann committed Mar 15, 2011
1 parent d1ebc8d commit bbfb1ff
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 52 deletions.
35 changes: 27 additions & 8 deletions src/Symfony/Component/HttpKernel/Profiler/MysqlProfilerStorage.php 100644 → 100755
Expand Up @@ -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 (!class_exists('PDO') || !in_array('mysql', \PDO::getAvailableDrivers(), true)) {
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)) {
throw new \RuntimeException('You need to enable PDO_Mysql extension for the profiler to run properly.');
}

Expand All @@ -42,4 +40,25 @@ protected function initDb()

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);
}
}
45 changes: 19 additions & 26 deletions src/Symfony/Component/HttpKernel/Profiler/PdoProfilerStorage.php 100644 → 100755
Expand Up @@ -16,6 +16,7 @@
/**
* 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
Expand Down Expand Up @@ -58,24 +59,6 @@ public function find($ip, $url, $limit)
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}
*/
Expand Down Expand Up @@ -129,18 +112,31 @@ public function purge()
$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();
$this->exec($db, 'DELETE FROM data WHERE created_at < :time', array(':time' => time() - $this->lifetime));
$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);
Expand Down Expand Up @@ -187,8 +183,5 @@ protected function fetch($db, $query, array $args = array())

protected function close($db)
{
if ($db instanceof \SQLite3) {
$db->close();
}
}
}
39 changes: 21 additions & 18 deletions src/Symfony/Component/HttpKernel/Profiler/SqliteProfilerStorage.php 100644 → 100755
Expand Up @@ -20,24 +20,6 @@
*/
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
*/
Expand Down Expand Up @@ -108,6 +90,27 @@ protected function fetch($db, $query, array $args = array())
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) {
Expand Down

0 comments on commit bbfb1ff

Please sign in to comment.