- reformating for PSR-2 coding standards https://github.com/smarty-php/smarty/pull/483

This commit is contained in:
uwetews
2018-08-31 16:45:09 +02:00
parent d52a04fba1
commit 4f7cd8f1b3
177 changed files with 1905 additions and 1498 deletions

View File

@@ -24,13 +24,24 @@
*/
class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom
{
// PDO instance
/**
* @var \PDO
*/
protected $db;
/**
* @var \PDOStatement
*/
protected $fetch;
/**
* @var \PDOStatement
*/
protected $fetchTimestamp;
/**
* @var \PDOStatement
*/
protected $save;
/**
@@ -42,8 +53,7 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom
{
try {
$this->db = new PDO("mysql:dbname=test;host=127.0.0.1", "smarty");
}
catch (PDOException $e) {
} catch (PDOException $e) {
throw new SmartyException('Mysql Resource failed: ' . $e->getMessage());
}
$this->fetch = $this->db->prepare('SELECT modified, content FROM output_cache WHERE id = :id');
@@ -83,7 +93,8 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom
/**
* Fetch cached content's modification timestamp from data source
*
* @note implementing this method is optional. Only implement it if modification times can be accessed faster than loading the complete cached content.
* @note implementing this method is optional. Only implement it if modification times can be accessed faster than
* loading the complete cached content.
*
* @param string $id unique cache content identifier
* @param string $name template name
@@ -97,7 +108,6 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom
$this->fetchTimestamp->execute(array('id' => $id));
$mtime = strtotime($this->fetchTimestamp->fetchColumn());
$this->fetchTimestamp->closeCursor();
return $mtime;
}
@@ -116,10 +126,12 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom
protected function save($id, $name, $cache_id, $compile_id, $exp_time, $content)
{
$this->save->execute(
array('id' => $id, 'name' => $name, 'cache_id' => $cache_id, 'compile_id' => $compile_id,
'content' => $content,)
array('id' => $id,
'name' => $name,
'cache_id' => $cache_id,
'compile_id' => $compile_id,
'content' => $content,)
);
return !!$this->save->rowCount();
}
@@ -139,8 +151,7 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom
if ($name === null && $cache_id === null && $compile_id === null && $exp_time === null) {
// returning the number of deleted caches would require a second query to count them
$query = $this->db->query('TRUNCATE TABLE output_cache');
return - 1;
return -1;
}
// build the filter
$where = array();
@@ -158,12 +169,15 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom
}
// equal test cache_id and match sub-groups
if ($cache_id !== null) {
$where[] = '(cache_id = ' . $this->db->quote($cache_id) . ' OR cache_id LIKE ' .
$this->db->quote($cache_id . '|%') . ')';
$where[] =
'(cache_id = ' .
$this->db->quote($cache_id) .
' OR cache_id LIKE ' .
$this->db->quote($cache_id . '|%') .
')';
}
// run delete query
$query = $this->db->query('DELETE FROM output_cache WHERE ' . join(' AND ', $where));
return $query->rowCount();
}
}