ngyuki / ephp
ephp 是一个 PHP 模板
dev-master
2020-02-10 02:51 UTC
Requires
- php: ^7.2
- microsoft/tolerant-php-parser: ^0.0.18
Requires (Dev)
- mikey179/vfsstream: ^1.6
This package is auto-updated.
Last update: 2024-09-10 13:21:09 UTC
README
ephp 是一个支持自动转义的纯PHP模板。
示例
<!-- index.phtml --> <strong><?= strtoupper($name) ?></strong>
使用 StreamFilter
(用于开发)。
<?php $filter = new StreamFilter(); (function ($filename, $variables) use ($filter) { extract($variables, EXTR_SKIP); require $filter->path($filename); //=> <strong>A & B</strong> })('index.phtml', ['name' => 'a & b']);
使用 Compiler
(用于生产)。
<?php $sourceDir = __DIR__; $compiledDir = __DIR__ . '/compiled'; $compiler = new Compiler($sourceDir, $compiledDir); (function ($filename, $variables) use ($compiler) { extract($variables, EXTR_SKIP); require $compiler->compile($filename); //=> <strong>A & B</strong> })('index.phtml', ['name' => 'a & b']);