当前位置: 首页>>代码示例>>PHP>>正文


PHP Twig_Compiler::getVarName方法代码示例

本文整理汇总了PHP中Twig_Compiler::getVarName方法的典型用法代码示例。如果您正苦于以下问题:PHP Twig_Compiler::getVarName方法的具体用法?PHP Twig_Compiler::getVarName怎么用?PHP Twig_Compiler::getVarName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Twig_Compiler的用法示例。


在下文中一共展示了Twig_Compiler::getVarName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: compile

 public function compile(\Twig_Compiler $compiler)
 {
     if (PHP_VERSION_ID >= 70000) {
         $compiler->raw('is_numeric(')->subcompile($this->getNode('node'))->raw(')');
         return;
     }
     // Forward support towards PHP 7.
     // Strings in hexadecimal notation are no longer regarded as `numeric`,
     // for example: `is_numeric('0xf4c3b00c')` returns `false`.
     // @see https://secure.php.net/manual/en/function.is-numeric.php
     $var = $compiler->getVarName();
     $compiler->raw(sprintf('(is_numeric($%s = ', $var))->subcompile($this->getNode('node'))->raw(sprintf(') && (!is_string($%s) || (strlen($%s) < 2 || (\'x\' !== $%s[1] && \'X\' !== $%s[1]))))', $var, $var, $var, $var));
 }
开发者ID:GeckoPackages,项目名称:GeckoTwig,代码行数:13,代码来源:NumericTest.php

示例2: compile

 public function compile(Twig_Compiler $compiler)
 {
     $compiler->addDebugInfo($this);
     if ($this->hasNode('variables')) {
         $varsName = $compiler->getVarName();
         $compiler->write(sprintf('$%s = ', $varsName))->subcompile($this->getNode('variables'))->raw(";\n")->write(sprintf("if (!is_array(\$%s)) {\n", $varsName))->indent()->write("throw new Twig_Error_Runtime('Variables passed to the \"with\" tag must be a hash.');\n")->outdent()->write("}\n");
         if ($this->getAttribute('only')) {
             $compiler->write("\$context = array('_parent' => \$context);\n");
         } else {
             $compiler->write("\$context['_parent'] = \$context;\n");
         }
         $compiler->write(sprintf("\$context = array_merge(\$context, \$%s);\n", $varsName));
     } else {
         $compiler->write("\$context['_parent'] = \$context;\n");
     }
     $compiler->subcompile($this->getNode('body'))->write("\$context = \$context['_parent'];\n");
 }
开发者ID:naldz,项目名称:cyberden,代码行数:17,代码来源:With.php

示例3: compile

 public function compile(Twig_Compiler $compiler)
 {
     $left = $compiler->getVarName();
     $right = $compiler->getVarName();
     $compiler->raw(sprintf('(is_string($%s = ', $left))->subcompile($this->getNode('left'))->raw(sprintf(') && is_string($%s = ', $right))->subcompile($this->getNode('right'))->raw(sprintf(') && (\'\' === $%2$s || 0 === strpos($%1$s, $%2$s)))', $left, $right));
 }
开发者ID:idwsdta,项目名称:INIT-frame,代码行数:6,代码来源:StartsWith.php


注:本文中的Twig_Compiler::getVarName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。