mirror of
https://github.com/smarty-php/smarty.git
synced 2026-05-19 23:24:47 +02:00
- reformat all code for unique style
This commit is contained in:
@@ -32,7 +32,7 @@ class Smarty_CacheResource_Apc extends Smarty_CacheResource_KeyValueStore
|
||||
$_res = array();
|
||||
$res = apc_fetch($keys);
|
||||
foreach ($res as $k => $v) {
|
||||
$_res[$k] = $v;
|
||||
$_res[ $k ] = $v;
|
||||
}
|
||||
|
||||
return $_res;
|
||||
|
||||
@@ -43,12 +43,12 @@ class Smarty_CacheResource_Memcache extends Smarty_CacheResource_KeyValueStore
|
||||
foreach ($keys as $k) {
|
||||
$_k = sha1($k);
|
||||
$_keys[] = $_k;
|
||||
$lookup[$_k] = $k;
|
||||
$lookup[ $_k ] = $k;
|
||||
}
|
||||
$_res = array();
|
||||
$res = $this->memcache->get($_keys);
|
||||
foreach ($res as $k => $v) {
|
||||
$_res[$lookup[$k]] = $v;
|
||||
$_res[ $lookup[ $k ] ] = $v;
|
||||
}
|
||||
|
||||
return $_res;
|
||||
|
||||
@@ -26,8 +26,11 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom
|
||||
{
|
||||
// PDO instance
|
||||
protected $db;
|
||||
|
||||
protected $fetch;
|
||||
|
||||
protected $fetchTimestamp;
|
||||
|
||||
protected $save;
|
||||
|
||||
public function __construct()
|
||||
@@ -62,8 +65,8 @@ class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom
|
||||
$row = $this->fetch->fetch();
|
||||
$this->fetch->closeCursor();
|
||||
if ($row) {
|
||||
$content = $row['content'];
|
||||
$mtime = strtotime($row['modified']);
|
||||
$content = $row[ 'content' ];
|
||||
$mtime = strtotime($row[ 'modified' ]);
|
||||
} else {
|
||||
$content = null;
|
||||
$mtime = null;
|
||||
@@ -105,13 +108,8 @@ 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,
|
||||
));
|
||||
$this->save->execute(array('id' => $id, 'name' => $name, 'cache_id' => $cache_id, 'compile_id' => $compile_id,
|
||||
'content' => $content,));
|
||||
|
||||
return !!$this->save->rowCount();
|
||||
}
|
||||
@@ -151,8 +149,8 @@ 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));
|
||||
|
||||
@@ -30,21 +30,21 @@
|
||||
class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
|
||||
{
|
||||
|
||||
protected $fetchStatements = Array('default' => 'SELECT %2$s
|
||||
protected $fetchStatements = Array('default' => 'SELECT %2$s
|
||||
FROM %1$s
|
||||
WHERE 1
|
||||
AND id = :id
|
||||
AND cache_id IS NULL
|
||||
AND compile_id IS NULL',
|
||||
|
||||
'withCacheId' => 'SELECT %2$s
|
||||
'withCacheId' => 'SELECT %2$s
|
||||
FROM %1$s
|
||||
WHERE 1
|
||||
AND id = :id
|
||||
AND cache_id = :cache_id
|
||||
AND compile_id IS NULL',
|
||||
|
||||
'withCompileId' => 'SELECT %2$s
|
||||
'withCompileId' => 'SELECT %2$s
|
||||
FROM %1$s
|
||||
WHERE 1
|
||||
AND id = :id
|
||||
@@ -57,6 +57,7 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
|
||||
AND id = :id
|
||||
AND cache_id = :cache_id
|
||||
AND compile_id = :compile_id');
|
||||
|
||||
protected $insertStatement = 'INSERT INTO %s
|
||||
|
||||
SET id = :id,
|
||||
@@ -76,9 +77,11 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
|
||||
content = :content';
|
||||
|
||||
protected $deleteStatement = 'DELETE FROM %1$s WHERE %2$s';
|
||||
|
||||
protected $truncateStatement = 'TRUNCATE TABLE %s';
|
||||
|
||||
protected $fetchColumns = 'modified, content';
|
||||
|
||||
protected $fetchTimestampColumns = 'modified';
|
||||
|
||||
protected $pdo, $table, $database;
|
||||
@@ -137,13 +140,15 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
|
||||
{
|
||||
|
||||
if (!is_null($cache_id) && !is_null($compile_id)) {
|
||||
$query = $this->fetchStatements['withCacheIdAndCompileId'] AND $args = Array('id' => $id, 'cache_id' => $cache_id, 'compile_id' => $compile_id);
|
||||
$query = $this->fetchStatements[ 'withCacheIdAndCompileId' ] AND
|
||||
$args = Array('id' => $id, 'cache_id' => $cache_id, 'compile_id' => $compile_id);
|
||||
} elseif (is_null($cache_id) && !is_null($compile_id)) {
|
||||
$query = $this->fetchStatements['withCompileId'] AND $args = Array('id' => $id, 'compile_id' => $compile_id);
|
||||
$query = $this->fetchStatements[ 'withCompileId' ] AND
|
||||
$args = Array('id' => $id, 'compile_id' => $compile_id);
|
||||
} elseif (!is_null($cache_id) && is_null($compile_id)) {
|
||||
$query = $this->fetchStatements['withCacheId'] AND $args = Array('id' => $id, 'cache_id' => $cache_id);
|
||||
$query = $this->fetchStatements[ 'withCacheId' ] AND $args = Array('id' => $id, 'cache_id' => $cache_id);
|
||||
} else {
|
||||
$query = $this->fetchStatements['default'] AND $args = Array('id' => $id);
|
||||
$query = $this->fetchStatements[ 'default' ] AND $args = Array('id' => $id);
|
||||
}
|
||||
|
||||
$query = sprintf($query, $columns);
|
||||
@@ -174,13 +179,13 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
|
||||
{
|
||||
|
||||
$stmt = $this->getFetchStatement($this->fetchColumns, $id, $cache_id, $compile_id);
|
||||
$stmt ->execute();
|
||||
$stmt->execute();
|
||||
$row = $stmt->fetch();
|
||||
$stmt ->closeCursor();
|
||||
$stmt->closeCursor();
|
||||
|
||||
if ($row) {
|
||||
$content = $this->outputContent($row['content']);
|
||||
$mtime = strtotime($row['modified']);
|
||||
$content = $this->outputContent($row[ 'content' ]);
|
||||
$mtime = strtotime($row[ 'modified' ]);
|
||||
} else {
|
||||
$content = null;
|
||||
$mtime = null;
|
||||
@@ -226,13 +231,13 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
|
||||
|
||||
$stmt = $this->pdo->prepare($this->insertStatement);
|
||||
|
||||
$stmt ->bindValue('id', $id);
|
||||
$stmt ->bindValue('name', $name);
|
||||
$stmt ->bindValue('cache_id', $cache_id, (is_null($cache_id)) ? PDO::PARAM_NULL : PDO::PARAM_STR);
|
||||
$stmt ->bindValue('compile_id', $compile_id, (is_null($compile_id)) ? PDO::PARAM_NULL : PDO::PARAM_STR);
|
||||
$stmt ->bindValue('expire', (int) $exp_time, PDO::PARAM_INT);
|
||||
$stmt ->bindValue('content', $this->inputContent($content));
|
||||
$stmt ->execute();
|
||||
$stmt->bindValue('id', $id);
|
||||
$stmt->bindValue('name', $name);
|
||||
$stmt->bindValue('cache_id', $cache_id, (is_null($cache_id)) ? PDO::PARAM_NULL : PDO::PARAM_STR);
|
||||
$stmt->bindValue('compile_id', $compile_id, (is_null($compile_id)) ? PDO::PARAM_NULL : PDO::PARAM_STR);
|
||||
$stmt->bindValue('expire', (int) $exp_time, PDO::PARAM_INT);
|
||||
$stmt->bindValue('content', $this->inputContent($content));
|
||||
$stmt->execute();
|
||||
|
||||
return !!$stmt->rowCount();
|
||||
}
|
||||
@@ -289,8 +294,8 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
|
||||
}
|
||||
// equal test cache_id and match sub-groups
|
||||
if ($cache_id !== null) {
|
||||
$where[] = '(cache_id = ' . $this->pdo->quote($cache_id)
|
||||
. ' OR cache_id LIKE ' . $this->pdo->quote($cache_id . '|%') . ')';
|
||||
$where[] = '(cache_id = ' . $this->pdo->quote($cache_id) . ' OR cache_id LIKE ' .
|
||||
$this->pdo->quote($cache_id . '|%') . ')';
|
||||
}
|
||||
// equal test compile_id
|
||||
if ($compile_id !== null) {
|
||||
|
||||
@@ -21,8 +21,10 @@ class Smarty_Resource_Mysql extends Smarty_Resource_Custom
|
||||
{
|
||||
// PDO instance
|
||||
protected $db;
|
||||
|
||||
// prepared fetch() statement
|
||||
protected $fetch;
|
||||
|
||||
// prepared fetchTimestamp() statement
|
||||
protected $mtime;
|
||||
|
||||
@@ -53,8 +55,8 @@ class Smarty_Resource_Mysql extends Smarty_Resource_Custom
|
||||
$row = $this->fetch->fetch();
|
||||
$this->fetch->closeCursor();
|
||||
if ($row) {
|
||||
$source = $row['source'];
|
||||
$mtime = strtotime($row['modified']);
|
||||
$source = $row[ 'source' ];
|
||||
$mtime = strtotime($row[ 'modified' ]);
|
||||
} else {
|
||||
$source = null;
|
||||
$mtime = null;
|
||||
|
||||
@@ -23,6 +23,7 @@ class Smarty_Resource_Mysqls extends Smarty_Resource_Custom
|
||||
{
|
||||
// PDO instance
|
||||
protected $db;
|
||||
|
||||
// prepared fetch() statement
|
||||
protected $fetch;
|
||||
|
||||
@@ -52,8 +53,8 @@ class Smarty_Resource_Mysqls extends Smarty_Resource_Custom
|
||||
$row = $this->fetch->fetch();
|
||||
$this->fetch->closeCursor();
|
||||
if ($row) {
|
||||
$source = $row['source'];
|
||||
$mtime = strtotime($row['modified']);
|
||||
$source = $row[ 'source' ];
|
||||
$mtime = strtotime($row[ 'modified' ]);
|
||||
} else {
|
||||
$source = null;
|
||||
$mtime = null;
|
||||
|
||||
Reference in New Issue
Block a user