Skip to content

Commit

Permalink
Merge pull request #11544 from creative-commoners/pulls/5/deprecate-o…
Browse files Browse the repository at this point in the history
…ld-syntax

A few deprecation fixes
  • Loading branch information
emteknetnz authored Jan 13, 2025
2 parents bcdd1e2 + 94af2e5 commit 0aa00a6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
8 changes: 7 additions & 1 deletion src/Dev/Deprecation.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ public static function withSuppressedNotice(callable $func): mixed
*/
protected static function get_called_method_from_trace($backtrace, $level = 1)
{
if ($backtrace === null) {
return '';
}
$level = (int)$level;
if (!$level) {
$level = 1;
Expand Down Expand Up @@ -197,8 +200,11 @@ private static function get_called_from_trace(array $backtrace, int $level): arr
return $called;
}

private static function isCalledFromSupportedCode(array $backtrace): bool
private static function isCalledFromSupportedCode(?array $backtrace): bool
{
if ($backtrace === null) {
return false;
}
$called = Deprecation::get_called_from_trace($backtrace, 1);
$file = $called['file'] ?? '';
if (!$file) {
Expand Down
8 changes: 6 additions & 2 deletions src/View/SSTemplateParser.peg
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,9 @@ class SSTemplateParser extends Parser implements TemplateParser
*/
function OldI18NTag_STR(&$res, $sub)
{
$res['php'] = '$val .= ' . $sub['php'] . ';';
$res['php'] = '$val .= ' . $sub['php'] . ';' . Deprecation::class
. '::notice(\'5.4.0\', \'The <% _t() %> template syntax is deprecated. Use <%t %> instead.\', '
. Deprecation::class . '::SCOPE_GLOBAL);';
}

/*!*
Expand Down Expand Up @@ -1153,7 +1155,9 @@ class SSTemplateParser extends Parser implements TemplateParser
if ($res['ArgumentCount'] != 0) {
throw new SSTemplateParseException('Base_tag takes no arguments', $this);
}
return '$val .= \\SilverStripe\\View\\SSViewer::get_base_tag($val);';
$code = '$isXhtml = preg_match(\'/<!DOCTYPE[^>]+xhtml/i\', $val);';
$code .= PHP_EOL . '$val .= \\SilverStripe\\View\\SSViewer::getBaseTag($isXhtml);';
return $code;
}

/**
Expand Down
8 changes: 6 additions & 2 deletions src/View/SSTemplateParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -3748,7 +3748,9 @@ function match_OldI18NTag ($stack = array()) {

function OldI18NTag_STR(&$res, $sub)
{
$res['php'] = '$val .= ' . $sub['php'] . ';';
$res['php'] = '$val .= ' . $sub['php'] . ';' . Deprecation::class
. '::notice(\'5.4.0\', \'The <% _t() %> template syntax is deprecated. Use <%t %> instead.\', '
. Deprecation::class . '::SCOPE_GLOBAL);';
}

/* NamedArgument: Name:Word "=" Value:Argument */
Expand Down Expand Up @@ -4438,7 +4440,9 @@ function OpenBlock_Handle_Base_tag(&$res)
if ($res['ArgumentCount'] != 0) {
throw new SSTemplateParseException('Base_tag takes no arguments', $this);
}
return '$val .= \\SilverStripe\\View\\SSViewer::get_base_tag($val);';
$code = '$isXhtml = preg_match(\'/<!DOCTYPE[^>]+xhtml/i\', $val);';
$code .= PHP_EOL . '$val .= \\SilverStripe\\View\\SSViewer::getBaseTag($isXhtml);';
return $code;
}

/**
Expand Down

0 comments on commit 0aa00a6

Please sign in to comment.