vendor/symfony/ux-twig-component/src/Twig/ComponentLexer.php line 34

  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  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 Symfony\UX\TwigComponent\Twig;
  11. use Twig\Lexer;
  12. use Twig\Source;
  13. use Twig\TokenStream;
  14. /**
  15.  * @author Mathèo Daninos <matheo.daninos@gmail.com>
  16.  *
  17.  * @internal
  18.  *
  19.  * thanks to @giorgiopogliani for the inspiration on this lexer <3
  20.  *
  21.  * @see https://github.com/giorgiopogliani/twig-components
  22.  */
  23. class ComponentLexer extends Lexer
  24. {
  25.     public function tokenize(Source $source): TokenStream
  26.     {
  27.         $preLexer = new TwigPreLexer();
  28.         $preparsed $preLexer->preLexComponents($source->getCode());
  29.         return parent::tokenize(
  30.             new Source(
  31.                 $preparsed,
  32.                 $source->getName(),
  33.                 $source->getPath()
  34.             )
  35.         );
  36.     }
  37. }