diff options
| author | uwetews <uwe.tews@googlemail.com> | 2016-02-09 01:27:15 +0100 |
|---|---|---|
| committer | uwetews <uwe.tews@googlemail.com> | 2016-02-09 01:27:15 +0100 |
| commit | b04486a091558a2b1280e3ee7fb90758e9a32230 (patch) | |
| tree | ddb15a12dba78e6873a348acd25f872429e210d2 /demo | |
| parent | c59ca44b9ff62a7f54e30409514834a8529780ca (diff) | |
| download | smarty-b04486a091558a2b1280e3ee7fb90758e9a32230.tar.gz smarty-b04486a091558a2b1280e3ee7fb90758e9a32230.tar.bz2 smarty-b04486a091558a2b1280e3ee7fb90758e9a32230.zip | |
- reformat all code for unique style
Diffstat (limited to 'demo')
| -rw-r--r-- | demo/index.php | 4 | ||||
| -rw-r--r-- | demo/plugins/cacheresource.apc.php | 2 | ||||
| -rw-r--r-- | demo/plugins/cacheresource.memcache.php | 4 | ||||
| -rw-r--r-- | demo/plugins/cacheresource.mysql.php | 20 | ||||
| -rw-r--r-- | demo/plugins/cacheresource.pdo.php | 45 | ||||
| -rw-r--r-- | demo/plugins/resource.mysql.php | 6 | ||||
| -rw-r--r-- | demo/plugins/resource.mysqls.php | 5 |
7 files changed, 46 insertions, 40 deletions
diff --git a/demo/index.php b/demo/index.php index 33f3035c..b67c217b 100644 --- a/demo/index.php +++ b/demo/index.php @@ -17,8 +17,8 @@ $smarty->cache_lifetime = 120; $smarty->assign("Name", "Fred Irving Johnathan Bradley Peppergill", true); $smarty->assign("FirstName", array("John", "Mary", "James", "Henry")); $smarty->assign("LastName", array("Doe", "Smith", "Johnson", "Case")); -$smarty->assign("Class", array(array("A", "B", "C", "D"), array("E", "F", "G", "H"), - array("I", "J", "K", "L"), array("M", "N", "O", "P"))); +$smarty->assign("Class", array(array("A", "B", "C", "D"), array("E", "F", "G", "H"), array("I", "J", "K", "L"), + array("M", "N", "O", "P"))); $smarty->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" => "3"), array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234"))); diff --git a/demo/plugins/cacheresource.apc.php b/demo/plugins/cacheresource.apc.php index d7336f2b..ed55ec84 100644 --- a/demo/plugins/cacheresource.apc.php +++ b/demo/plugins/cacheresource.apc.php @@ -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; diff --git a/demo/plugins/cacheresource.memcache.php b/demo/plugins/cacheresource.memcache.php index 15bb073b..945beb34 100644 --- a/demo/plugins/cacheresource.memcache.php +++ b/demo/plugins/cacheresource.memcache.php @@ -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; diff --git a/demo/plugins/cacheresource.mysql.php b/demo/plugins/cacheresource.mysql.php index d8d00ab2..027b9376 100644 --- a/demo/plugins/cacheresource.mysql.php +++ b/demo/plugins/cacheresource.mysql.php @@ -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)); diff --git a/demo/plugins/cacheresource.pdo.php b/demo/plugins/cacheresource.pdo.php index 569193aa..d1e2d6ac 100644 --- a/demo/plugins/cacheresource.pdo.php +++ b/demo/plugins/cacheresource.pdo.php @@ -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) { diff --git a/demo/plugins/resource.mysql.php b/demo/plugins/resource.mysql.php index dfc9606b..619707e7 100644 --- a/demo/plugins/resource.mysql.php +++ b/demo/plugins/resource.mysql.php @@ -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; diff --git a/demo/plugins/resource.mysqls.php b/demo/plugins/resource.mysqls.php index f694ddf1..d85aecf3 100644 --- a/demo/plugins/resource.mysqls.php +++ b/demo/plugins/resource.mysqls.php @@ -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; |
