Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More fixes PSR-2 #483

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions demo/plugins/cacheresource.mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ public function __construct()
{
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');
Expand Down
99 changes: 50 additions & 49 deletions demo/plugins/cacheresource.pdo.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/
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
Expand Down Expand Up @@ -74,14 +74,16 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
protected $truncateStatement = 'TRUNCATE TABLE %s';
protected $fetchColumns = 'modified, content';
protected $fetchTimestampColumns = 'modified';
protected $pdo, $table, $database;
protected $pdo;
protected $table;
protected $database;

/*
* Constructor
*
* @param PDO $pdo PDO : active connection
* @param string $table : table (or view) name
* @param string $database : optional - if table is located in another db
/*
* Constructor
*
* @param PDO $pdo PDO : active connection
* @param string $table : table (or view) name
* @param string $database : optional - if table is located in another db
*/
/**
* Smarty_CacheResource_Pdo constructor.
Expand All @@ -103,15 +105,15 @@ public function __construct(PDO $pdo, $table, $database = null)
$this->fillStatementsWithTableName();
}

/*
* Fills the table name into the statements.
*
* @return Current Instance
* @access protected
/*
* Fills the table name into the statements.
*
* @return Current Instance
* @access protected
*/
protected function fillStatementsWithTableName()
{
foreach ($this->fetchStatements AS &$statement) {
foreach ($this->fetchStatements as &$statement) {
$statement = sprintf($statement, $this->getTableName(), '%s');
}
$this->insertStatement = sprintf($this->insertStatement, $this->getTableName());
Expand All @@ -120,31 +122,31 @@ protected function fillStatementsWithTableName()
return $this;
}

/*
* Gets the fetch statement, depending on what you specify
*
* @param string $columns : the column(s) name(s) you want to retrieve from the database
* @param string $id unique cache content identifier
* @param string|null $cache_id cache id
* @param string|null $compile_id compile id
* @access protected
/*
* Gets the fetch statement, depending on what you specify
*
* @param string $columns : the column(s) name(s) you want to retrieve from the database
* @param string $id unique cache content identifier
* @param string|null $cache_id cache id
* @param string|null $compile_id compile id
* @access protected
*/
protected function getFetchStatement($columns, $id, $cache_id = null, $compile_id = null)
{
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);
$stmt = $this->pdo->prepare($query);
foreach ($args AS $key => $value) {
foreach ($args as $key => $value) {
$stmt->bindValue($key, $value);
}
return $stmt;
Expand Down Expand Up @@ -224,24 +226,24 @@ protected function save($id, $name, $cache_id = null, $compile_id = null, $exp_t
return !!$stmt->rowCount();
}

/*
* Encodes the content before saving to database
*
* @param string $content
* @return string $content
* @access protected
/*
* Encodes the content before saving to database
*
* @param string $content
* @return string $content
* @access protected
*/
protected function inputContent($content)
{
return $content;
}

/*
* Decodes the content before saving to database
*
* @param string $content
* @return string $content
* @access protected
/*
* Decodes the content before saving to database
*
* @param string $content
* @return string $content
* @access protected
*/
protected function outputContent($content)
{
Expand All @@ -263,33 +265,33 @@ protected function delete($name = null, $cache_id = null, $compile_id = null, $e
{
// delete the whole cache
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
// returning the number of deleted caches would require a second query to count them
$this->pdo->query($this->truncateStatement);
return -1;
}
// build the filter
// build the filter
$where = array();
// equal test name
// equal test name
if ($name !== null) {
$where[] = 'name = ' . $this->pdo->quote($name);
}
// equal test cache_id and match sub-groups
// 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 . '|%') . ')';
}
// equal test compile_id
// equal test compile_id
if ($compile_id !== null) {
$where[] = 'compile_id = ' . $this->pdo->quote($compile_id);
}
// for clearing expired caches
// for clearing expired caches
if ($exp_time === Smarty::CLEAR_EXPIRED) {
$where[] = 'expire < CURRENT_TIMESTAMP';
} // range test expiration time
elseif ($exp_time !== null) {
$where[] = 'modified < DATE_SUB(NOW(), INTERVAL ' . intval($exp_time) . ' SECOND)';
}
// run delete query
// run delete query
$query = $this->pdo->query(sprintf($this->deleteStatement, join(' AND ', $where)));
return $query->rowCount();
}
Expand All @@ -305,4 +307,3 @@ protected function getTableName()
return (is_null($this->database)) ? "`{$this->table}`" : "`{$this->database}`.`{$this->table}`";
}
}

27 changes: 13 additions & 14 deletions demo/plugins/cacheresource.pdo_gzip.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,27 @@
class Smarty_CacheResource_Pdo_Gzip extends Smarty_CacheResource_Pdo
{

/*
* Encodes the content before saving to database
*
* @param string $content
* @return string $content
* @access protected
/*
* Encodes the content before saving to database
*
* @param string $content
* @return string $content
* @access protected
*/
protected function inputContent($content)
{
return gzdeflate($content);
}

/*
* Decodes the content before saving to database
*
* @param string $content
* @return string $content
* @access protected
/*
* Decodes the content before saving to database
*
* @param string $content
* @return string $content
* @access protected
*/
protected function outputContent($content)
{
return gzinflate($content);
}
}

}
4 changes: 1 addition & 3 deletions demo/plugins/resource.extendsall.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ public function populate(Smarty_Template_Source $source, Smarty_Internal_Templat
$sources[ $s->uid ] = $s;
$uid .= $s->filepath;
$timestamp = $s->timestamp > $timestamp ? $s->timestamp : $timestamp;
}
catch (SmartyException $e) {
} catch (SmartyException $e) {
}
}
if (!$sources) {
Expand Down Expand Up @@ -61,5 +60,4 @@ public function checkTimestamps()
{
return false;
}

}
3 changes: 1 addition & 2 deletions demo/plugins/resource.mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ public function __construct()
{
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, source FROM templates WHERE name = :name');
Expand Down
3 changes: 1 addition & 2 deletions demo/plugins/resource.mysqls.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ public function __construct()
{
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, source FROM templates WHERE name = :name');
Expand Down
2 changes: 1 addition & 1 deletion libs/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static function registerBC($prepend = false)
if (!defined('SMARTY_SPL_AUTOLOAD')) {
define('SMARTY_SPL_AUTOLOAD', 0);
}
if (SMARTY_SPL_AUTOLOAD
if (SMARTY_SPL_AUTOLOAD
&& set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false
) {
$registeredAutoLoadFunctions = spl_autoload_functions();
Expand Down
3 changes: 1 addition & 2 deletions libs/Smarty.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1079,8 +1079,7 @@ public function _getTemplateId($template_name,
$compile_id = null,
$caching = null,
Smarty_Internal_Template $template = null
)
{
) {
$template_name = (strpos($template_name, ':') === false) ? "{$this->default_resource_type}:{$template_name}" :
$template_name;
$cache_id = $cache_id === null ? $this->cache_id : $cache_id;
Expand Down
3 changes: 1 addition & 2 deletions libs/plugins/function.html_checkboxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,7 @@ function smarty_function_html_checkboxes_output($name,
$labels,
$label_ids,
$escape = true
)
{
) {
$_output = '';
if (is_object($value)) {
if (method_exists($value, '__toString')) {
Expand Down
3 changes: 1 addition & 2 deletions libs/plugins/function.html_radios.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,7 @@ function smarty_function_html_radios_output($name,
$labels,
$label_ids,
$escape
)
{
) {
$_output = '';
if (is_object($value)) {
if (method_exists($value, '__toString')) {
Expand Down
20 changes: 10 additions & 10 deletions libs/plugins/modifier.debug_print_var.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth =
{
$_replace = array("\n" => '\n', "\r" => '\r', "\t" => '\t');
switch (gettype($var)) {
case 'array' :
case 'array':
$results = '<b>Array (' . count($var) . ')</b>';
if ($depth === $max) {
break;
Expand All @@ -37,7 +37,7 @@ function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth =
$depth--;
}
break;
case 'object' :
case 'object':
$object_vars = get_object_vars($var);
$results = '<b>' . get_class($var) . ' Object (' . count($object_vars) . ')</b>';
if (in_array($var, $objects)) {
Expand All @@ -54,9 +54,9 @@ function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth =
$depth--;
}
break;
case 'boolean' :
case 'NULL' :
case 'resource' :
case 'boolean':
case 'NULL':
case 'resource':
if (true === $var) {
$results = 'true';
} elseif (false === $var) {
Expand All @@ -68,11 +68,11 @@ function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth =
}
$results = '<i>' . $results . '</i>';
break;
case 'integer' :
case 'float' :
case 'integer':
case 'float':
$results = htmlspecialchars((string)$var);
break;
case 'string' :
case 'string':
$results = strtr($var, $_replace);
if (Smarty::$_MBSTRING) {
if (mb_strlen($var, Smarty::$_CHARSET) > $length) {
Expand All @@ -85,8 +85,8 @@ function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth =
}
$results = htmlspecialchars('"' . $results . '"', ENT_QUOTES, Smarty::$_CHARSET);
break;
case 'unknown type' :
default :
case 'unknown type':
default:
$results = strtr((string)$var, $_replace);
if (Smarty::$_MBSTRING) {
if (mb_strlen($results, Smarty::$_CHARSET) > $length) {
Expand Down
2 changes: 1 addition & 1 deletion libs/plugins/modifier.replace.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function smarty_modifier_replace($string, $search, $replace)
}
$is_loaded = true;
}
return smarty_mb_str_replace($search, $replace, $string);
return smarty_mb_str_replace($search, $replace, $string);
}

return str_replace($search, $replace, $string);
Expand Down
3 changes: 1 addition & 2 deletions libs/plugins/modifiercompiler.escape.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ function smarty_modifiercompiler_escape($params, Smarty_Internal_TemplateCompile
$params[ 0 ] .
', array("\\\\" => "\\\\\\\\", "\'" => "\\\\\'", "\"" => "\\\\\"", "\\r" => "\\\\r", "\\n" => "\\\n", "</" => "<\/" ))';
}
}
catch (SmartyException $e) {
} catch (SmartyException $e) {
// pass through to regular plugin fallback
}
// could not optimize |escape call, so fallback to regular plugin
Expand Down
2 changes: 1 addition & 1 deletion libs/plugins/shared.make_timestamp.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function smarty_make_timestamp($string)
if (empty($string)) {
// use "now":
return time();
} elseif ($string instanceof DateTime
} elseif ($string instanceof DateTime
|| (interface_exists('DateTimeInterface', false) && $string instanceof DateTimeInterface)
) {
return (int) $string->format('U'); // PHP 5.2 BC
Expand Down
Loading