buttress / phpx-compile
PHPX 编译器
v0.2
2024-03-12 05:16 UTC
Requires
- php: >=8
- nikic/php-parser: ^5.0
Requires (Dev)
- buttress/phpx: ^0.2
- laravel/pint: ^1.14
- pestphp/pest: ^2
README
<PHPX compile="true"/>
PHPX 的实验性编译器
PHPX Compile 将 PHPX 编译成更优化的 PHP,显著减少渲染 PHPX 文件时的函数调用。在测试中,我们观察到与纯 PHPX 相比,速度提高了约 6 倍。
编译后的 PHPX 文件仍然是纯 PHP,可以替换现有的模板。
警告
此项目是实验性的,尚未经过验证。预计 PHPX Compile 不总是能生成有效的输出。
<?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') ]), ]) );
变为
<?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>';
安装
要安装 PHPX Compile,请使用 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 一个流畅的 DOMDocument 包装器,它使您能够在纯 PHP 中轻松编写安全有效的 HTML。
- PHPX Templates 建立在 PHPX 和 PHPX Compile 之上的实验性模板引擎。
贡献
欢迎对 PHPX Compile 的贡献!请随意 Fork 存储库并提交拉取请求。
许可证
PHPX 在 MIT 许可证下发布。
Githooks
要添加我们的 githooks 并在提交之前运行测试
git config --local core.hooksPath .githooks
支持
如果您遇到任何问题或有任何疑问,请在 GitHub 上提交一个问题。
感谢您查看 PHPX Compile ❤️