PHP code example of machinateur / twig-comment-lexer

1. Go to this page and download the library: Download machinateur/twig-comment-lexer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

machinateur / twig-comment-lexer example snippets


 /* comment on line 1
 Comment test using real tag
  */



declare(strict_types=1);

namespace Machinateur\Twig\NodeVisitor;

use Machinateur\Twig\Node\CommentNode;
use Twig\Environment;
use Twig\Node\Node;
use Twig\Node\ModuleNode;
use Twig\NodeVisitor\NodeVisitorInterface;

class CommentNodeVisitor implements NodeVisitorInterface
{
    public function enterNode(Node $node, Environment $env): Node
    {
        if ($node instanceof ModuleNode) {
            // TODO: Set up collector node to expose methods in compiled source, if needed at runtime.
        }

        return $node;
    }

    public function leaveNode(Node $node, Environment $env): ?Node
    {
        if ($node instanceof CommentNode) {
            // TODO: Do stuff to the comment's content...
            //  And track it inside the collector node, if needed at runtime.
        }

        return $node;
    }

    /**
     * Priority `0` is the default.
     */
    public function getPriority(): int
    {
        return 0;
    }
}