承接 skrz/templating-engine 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

skrz/templating-engine

Composer 安装命令:

composer require skrz/templating-engine

包简介

Like Smarty, but faster

README 文档

README

Like Smarty, but faster

Why?

At Skrz.cz, the largest Czech best-prices search engine, we heavily use Smarty. However, Smarty's official implementation ceased to meet our needs, mainly regarding performance.

Skrz\Templating\Engine is Smarty syntax-compatible. Not every Smarty construct has been implemented. You can think of what has been implemented as the good parts.

Key design decisions are:

  • Compile time and run time are strictly separated. When you do ->display(...), or ->fetch(...) in Smarty, many things can happen. Smarty checks if the template has been compiled, if compiled code is still valid, if cached content hasn't been hit, etc. Skrz\Templating\Engine does none of that.

  • Compilation is managed by external tool. At Skrz we use Grunt to compile CSS, Javascript, and also templates in development.

  • Compilation output is an autoload-able class, rendering should be encapsulated in a method. Smarty compiles templates into a bunch of functions that reside inside if statements, so they cannot be declared twice. With JIT-ing PHP implementations coming up (HHVM, PHP-NG, HippyVM), this is quite sub-optimal, because certain optimizations cannot be applied (e.g. HHVM can optimize file inclusion that only contains classes at the top level, into just populating class tables).

Usage

Skrz\Templating\Engine provides only parser and compiler. Please refer to tests on how they are used.

Basically, you just create ParserContext, parse template file, create CompilerContext, and compile into output file.

Let's say, you have template MyTemplate.tpl in current directory and want to compile it into MyTemplate.php:

$outputFileName = __DIR__ . "/MyTemplate.php";

$parserContext = new ParserContext();
$parserContext
    ->addPath(__DIR__);
    ->setFile("MyTemplate.tpl");

$compilerContext = new CompilerContext();
$compilerContext
    ->setParserContext($parserContext)
    ->setClassName("MyTemplate")
    ->setTemplate($parserContext->parse())
    ->setOutputFileName($outputFileName)
    ->dump();

License

The MIT license. See LICENSE file.

统计信息

  • 总下载量: 34.61k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 3
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-08-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固