vendor/twig/twig/src/Node/Expression/AssignNameExpression.php line 25

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of Twig.
  4.  *
  5.  * (c) Fabien Potencier
  6.  * (c) Armin Ronacher
  7.  *
  8.  * For the full copyright and license information, please view the LICENSE
  9.  * file that was distributed with this source code.
  10.  */
  11. namespace Twig\Node\Expression;
  12. use Twig\Compiler;
  13. use Twig\Error\SyntaxError;
  14. use Twig\Node\Expression\Variable\AssignContextVariable;
  15. use Twig\Node\Expression\Variable\ContextVariable;
  16. class AssignNameExpression extends ContextVariable
  17. {
  18.     public function __construct(string $nameint $lineno)
  19.     {
  20.         if (self::class === static::class) {
  21.             trigger_deprecation('twig/twig''3.15''The "%s" class is deprecated, use "%s" instead.'self::class, AssignContextVariable::class);
  22.         }
  23.         // All names supported by ExpressionParser::parsePrimaryExpression() should be excluded
  24.         if (\in_array(strtolower($name), ['true''false''none''null'], true)) {
  25.             throw new SyntaxError(\sprintf('You cannot assign a value to "%s".'$name), $lineno);
  26.         }
  27.         parent::__construct($name$lineno);
  28.     }
  29.     public function compile(Compiler $compiler): void
  30.     {
  31.         $compiler
  32.             ->raw('$context[')
  33.             ->string($this->getAttribute('name'))
  34.             ->raw(']')
  35.         ;
  36.     }
  37. }