Problem/Motivation
Twig has a wonderful AST debug printer which is broken with Drupal.
Steps to reproduce
$twig = \Drupal::service('twig');
$string = '{{ foo }}';
$stream = $twig->tokenize(new \Twig\Source($string, '{# inline_template_start #}'));
$nodes = $twig->parse($stream);
$twig->compile($nodes);
print $nodes;
errors out with var_export does not handle circular references Node.php:56
I believe I have hunted the problem to the class resolver https://gist.github.com/chx/df272b847b2770be00f6b7b8bf1b5ff8 but it's not yet clear what are the next steps. To be continued tomorrow.
Proposed resolution
Note adding DependencySerializationTrait to TwigExtension does not help -- especially because ClassResolver already has it. Yet, the problem lies somewhere there. Hiding the container from the eyes of var_export does help, ContainerAwareTrait could store https://gist.github.com/chx/6a0388e79b527b6bbcea6956f5225821 instead of the raw container. This is, of course, extremely ugly. To be continued tomorrow.
Comments
Comment #2
ghost of drupal pastComment #3
ghost of drupal pasthttps://github.com/twigphp/Twig/pull/3694