vendor/twig/twig/src/NodeVisitor/YieldNotReadyNodeVisitor.php line 45

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\NodeVisitor;
  11. use Twig\Attribute\YieldReady;
  12. use Twig\Environment;
  13. use Twig\Node\Expression\AbstractExpression;
  14. use Twig\Node\Node;
  15. /**
  16.  * @internal to be removed in Twig 4
  17.  */
  18. final class YieldNotReadyNodeVisitor implements NodeVisitorInterface
  19. {
  20.     private $useYield;
  21.     private $yieldReadyNodes = [];
  22.     public function __construct(bool $useYield)
  23.     {
  24.         $this->useYield $useYield;
  25.     }
  26.     public function enterNode(Node $nodeEnvironment $env): Node
  27.     {
  28.         $class \get_class($node);
  29.         if ($node instanceof AbstractExpression || isset($this->yieldReadyNodes[$class])) {
  30.             return $node;
  31.         }
  32.         if (!$this->yieldReadyNodes[$class] = (bool) (new \ReflectionClass($class))->getAttributes(YieldReady::class)) {
  33.             if ($this->useYield) {
  34.                 throw new \LogicException(sprintf('You cannot enable the "use_yield" option of Twig as node "%s" is not marked as ready for it; please make it ready and then flag it with the #[YieldReady] attribute.'$class));
  35.             }
  36.             trigger_deprecation('twig/twig''3.9''Twig node "%s" is not marked as ready for using "yield" instead of "echo"; please make it ready and then flag it with the #[YieldReady] attribute.'$class);
  37.         }
  38.         return $node;
  39.     }
  40.     public function leaveNode(Node $nodeEnvironment $env): ?Node
  41.     {
  42.         return $node;
  43.     }
  44.     public function getPriority(): int
  45.     {
  46.         return 255;
  47.     }
  48. }