PHP Parser is an awesome tool but falls a little flat in the code generation area. The templating is basic and the syntax in general is quite verbose. Not something you'd want to hand-write or maintain. Also, for some cases, you need a stupid, fast fallback.
PHP-Rapidgen does two things:
- Mix PHP-Parser and handlebars.php, with canonical template traversal, helpers
- Introduce a Shorthand JSON syntax for PHP Parser
Handlebars is a great way to write a lot of static code that might need just a touch of dynamic replacements. PHP Parser is great for super-accurate generation of code.
PHP-Rapidgen uses PHP-Parser as its native source, while also allowing for handlebars templates. Furthermore, you can mix and match them to your heart's content.
This is made possible by a canonical template traversal on the one hand (see below for examples). On the other hand, helpers are natively written in PHP-Parser Syntax (well, a shorthand version) and can also be used from both sources.
Finally, PHP-Rapidgen also handles context canonically such that both handlebars and PHP-Parser derive data from the same source.
Your Project ´´´ project |-- templates | |-- main.handlebars | |-- main.json | +-- simple.php |-- context.json +-- generate.php ´´´
As an example, both the handlebars and the json file produce the same output.
main.handlebars ´´´handlebars