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

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. class AssignNameExpression extends NameExpression
  16. {
  17.     public function __construct(string $nameint $lineno)
  18.     {
  19.         if (self::class === static::class) {
  20.             trigger_deprecation('twig/twig''3.15''The "%s" class is deprecated, use "%s" instead.'self::class, AssignContextVariable::class);
  21.         }
  22.         // All names supported by ExpressionParser::parsePrimaryExpression() should be excluded
  23.         if (\in_array(strtolower($name), ['true''false''none''null'])) {
  24.             throw new SyntaxError(\sprintf('You cannot assign a value to "%s".'$name), $lineno);
  25.         }
  26.         parent::__construct($name$lineno);
  27.     }
  28.     public function compile(Compiler $compiler): void
  29.     {
  30.         $compiler
  31.             ->raw('$context[')
  32.             ->string($this->getAttribute('name'))
  33.             ->raw(']')
  34.         ;
  35.     }
  36. }