vendor/twig/twig/src/Node/DeprecatedNode.php line 25

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