本文整理汇总了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));
}
示例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");
}
示例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));
}