Skip to content

Commit

Permalink
minor #4603 remove not needed code (xabbuh, fabpot)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.x branch.

Discussion
----------

remove not needed code

Commits
-------

719bba9 Simplify code
da64c42 Add tests
53facb7 remove not needed code
  • Loading branch information
fabpot committed Feb 28, 2025
2 parents 71f83ec + 719bba9 commit 1fee48e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/Error/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,12 @@ private function guessTemplateInfo(): void

$this->lineno = 0;
$template = null;
$templateClass = null;
$backtrace = debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS | \DEBUG_BACKTRACE_PROVIDE_OBJECT);
foreach ($backtrace as $trace) {
if (isset($trace['object']) && $trace['object'] instanceof Template) {
$currentClass = \get_class($trace['object']);
$isEmbedContainer = null === $templateClass ? false : str_starts_with($templateClass, $currentClass);
if ($this->source->getName() === $trace['object']->getTemplateName() && !$isEmbedContainer) {
$template = $trace['object'];
$templateClass = \get_class($trace['object']);

break;
}
if (isset($trace['object']) && $trace['object'] instanceof Template && $this->source->getName() === $trace['object']->getTemplateName()) {
$template = $trace['object'];

break;
}
}

Expand Down
25 changes: 25 additions & 0 deletions tests/ErrorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,31 @@ public static function getErroredTemplates()
],
'index', 3,
],

// error occurs in an embed tag
[
[
'index' => "
{% embed 'base' %}
{% endembed %}",
'base' => '{% block foo %}{{ foo.bar }}{% endblock %}',
],
'base', 1,
],

// error occurs in an overridden block from an embed tag
[
[
'index' => "
{% embed 'base' %}
{% block foo %}
{{ foo.bar }}
{% endblock %}
{% endembed %}",
'base' => '{% block foo %}{% endblock %}',
],
'index', 4,
],
];
}

Expand Down

0 comments on commit 1fee48e

Please sign in to comment.