blob: 5ff44307fc5189968be4696675215b341d63adce [file] [log] [blame]
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +01001<?php
2
3/*
4 * This file is part of Twig.
5 *
6 * (c) Fabien Potencier
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Twig\Node;
13
14use Twig\Compiler;
15use Twig\Node\Expression\AbstractExpression;
16use Twig\Node\Expression\ConstantExpression;
17
18/**
19 * Represents a deprecated node.
20 *
21 * @author Yonel Ceruto <yonelceruto@gmail.com>
22 */
23class DeprecatedNode extends Node
24{
25 public function __construct(AbstractExpression $expr, int $lineno, string $tag = null)
26 {
27 parent::__construct(['expr' => $expr], [], $lineno, $tag);
28 }
29
30 public function compile(Compiler $compiler): void
31 {
32 $compiler->addDebugInfo($this);
33
34 $expr = $this->getNode('expr');
35
36 if ($expr instanceof ConstantExpression) {
37 $compiler->write('@trigger_error(')
38 ->subcompile($expr);
39 } else {
40 $varName = $compiler->getVarName();
41 $compiler->write(sprintf('$%s = ', $varName))
42 ->subcompile($expr)
43 ->raw(";\n")
44 ->write(sprintf('@trigger_error($%s', $varName));
45 }
46
47 $compiler
48 ->raw('.')
49 ->string(sprintf(' ("%s" at line %d).', $this->getTemplateName(), $this->getTemplateLine()))
50 ->raw(", E_USER_DEPRECATED);\n")
51 ;
52 }
53}