Use PHP 7 Null Coalescing Operator (??)

This commit is contained in:
Ian
2022-08-08 17:27:57 +02:00
parent 7f579fdc69
commit 159ed4ee02
28 changed files with 71 additions and 89 deletions

View File

@@ -771,7 +771,7 @@ class Smarty extends Smarty_Internal_TemplateBase
$this->_normalizeTemplateConfig($isConfig); $this->_normalizeTemplateConfig($isConfig);
} }
if ($index !== null) { if ($index !== null) {
return isset($dir[ $index ]) ? $dir[ $index ] : null; return ($dir[ $index ] ?? null);
} }
return $dir; return $dir;
} }

View File

@@ -23,7 +23,7 @@
function smarty_function_counter($params, $template) function smarty_function_counter($params, $template)
{ {
static $counters = array(); static $counters = array();
$name = (isset($params[ 'name' ])) ? $params[ 'name' ] : 'default'; $name = $params[ 'name' ] ?? 'default';
if (!isset($counters[ $name ])) { if (!isset($counters[ $name ])) {
$counters[ $name ] = array('start' => 1, 'skip' => 1, 'direction' => 'up', 'count' => 1); $counters[ $name ] = array('start' => 1, 'skip' => 1, 'direction' => 'up', 'count' => 1);
} }

View File

@@ -156,7 +156,7 @@ function smarty_function_html_radios($params, Smarty_Internal_Template $template
} }
} else { } else {
foreach ($values as $_i => $_key) { foreach ($values as $_i => $_key) {
$_val = isset($output[ $_i ]) ? $output[ $_i ] : ''; $_val = $output[ $_i ] ?? '';
$_html_result[] = $_html_result[] =
smarty_function_html_radios_output( smarty_function_html_radios_output(
$name, $name,

View File

@@ -187,9 +187,7 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
'd' => 'Day' 'd' => 'Day'
) as $_elementKey => $_elementName) { ) as $_elementKey => $_elementName) {
$_variableName = '_' . strtolower($_elementName); $_variableName = '_' . strtolower($_elementName);
$$_variableName = $$_variableName = $params[ 'time' ][ $prefix . $_elementName ] ?? date($_elementKey);
isset($params[ 'time' ][ $prefix . $_elementName ]) ? $params[ 'time' ][ $prefix . $_elementName ] :
date($_elementKey);
} }
} elseif (isset($params[ 'time' ][ $field_array ][ $prefix . 'Year' ])) { } elseif (isset($params[ 'time' ][ $field_array ][ $prefix . 'Year' ])) {
// $_REQUEST given // $_REQUEST given
@@ -258,9 +256,8 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
if ($year_id !== null || $all_id !== null) { if ($year_id !== null || $all_id !== null) {
$_html_years .= ' id="' . smarty_function_escape_special_chars( $_html_years .= ' id="' . smarty_function_escape_special_chars(
$year_id !== null ? $year_id !== null ?
($year_id ? $year_id : $_name) : ($year_id ?? $_name) :
($all_id ? ($all_id . $_name) : ($all_id ? ($all_id . $_name) : $_name)
$_name)
) . '"'; ) . '"';
} }
if ($year_size) { if ($year_size) {
@@ -268,7 +265,7 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
} }
$_html_years .= $_extra . $extra_attrs . '>' . $option_separator; $_html_years .= $_extra . $extra_attrs . '>' . $option_separator;
if (isset($year_empty) || isset($all_empty)) { if (isset($year_empty) || isset($all_empty)) {
$_html_years .= '<option value="">' . (isset($year_empty) ? $year_empty : $all_empty) . '</option>' . $_html_years .= '<option value="">' . ($year_empty ?? $all_empty) . '</option>' .
$option_separator; $option_separator;
} }
$op = $start_year > $end_year ? -1 : 1; $op = $start_year > $end_year ? -1 : 1;
@@ -293,9 +290,8 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
if ($month_id !== null || $all_id !== null) { if ($month_id !== null || $all_id !== null) {
$_html_months .= ' id="' . smarty_function_escape_special_chars( $_html_months .= ' id="' . smarty_function_escape_special_chars(
$month_id !== null ? $month_id !== null ?
($month_id ? $month_id : $_name) : ($month_id ?? $_name) :
($all_id ? ($all_id . $_name) : ($all_id ? ($all_id . $_name) : $_name)
$_name)
) . '"'; ) . '"';
} }
if ($month_size) { if ($month_size) {
@@ -303,14 +299,14 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
} }
$_html_months .= $_extra . $extra_attrs . '>' . $option_separator; $_html_months .= $_extra . $extra_attrs . '>' . $option_separator;
if (isset($month_empty) || isset($all_empty)) { if (isset($month_empty) || isset($all_empty)) {
$_html_months .= '<option value="">' . (isset($month_empty) ? $month_empty : $all_empty) . '</option>' . $_html_months .= '<option value="">' . ($month_empty ?? $all_empty) . '</option>' .
$option_separator; $option_separator;
} }
for ($i = 1; $i <= 12; $i++) { for ($i = 1; $i <= 12; $i++) {
$_val = sprintf('%02d', $i); $_val = sprintf('%02d', $i);
$_text = isset($month_names) ? smarty_function_escape_special_chars($month_names[ $i ]) : $_text = isset($month_names) ? smarty_function_escape_special_chars($month_names[ $i ]) :
($month_format === '%m' ? $_val : strftime($month_format, $_month_timestamps[ $i ])); ($month_format === '%m' ? $_val : @strftime($month_format, $_month_timestamps[ $i ]));
$_value = $month_value_format === '%m' ? $_val : strftime($month_value_format, $_month_timestamps[ $i ]); $_value = $month_value_format === '%m' ? $_val : @strftime($month_value_format, $_month_timestamps[ $i ]);
$_html_months .= '<option value="' . $_value . '"' . ($_val == $_month ? ' selected="selected"' : '') . $_html_months .= '<option value="' . $_value . '"' . ($_val == $_month ? ' selected="selected"' : '') .
'>' . $_text . '</option>' . $option_separator; '>' . $_text . '</option>' . $option_separator;
} }
@@ -339,7 +335,7 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
} }
$_html_days .= $_extra . $extra_attrs . '>' . $option_separator; $_html_days .= $_extra . $extra_attrs . '>' . $option_separator;
if (isset($day_empty) || isset($all_empty)) { if (isset($day_empty) || isset($all_empty)) {
$_html_days .= '<option value="">' . (isset($day_empty) ? $day_empty : $all_empty) . '</option>' . $_html_days .= '<option value="">' . ($day_empty ?? $all_empty) . '</option>' .
$option_separator; $option_separator;
} }
for ($i = 1; $i <= 31; $i++) { for ($i = 1; $i <= 31; $i++) {

View File

@@ -147,9 +147,7 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
's' => 'Second' 's' => 'Second'
) as $_elementKey => $_elementName) { ) as $_elementKey => $_elementName) {
$_variableName = '_' . strtolower($_elementName); $_variableName = '_' . strtolower($_elementName);
$$_variableName = $$_variableName = $params[ 'time' ][ $prefix . $_elementName ] ?? date($_elementKey);
isset($params[ 'time' ][ $prefix . $_elementName ]) ? $params[ 'time' ][ $prefix . $_elementName ] :
date($_elementKey);
} }
$_meridian = $_meridian =
isset($params[ 'time' ][ $prefix . 'Meridian' ]) ? (' ' . $params[ 'time' ][ $prefix . 'Meridian' ]) : isset($params[ 'time' ][ $prefix . 'Meridian' ]) ? (' ' . $params[ 'time' ][ $prefix . 'Meridian' ]) :
@@ -199,7 +197,7 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
if ($hour_id !== null || $all_id !== null) { if ($hour_id !== null || $all_id !== null) {
$_html_hours .= ' id="' . $_html_hours .= ' id="' .
smarty_function_escape_special_chars( smarty_function_escape_special_chars(
$hour_id !== null ? ($hour_id ? $hour_id : $_name) : $hour_id !== null ? ($hour_id ?? $_name) :
($all_id ? ($all_id . $_name) : $_name) ($all_id ? ($all_id . $_name) : $_name)
) . '"'; ) . '"';
} }
@@ -208,7 +206,7 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
} }
$_html_hours .= $_extra . $extra_attrs . '>' . $option_separator; $_html_hours .= $_extra . $extra_attrs . '>' . $option_separator;
if (isset($hour_empty) || isset($all_empty)) { if (isset($hour_empty) || isset($all_empty)) {
$_html_hours .= '<option value="">' . (isset($hour_empty) ? $hour_empty : $all_empty) . '</option>' . $_html_hours .= '<option value="">' . ($hour_empty ?? $all_empty) . '</option>' .
$option_separator; $option_separator;
} }
$start = $use_24_hours ? 0 : 1; $start = $use_24_hours ? 0 : 1;
@@ -241,9 +239,8 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
if ($minute_id !== null || $all_id !== null) { if ($minute_id !== null || $all_id !== null) {
$_html_minutes .= ' id="' . smarty_function_escape_special_chars( $_html_minutes .= ' id="' . smarty_function_escape_special_chars(
$minute_id !== null ? $minute_id !== null ?
($minute_id ? $minute_id : $_name) : ($minute_id ?? $_name) :
($all_id ? ($all_id . $_name) : ($all_id ? ($all_id . $_name) : $_name)
$_name)
) . '"'; ) . '"';
} }
if ($minute_size) { if ($minute_size) {
@@ -251,7 +248,7 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
} }
$_html_minutes .= $_extra . $extra_attrs . '>' . $option_separator; $_html_minutes .= $_extra . $extra_attrs . '>' . $option_separator;
if (isset($minute_empty) || isset($all_empty)) { if (isset($minute_empty) || isset($all_empty)) {
$_html_minutes .= '<option value="">' . (isset($minute_empty) ? $minute_empty : $all_empty) . '</option>' . $_html_minutes .= '<option value="">' . ($minute_empty ?? $all_empty) . '</option>' .
$option_separator; $option_separator;
} }
$selected = $_minute !== null ? ($_minute - $_minute % $minute_interval) : null; $selected = $_minute !== null ? ($_minute - $_minute % $minute_interval) : null;
@@ -279,9 +276,8 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
if ($second_id !== null || $all_id !== null) { if ($second_id !== null || $all_id !== null) {
$_html_seconds .= ' id="' . smarty_function_escape_special_chars( $_html_seconds .= ' id="' . smarty_function_escape_special_chars(
$second_id !== null ? $second_id !== null ?
($second_id ? $second_id : $_name) : ($second_id ?? $_name) :
($all_id ? ($all_id . $_name) : ($all_id ? ($all_id . $_name) : $_name)
$_name)
) . '"'; ) . '"';
} }
if ($second_size) { if ($second_size) {
@@ -289,7 +285,7 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
} }
$_html_seconds .= $_extra . $extra_attrs . '>' . $option_separator; $_html_seconds .= $_extra . $extra_attrs . '>' . $option_separator;
if (isset($second_empty) || isset($all_empty)) { if (isset($second_empty) || isset($all_empty)) {
$_html_seconds .= '<option value="">' . (isset($second_empty) ? $second_empty : $all_empty) . '</option>' . $_html_seconds .= '<option value="">' . ($second_empty ?? $all_empty) . '</option>' .
$option_separator; $option_separator;
} }
$selected = $_second !== null ? ($_second - $_second % $second_interval) : null; $selected = $_second !== null ? ($_second - $_second % $second_interval) : null;
@@ -317,10 +313,8 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
if ($meridian_id !== null || $all_id !== null) { if ($meridian_id !== null || $all_id !== null) {
$_html_meridian .= ' id="' . smarty_function_escape_special_chars( $_html_meridian .= ' id="' . smarty_function_escape_special_chars(
$meridian_id !== null ? $meridian_id !== null ?
($meridian_id ? $meridian_id : ($meridian_id ?? $_name) :
$_name) : ($all_id ? ($all_id . $_name) : $_name)
($all_id ? ($all_id . $_name) :
$_name)
) . '"'; ) . '"';
} }
if ($meridian_size) { if ($meridian_size) {
@@ -328,7 +322,7 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
} }
$_html_meridian .= $_extra . $extra_attrs . '>' . $option_separator; $_html_meridian .= $_extra . $extra_attrs . '>' . $option_separator;
if (isset($meridian_empty) || isset($all_empty)) { if (isset($meridian_empty) || isset($all_empty)) {
$_html_meridian .= '<option value="">' . (isset($meridian_empty) ? $meridian_empty : $all_empty) . $_html_meridian .= '<option value="">' . ($meridian_empty ?? $all_empty) .
'</option>' . $option_separator; '</option>' . $option_separator;
} }
$_html_meridian .= '<option value="am"' . ($_hour > 0 && $_hour < 12 ? ' selected="selected"' : '') . $_html_meridian .= '<option value="am"' . ($_hour > 0 && $_hour < 12 ? ' selected="selected"' : '') .

