Is Rector able to convert PHP templates to TWIG? #7097
-
|
Hi, the Mautic open source project is using Symfony's PHP templates but support for that was removed in Symfony 5. We are in process to update to Symfony 5 and this is one of the biggest pains to get there. I know this is a niche problem as every other project use twig so we'd have to write the rules ourselves. But I wanted to confirm with someone with more Rector experience whether it is even possible. The template files are obviously heavily infected with HTML and I know that other tools like CS fixers don't play nicely with these templates. Here is an example of a PHP template file that needs converting to TWIG: https://github.com/mautic/mautic/blob/4.x/app/bundles/LeadBundle/Views/Lead/lead.html.php |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
|
Hi Honza,
I disagree, there are many projects who use PHP templates and need to migrate too. It would be great addition to https://github.com/rectorphp/rector-symfony The other way around would be very hard, as there is no easy to use Twig-AST parser. E.g. writing printer for echo $value;that would dump a string: {{ value }} |
Beta Was this translation helpful? Give feedback.
-
|
Folks here might be interested in https://github.com/makinacorpus/php-twig-converter (I'm not involved with that project, just found it via a Google search). Last commit there was 7 years ago, so I don't know how much mileage you'll get from it, but it could be a helpful start nonetheless. |
Beta Was this translation helpful? Give feedback.
Hi Honza,
I love this crazy idea :)
I disagree, there are many projects who use PHP templates and need to migrate too. It would be great addition to https://github.com/rectorphp/rector-symfony
The other way around would be very hard, as there is no easy to use Twig-AST parser.
But parsing PHP and dumping TWIG is easy. All you need is a custom printer - https://github.com/rectorphp/rector-src/blob/be530c5e2f56190f5fe1813ae4344cdaf3f75d7f/src/PhpParser/Printer/BetterStandardPrinter.php#L40
E.g. writing printer for
Echo_:that would dump a string:
{{ value }}