mcuelenaere/plitz
Composer 安装命令:
composer require mcuelenaere/plitz
包简介
Pure PHP port of Blitz
README 文档
README
Plitz is a pure PHP port of the Blitz PHP template extension.
Installation
Install with composer:
composer require mcuelenaere/plitz
Usage
There are 2 ways to use the functionality provided by Plitz:
Blitz compatibility layer
$template = <<<EOF Hello {{ audience }}! EOF ; $assignments = [ 'audience' => 'world' ]; // construct Blitz object $blitz = new Plitz\Bindings\Blitz\Blitz(); // load template $blitz->load($template); // render template to stdout $blitz->display($assignments);
Direct access to Plitz classes
$template = <<<EOF Hello {{ audience }}! EOF ; $assignments = [ 'audience' => 'world' ]; // wrap template in a simple data:// stream $inputStream = fopen("data://text/plain;base64," . base64_encode($template), "r"); // write compiled template to a memory buffer $outputStream = fopen("php://memory", "r+"); try { // setup the required infrastructure $lexer = new Plitz\Lexer\Lexer($inputStream, "no template filename available"); $compiler = new Plitz\Compilers\PhpCompiler($outputStream); // or perhaps you want the Plitz\Compilers\JsCompiler ? $parser = new Plitz\Parser\Parser($lexer->lex(), $compiler); // lex and parse from the input stream and compile to the output stream $parser->parse(); // retrieve the compiled code from the memory stream fseek($outputStream, 0, SEEK_SET); $compiledCode = stream_get_contents($outputStream); } catch (Plitz\Lexer\LexException $ex) { printf("We got an exception from the lexer: %s (%s: line %d, pos %d)", $ex->getMessage(), $ex->getTemplateName(), $ex->getTemplateLine(), $ex->getTemplateColumn()); exit(1); } catch (Plitz\Parser\ParseException $ex) { printf("We got an exception from the parser: %s (%s: line %d, pos %d)", $ex->getMessage(), $ex->getTemplateName(), $ex->getTemplateLine(), $ex->getTemplateColumn()); exit(1); } finally { // cleanup when we're done fclose($inputStream); fclose($outputStream); } // create a function from the compiled code $templateFunction = create_function('$context', 'ob_start(); ?>' . $compiledCode . '<?php return ob_get_clean();'); // and last but not least: actually run it! echo $templateFunction($assignments);
Design
Plitz consists of 4 components:
- the lexer: tokenizes the input stream into a stream of
Plitz\Lexer\Tokens - the parser: parses a
Plitz\Lexer\TokenStreamand informs aPlitz\Parser\Visitorof the parsed blocks - the compiler: implements the
Plitz\Parser\Visitorclass and writes code to an output stream - the Blitz compatibility layer: wraps all the parts above up in a single class while trying to maintain source-compatibility with
Blitz
mcuelenaere/plitz 适用场景与选型建议
mcuelenaere/plitz 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9.94k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2015 年 02 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 mcuelenaere/plitz 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mcuelenaere/plitz 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 9.94k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: LGPL-2.1
- 更新时间: 2015-02-08