View File

@@ -117,7 +117,7 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
$cached->content, $cached->content,
$timestamp $timestamp
); );
$cached->timestamp = isset($timestamp) ? $timestamp : false; $cached->timestamp = $timestamp ?? false;
$cached->exists = !!$cached->timestamp; $cached->exists = !!$cached->timestamp;
} }
@@ -138,8 +138,8 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
if (!$cached) { if (!$cached) {
$cached = $_smarty_tpl->cached; $cached = $_smarty_tpl->cached;
} }
$content = $cached->content ? $cached->content : null; $content = $cached->content ?? null;
$timestamp = $cached->timestamp ? $cached->timestamp : null; $timestamp = $cached->timestamp ?? null;
if ($content === null || !$timestamp) { if ($content === null || !$timestamp) {
$this->fetch( $this->fetch(
$_smarty_tpl->cached->filepath, $_smarty_tpl->cached->filepath,
@@ -187,7 +187,7 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
*/ */
public function readCachedContent(Smarty_Internal_Template $_template) public function readCachedContent(Smarty_Internal_Template $_template)
{ {
$content = $_template->cached->content ? $_template->cached->content : null; $content = $_template->cached->content ?? null;
$timestamp = null; $timestamp = null;
if ($content === null) { if ($content === null) {
$timestamp = null; $timestamp = null;

View File

@@ -102,8 +102,8 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
if (!$cached) { if (!$cached) {
$cached = $_smarty_tpl->cached; $cached = $_smarty_tpl->cached;
} }
$content = $cached->content ? $cached->content : null; $content = $cached->content ?? null;
$timestamp = $cached->timestamp ? $cached->timestamp : null; $timestamp = $cached->timestamp ?? null;
if ($content === null || !$timestamp) { if ($content === null || !$timestamp) {
if (!$this->fetch( if (!$this->fetch(
$_smarty_tpl->cached->filepath, $_smarty_tpl->cached->filepath,
@@ -148,7 +148,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
*/ */
public function readCachedContent(Smarty_Internal_Template $_template) public function readCachedContent(Smarty_Internal_Template $_template)
{ {
$content = $_template->cached->content ? $_template->cached->content : null; $content = $_template->cached->content ?? null;
$timestamp = null; $timestamp = null;
if ($content === null) { if ($content === null) {
if (!$this->fetch( if (!$this->fetch(

View File

@@ -112,7 +112,7 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_Compile_Shared_
$_block = $compiler->_cache[ 'blockParams' ][ $compiler->_cache[ 'blockNesting' ] ]; $_block = $compiler->_cache[ 'blockParams' ][ $compiler->_cache[ 'blockNesting' ] ];
unset($compiler->_cache[ 'blockParams' ][ $compiler->_cache[ 'blockNesting' ] ]); unset($compiler->_cache[ 'blockParams' ][ $compiler->_cache[ 'blockNesting' ] ]);
$_name = $_attr[ 'name' ]; $_name = $_attr[ 'name' ];
$_assign = isset($_attr[ 'assign' ]) ? $_attr[ 'assign' ] : null; $_assign = $_attr[ 'assign' ] ?? null;
unset($_attr[ 'assign' ], $_attr[ 'name' ]); unset($_attr[ 'assign' ], $_attr[ 'name' ]);
foreach ($_attr as $name => $stat) { foreach ($_attr as $name => $stat) {
if ((is_bool($stat) && $stat !== false) || (!is_bool($stat) && $stat !== 'false')) { if ((is_bool($stat) && $stat !== false) || (!is_bool($stat) && $stat !== 'false')) {

View File

@@ -63,9 +63,9 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase
{ {
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args, $parameter, 'capture'); $_attr = $this->getAttributes($compiler, $args, $parameter, 'capture');
$buffer = isset($_attr[ 'name' ]) ? $_attr[ 'name' ] : "'default'"; $buffer = $_attr[ 'name' ] ?? "'default'";
$assign = isset($_attr[ 'assign' ]) ? $_attr[ 'assign' ] : 'null'; $assign = $_attr[ 'assign' ] ?? 'null';
$append = isset($_attr[ 'append' ]) ? $_attr[ 'append' ] : 'null'; $append = $_attr[ 'append' ] ?? 'null';
$compiler->_cache[ 'capture_stack' ][] = array($compiler->nocache); $compiler->_cache[ 'capture_stack' ][] = array($compiler->nocache);
// maybe nocache because of nocache variables // maybe nocache because of nocache variables
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache; $compiler->nocache = $compiler->nocache | $compiler->tag_nocache;

View File

@@ -63,7 +63,7 @@ class Smarty_Internal_Compile_Child extends Smarty_Internal_CompileBase
if ($this->blockType === 'Child') { if ($this->blockType === 'Child') {
$compiler->_cache[ 'blockParams' ][ $compiler->_cache[ 'blockNesting' ] ][ 'callsChild' ] = 'true'; $compiler->_cache[ 'blockParams' ][ $compiler->_cache[ 'blockNesting' ] ][ 'callsChild' ] = 'true';
} }
$_assign = isset($_attr[ 'assign' ]) ? $_attr[ 'assign' ] : null; $_assign = $_attr[ 'assign' ] ?? null;
$output = "<?php \n"; $output = "<?php \n";
if (isset($_assign)) { if (isset($_assign)) {
$output .= "ob_start();\n"; $output .= "ob_start();\n";

View File

@@ -157,7 +157,7 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
$output = "<?php echo \"/*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/<?php "; $output = "<?php echo \"/*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/<?php ";
$output .= "\\\$_smarty_tpl->smarty->ext->_tplFunction->restoreTemplateVariables(\\\$_smarty_tpl, '{$_name}');?>\n"; $output .= "\\\$_smarty_tpl->smarty->ext->_tplFunction->restoreTemplateVariables(\\\$_smarty_tpl, '{$_name}');?>\n";
$output .= "/*/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\";\n?>"; $output .= "/*/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\";\n?>";
$output .= "<?php echo str_replace('{$compiler->template->compiled->nocache_hash}', \$_smarty_tpl->compiled->nocache_hash ?? '', ob_get_clean());\n"; $output .= "<?php echo str_replace('{$compiler->template->compiled->nocache_hash}', \$_smarty_tpl->compiled->nocache_hash, ob_get_clean());\n";
$output .= "}\n}\n"; $output .= "}\n}\n";
$output .= $compiler->cStyleComment("/ {$_funcName}_nocache ") . "\n\n"; $output .= $compiler->cStyleComment("/ {$_funcName}_nocache ") . "\n\n";
$output .= "?>\n"; $output .= "?>\n";

View File

@@ -196,7 +196,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
} }
$has_compiled_template = false; $has_compiled_template = false;
if ($merge_compiled_includes) { if ($merge_compiled_includes) {
$c_id = isset($_attr[ 'compile_id' ]) ? $_attr[ 'compile_id' ] : $compiler->template->compile_id; $c_id = $_attr[ 'compile_id' ] ?? $compiler->template->compile_id;
// we must observe different compile_id and caching // we must observe different compile_id and caching
$t_hash = sha1($c_id . ($_caching ? '--caching' : '--nocaching')); $t_hash = sha1($c_id . ($_caching ? '--caching' : '--nocaching'));
$compiler->smarty->allow_ambiguous_resources = true; $compiler->smarty->allow_ambiguous_resources = true;
@@ -314,7 +314,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
} else { } else {
$basename = $tpl->source->handler->getBasename($tpl->source); $basename = $tpl->source->handler->getBasename($tpl->source);
$sourceInfo = $tpl->source->type . ':' . $sourceInfo = $tpl->source->type . ':' .
($basename ? $basename : $tpl->source->name); ($basename ?? $tpl->source->name);
} }
// get compiled code // get compiled code
$compiled_code = "<?php\n\n"; $compiled_code = "<?php\n\n";

View File

@@ -193,7 +193,7 @@ class Smarty_Internal_Configfilelexer
$this->yyTraceFILE, $this->yyTraceFILE,
"%sState push %s\n", "%sState push %s\n",
$this->yyTracePrompt, $this->yyTracePrompt,
isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : $this->_yy_state $this->state_name[ $this->_yy_state ] ?? $this->_yy_state
); );
} }
array_push($this->_yy_stack, $this->_yy_state); array_push($this->_yy_stack, $this->_yy_state);
@@ -203,7 +203,7 @@ class Smarty_Internal_Configfilelexer
$this->yyTraceFILE, $this->yyTraceFILE,
"%snew State %s\n", "%snew State %s\n",
$this->yyTracePrompt, $this->yyTracePrompt,
isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : $this->_yy_state $this->state_name[ $this->_yy_state ] ?? $this->_yy_state
); );
} }
} }
@@ -215,7 +215,7 @@ class Smarty_Internal_Configfilelexer
$this->yyTraceFILE, $this->yyTraceFILE,
"%sState pop %s\n", "%sState pop %s\n",
$this->yyTracePrompt, $this->yyTracePrompt,
isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : $this->_yy_state $this->state_name[ $this->_yy_state ] ?? $this->_yy_state
); );
} }
$this->_yy_state = array_pop($this->_yy_stack); $this->_yy_state = array_pop($this->_yy_stack);
@@ -224,7 +224,7 @@ class Smarty_Internal_Configfilelexer
$this->yyTraceFILE, $this->yyTraceFILE,
"%snew State %s\n", "%snew State %s\n",
$this->yyTracePrompt, $this->yyTracePrompt,
isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : $this->_yy_state $this->state_name[ $this->_yy_state ] ?? $this->_yy_state
); );
} }
} }
@@ -237,7 +237,7 @@ class Smarty_Internal_Configfilelexer
$this->yyTraceFILE, $this->yyTraceFILE,
"%sState set %s\n", "%sState set %s\n",
$this->yyTracePrompt, $this->yyTracePrompt,
isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : $this->_yy_state $this->state_name[ $this->_yy_state ] ?? $this->_yy_state
); );
} }
} }

View File

@@ -220,8 +220,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
$debObj->debugging = false; $debObj->debugging = false;
$debObj->debugging_ctrl = 'NONE'; $debObj->debugging_ctrl = 'NONE';
$debObj->error_reporting = E_ALL & ~E_NOTICE; $debObj->error_reporting = E_ALL & ~E_NOTICE;
$debObj->debug_tpl = $debObj->debug_tpl = $smarty->debug_tpl ?? 'file:' . dirname(__FILE__) . '/../debug.tpl';
isset($smarty->debug_tpl) ? $smarty->debug_tpl : 'file:' . dirname(__FILE__) . '/../debug.tpl';
$debObj->registered_plugins = array(); $debObj->registered_plugins = array();
$debObj->registered_resources = array(); $debObj->registered_resources = array();
$debObj->registered_filters = array(); $debObj->registered_filters = array();

View File

@@ -66,7 +66,7 @@ class Smarty_Internal_Extension_Handler
public function _callExternalMethod(Smarty_Internal_Data $data, $name, $args) public function _callExternalMethod(Smarty_Internal_Data $data, $name, $args)
{ {
/* @var Smarty $data ->smarty */ /* @var Smarty $data ->smarty */
$smarty = isset($data->smarty) ? $data->smarty : $data; $smarty = $data->smarty ?? $data;
if (!isset($smarty->ext->$name)) { if (!isset($smarty->ext->$name)) {
if (preg_match('/^((set|get)|(.*?))([A-Z].*)$/', $name, $match)) { if (preg_match('/^((set|get)|(.*?))([A-Z].*)$/', $name, $match)) {
$basename = $this->upperCase($match[ 4 ]); $basename = $this->upperCase($match[ 4 ]);

View File

@@ -30,7 +30,7 @@ class Smarty_Internal_Method_GetAutoloadFilters extends Smarty_Internal_Method_S
$smarty = $obj->_getSmartyObj(); $smarty = $obj->_getSmartyObj();
if ($type !== null) { if ($type !== null) {
$this->_checkFilterType($type); $this->_checkFilterType($type);
return isset($smarty->autoload_filters[ $type ]) ? $smarty->autoload_filters[ $type ] : array(); return ($smarty->autoload_filters[ $type ] ?? array());
} }
return $smarty->autoload_filters; return $smarty->autoload_filters;
} }

View File

@@ -40,7 +40,7 @@ class Smarty_Internal_Method_GetStreamVariable
fclose($fp); fclose($fp);
return $_result; return $_result;
} }
$smarty = isset($data->smarty) ? $data->smarty : $data; $smarty = $data->smarty ?? $data;
if ($smarty->error_unassigned) { if ($smarty->error_unassigned) {
throw new SmartyException('Undefined stream variable "' . $variable . '"'); throw new SmartyException('Undefined stream variable "' . $variable . '"');
} else { } else {

View File

@@ -44,7 +44,7 @@ class Smarty_Internal_Method_RegisterFilter
{ {
$smarty = $obj->_getSmartyObj(); $smarty = $obj->_getSmartyObj();
$this->_checkFilterType($type); $this->_checkFilterType($type);
$name = isset($name) ? $name : $this->_getFilterName($callback); $name = $name ?? $this->_getFilterName($callback);
if (!is_callable($callback)) { if (!is_callable($callback)) {
throw new SmartyException("{$type}filter '{$name}' not callable"); throw new SmartyException("{$type}filter '{$name}' not callable");
} }

View File

@@ -150,7 +150,7 @@ class Smarty_Internal_Runtime_Capture
public function getBuffer(Smarty_Internal_Template $_template, $name = null) public function getBuffer(Smarty_Internal_Template $_template, $name = null)
{ {
if (isset($name)) { if (isset($name)) {
return isset($this->namedBuffer[ $name ]) ? $this->namedBuffer[ $name ] : null; return ($this->namedBuffer[ $name ] ?? null);
} else { } else {
return $this->namedBuffer; return $this->namedBuffer;
} }

View File

@@ -120,14 +120,12 @@ class Smarty_Internal_Runtime_GetIncludePath
public function getIncludePath($dirs, $file, Smarty $smarty) public function getIncludePath($dirs, $file, Smarty $smarty)
{ {
//if (!(isset($this->_has_stream_include) ? $this->_has_stream_include : $this->_has_stream_include = false)) { //if (!(isset($this->_has_stream_include) ? $this->_has_stream_include : $this->_has_stream_include = false)) {
if (!(isset($this->_has_stream_include) ? $this->_has_stream_include : if (!($this->_has_stream_include ?? ($this->_has_stream_include = function_exists('stream_resolve_include_path')))) {
$this->_has_stream_include = function_exists('stream_resolve_include_path'))
) {
$this->isNewIncludePath($smarty); $this->isNewIncludePath($smarty);
} }
// try PHP include_path // try PHP include_path
foreach ($dirs as $dir) { foreach ($dirs as $dir) {
$dir_n = isset($this->number[ $dir ]) ? $this->number[ $dir ] : $this->number[ $dir ] = $this->counter++; $dir_n = $this->number[ $dir ] ?? ($this->number[ $dir ] = $this->counter++);
if (isset($this->isFile[ $dir_n ][ $file ])) { if (isset($this->isFile[ $dir_n ][ $file ])) {
if ($this->isFile[ $dir_n ][ $file ]) { if ($this->isFile[ $dir_n ][ $file ]) {
return $this->isFile[ $dir_n ][ $file ]; return $this->isFile[ $dir_n ][ $file ];
@@ -153,14 +151,13 @@ class Smarty_Internal_Runtime_GetIncludePath
$this->_user_dirs[ $dir_n ] = $dir; $this->_user_dirs[ $dir_n ] = $dir;
} }
if ($this->_has_stream_include) { if ($this->_has_stream_include) {
$path = stream_resolve_include_path($dir . (isset($file) ? $file : '')); $path = stream_resolve_include_path($dir . ($file ?? ''));
if ($path) { if ($path) {
return $this->isFile[ $dir_n ][ $file ] = $path; return $this->isFile[ $dir_n ][ $file ] = $path;
} }
} else { } else {
foreach ($this->_include_dirs as $key => $_i_path) { foreach ($this->_include_dirs as $key => $_i_path) {
$path = isset($this->isPath[ $key ][ $dir_n ]) ? $this->isPath[ $key ][ $dir_n ] : $path = $this->isPath[ $key ][ $dir_n ] ?? ($this->isPath[ $key ][ $dir_n ] = is_dir($_dir_path = $_i_path . $dir) ? $_dir_path : false);
$this->isPath[ $key ][ $dir_n ] = is_dir($_dir_path = $_i_path . $dir) ? $_dir_path : false;
if ($path === false) { if ($path === false) {
continue; continue;
} }

View File

@@ -141,7 +141,7 @@ class Smarty_Internal_Runtime_Inheritance
*/ */
public function instanceBlock(Smarty_Internal_Template $tpl, $className, $name, $tplIndex = null) public function instanceBlock(Smarty_Internal_Template $tpl, $className, $name, $tplIndex = null)
{ {
$block = new $className($name, isset($tplIndex) ? $tplIndex : $this->tplIndex); $block = new $className($name, ($tplIndex ?? $this->tplIndex));
if (isset($this->childRoot[ $name ])) { if (isset($this->childRoot[ $name ])) {
$block->child = $this->childRoot[ $name ]; $block->child = $this->childRoot[ $name ];
} }

View File

@@ -21,8 +21,7 @@ class Smarty_Internal_Runtime_TplFunction
*/ */
public function callTemplateFunction(Smarty_Internal_Template $tpl, $name, $params, $nocache) public function callTemplateFunction(Smarty_Internal_Template $tpl, $name, $params, $nocache)
{ {
$funcParam = isset($tpl->tplFunctions[ $name ]) ? $tpl->tplFunctions[ $name ] : $funcParam = $tpl->tplFunctions[ $name ] ?? ($tpl->smarty->tplFunctions[ $name ] ?? null);
(isset($tpl->smarty->tplFunctions[ $name ]) ? $tpl->smarty->tplFunctions[ $name ] : null);
if (isset($funcParam)) { if (isset($funcParam)) {
if (!$tpl->caching || ($tpl->caching && $nocache)) { if (!$tpl->caching || ($tpl->caching && $nocache)) {
$function = $funcParam[ 'call_name' ]; $function = $funcParam[ 'call_name' ];
@@ -84,8 +83,7 @@ class Smarty_Internal_Runtime_TplFunction
public function getTplFunction(Smarty_Internal_Template $tpl, $name = null) public function getTplFunction(Smarty_Internal_Template $tpl, $name = null)
{ {
if (isset($name)) { if (isset($name)) {
return isset($tpl->tplFunctions[ $name ]) ? $tpl->tplFunctions[ $name ] : return ($tpl->tplFunctions[ $name ] ?? ($tpl->smarty->tplFunctions[ $name ] ?? false));
(isset($tpl->smarty->tplFunctions[ $name ]) ? $tpl->smarty->tplFunctions[ $name ] : false);
} else { } else {
return empty($tpl->tplFunctions) ? $tpl->smarty->tplFunctions : $tpl->tplFunctions; return empty($tpl->tplFunctions) ? $tpl->smarty->tplFunctions : $tpl->tplFunctions;
} }

View File

@@ -221,7 +221,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
$this->smarty->ext->_cacheModify->cacheModifiedCheck( $this->smarty->ext->_cacheModify->cacheModifiedCheck(
$this->cached, $this->cached,
$this, $this,
isset($content) ? $content : ob_get_clean() ($content ?? ob_get_clean())
); );
} else { } else {
if ((!$this->caching || $this->cached->has_nocache_code || $this->source->handler->recompiled) if ((!$this->caching || $this->cached->has_nocache_code || $this->source->handler->recompiled)
@@ -292,7 +292,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
$smarty = &$this->smarty; $smarty = &$this->smarty;
$_templateId = $smarty->_getTemplateId($template, $cache_id, $compile_id, $caching, $tpl); $_templateId = $smarty->_getTemplateId($template, $cache_id, $compile_id, $caching, $tpl);
// recursive call ? // recursive call ?
if (isset($tpl->templateId) ? $tpl->templateId : $tpl->_getTemplateId() !== $_templateId) { if (($tpl->templateId ?? $tpl->_getTemplateId()) !== $_templateId) {
// already in template cache? // already in template cache?
if (isset(self::$tplObjCache[ $_templateId ])) { if (isset(self::$tplObjCache[ $_templateId ])) {
// copy data from cached object // copy data from cached object
@@ -537,7 +537,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
} else { } else {
$tpl->mustCompile = !$is_valid; $tpl->mustCompile = !$is_valid;
$resource = $tpl->compiled; $resource = $tpl->compiled;
$resource->includes = isset($properties[ 'includes' ]) ? $properties[ 'includes' ] : array(); $resource->includes = $properties[ 'includes' ] ?? array();
} }
if ($is_valid) { if ($is_valid) {
$resource->unifunc = $properties[ 'unifunc' ]; $resource->unifunc = $properties[ 'unifunc' ];
@@ -579,8 +579,8 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
*/ */
public function _getTemplateId() public function _getTemplateId()
{ {
return isset($this->templateId) ? $this->templateId : $this->templateId = return ($this->templateId ?? ($this->templateId =
$this->smarty->_getTemplateId($this->template_resource, $this->cache_id, $this->compile_id); $this->smarty->_getTemplateId($this->template_resource, $this->cache_id, $this->compile_id)));
} }
/** /**

View File

@@ -186,7 +186,7 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
} else { } else {
// get template object // get template object
$saveVars = false; $saveVars = false;
$template = $smarty->createTemplate($template, $cache_id, $compile_id, $parent ? $parent : $this, false); $template = $smarty->createTemplate($template, $cache_id, $compile_id, ($parent ?? $this), false);
if ($this->_objType === 1) { if ($this->_objType === 1) {
// set caching in template object // set caching in template object
$template->caching = $this->caching; $template->caching = $this->caching;

View File

@@ -428,8 +428,8 @@ abstract class Smarty_Internal_TemplateCompilerBase
} }
$this->smarty->_debug->start_compile($this->template); $this->smarty->_debug->start_compile($this->template);
} }
$this->parent_compiler = $parent_compiler ? $parent_compiler : $this; $this->parent_compiler = $parent_compiler ?? $this;
$nocache = isset($nocache) ? $nocache : false; $nocache = $nocache ?? false;
if (empty($template->compiled->nocache_hash)) { if (empty($template->compiled->nocache_hash)) {
$template->compiled->nocache_hash = $this->nocache_hash; $template->compiled->nocache_hash = $this->nocache_hash;
} else { } else {
@@ -1029,7 +1029,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
$_scope = $_scopeName; $_scope = $_scopeName;
} elseif (is_string($_scopeName)) { } elseif (is_string($_scopeName)) {
$_scopeName = trim($_scopeName, '\'"'); $_scopeName = trim($_scopeName, '\'"');
$_scope = isset($validScopes[ $_scopeName ]) ? $validScopes[ $_scopeName ] : false; $_scope = $validScopes[ $_scopeName ] ?? false;
} else { } else {
$_scope = false; $_scope = false;
} }

View File

@@ -54,7 +54,7 @@ abstract class Smarty_Resource_Custom extends Smarty_Resource
$source->timestamp = $mtime; $source->timestamp = $mtime;
} else { } else {
$this->fetch($source->name, $content, $timestamp); $this->fetch($source->name, $content, $timestamp);
$source->timestamp = isset($timestamp) ? $timestamp : false; $source->timestamp = $timestamp ?? false;
if (isset($content)) { if (isset($content)) {
$source->content = $content; $source->content = $content;
} }

View File

@@ -230,7 +230,7 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
if (!$_template->source->handler->recompiled) { if (!$_template->source->handler->recompiled) {
return file_get_contents($this->filepath); return file_get_contents($this->filepath);
} }
return isset($this->content) ? $this->content : false; return ($this->content ?? false);
} }
/** /**

View File

@@ -135,9 +135,7 @@ class Smarty_Template_Source
*/ */
public function __construct(Smarty $smarty, $resource, $type, $name) public function __construct(Smarty $smarty, $resource, $type, $name)
{ {
$this->handler = $this->handler = $smarty->_cache[ 'resource_handlers' ][ $type ] ?? Smarty_Resource::load($smarty, $type);
isset($smarty->_cache[ 'resource_handlers' ][ $type ]) ? $smarty->_cache[ 'resource_handlers' ][ $type ] :
Smarty_Resource::load($smarty, $type);
$this->smarty = $smarty; $this->smarty = $smarty;
$this->resource = $resource; $this->resource = $resource;
$this->type = $type; $this->type = $type;
@@ -208,6 +206,6 @@ class Smarty_Template_Source
*/ */
public function getContent() public function getContent()
{ {
return isset($this->content) ? $this->content : $this->handler->getContent($this); return ($this->content ?? $this->handler->getContent($this));
} }
} }