承接 silent/twig-const-resolver 相关项目开发

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

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

silent/twig-const-resolver

最新稳定版本:1.1.1

Composer 安装命令:

composer require silent/twig-const-resolver

包简介

Simple Twig plugin to resolve constant on template cache build

README 文档

README

Packagist Travis Coveralls

Simple Twig plugin to resolve constant on template cache build.

Why

For example we have something like this:

{% if usertype == constant('Users::TYPE_TROLL') %}
    Bye-bye
{% else %}
    Hello!
{% endif %}

Without this extension Twig will compile it in something like this:

if (((isset($context["usertype"]) ? $context["usertype"] : null) == twig_constant("Users::TYPE_TROLL"))) {
    // twig_constant will be evaluated in runtime
    echo "Bye-bye";
} else {
    echo "Hello";
}

It will be compiled even if you have no constant with that name. So you will get an error in production.

With this extension you can avoid this types of errors cause it will evaluate constants at the build step, so this template will be compiled in something like this:

if (((isset($context["usertype"]) ? $context["usertype"] : null) == Users::TYPE_TROLL)) {
    // constant is resolved at the build step (Users::TYPE_TROLL)
    echo "Bye-bye";
} else {
    echo "Hello";
}

Also in evaluation mode it can be compiled in something like this:

if (((isset($context["usertype"]) ? $context["usertype"] : null) == 2)) {
    // constant is resolved and evaluated at the build step (Users::TYPE_TROLL => 2)
    echo "Bye-bye";
} else {
    echo "Hello";
}

Installation

The extension is installable via composer:

{
    "require": {
        "silent/twig-const-resolver": "~1.1"
    }
}

Setup

$twig->addExtension(
    /**
     * @param $evaluate bool Evaluate consts (default: false)
     */
    new \silent\Twig\ConstantResolverExtension\Extension()
);

统计信息

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

GitHub 信息

  • Stars: 2
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-09-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固