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

A few deprecation fixes #11544

Merged
Merged
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
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
Loading