<PHPX compile="true"/>
An experimental compiler for PHPX
PHPX Compile compiles PHPX into more optimized PHP significantly reducing function calls when rendering PHPX files. With the example used in tests we see about a 6x speed improvement over plain PHPX
Compiled PHPX files are still plain PHP and can be swapped out for existing templates.
Warning
This project is experimental and has not been proven. Expect PHPX Compile to not always produce working output.
<?php
$x = new Buttress\Phpx\Phpx();
$github = 'https://github.com/buttress/phpx';
return $x->render(
$x->div(class: 'content', c: [
$x->h1(id: 'title', c: 'Hello World!'),
$x->p(c: [
'Brought to you by ',
$x->a(href: $github, c: 'PHPX')
]),
])
);
becomes
<?php
$x = new Buttress\Phpx\Phpx();
$github = 'https://github.com/buttress/phpx';
return '<div class="content"><h1 id="title">Hello World!</h1>'.'<p>Brought to you by '.'<a href="'.htmlspecialchars($github, 50).'">PHPX</a>'.'</p>'.'</div>';
To install PHPX Compile, use composer:
composer require buttress/phpx-compile
/** Basic Usage */
$parser = (new \PhpParser\ParserFactory())->createForHostVersion();
$compiler = new \Buttress\Compiler($parser);
$phpxVariable = 'x'; // The variable name I use in my phpx files.
$input = file_get_contents('/my_file_that_uses_phpx');
$php = $compiler->compile($input, $phpxVariable);
- PHPX A fluent DOMDocument wrapper that makes it easy to write safe valid HTML in plain PHP.
- PHPX Templates An experimental template engine built around PHPX and PHPX Compile.
Contributions to PHPX Compile are always welcome! Feel free to fork the repository and submit a pull request.
PHPX is released under the MIT License.
To add our githooks and run tests before commit:
git config --local core.hooksPath .githooks
If you encounter any problems or have any questions, please open an issue on GitHub.
Thanks for checking out PHPX Compile ❤️