本文整理匯總了PHP中Twig_Node_Expression_Array::setNode方法的典型用法代碼示例。如果您正苦於以下問題:PHP Twig_Node_Expression_Array::setNode方法的具體用法?PHP Twig_Node_Expression_Array::setNode怎麽用?PHP Twig_Node_Expression_Array::setNode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Twig_Node_Expression_Array
的用法示例。
在下文中一共展示了Twig_Node_Expression_Array::setNode方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: compileString
protected function compileString(\Twig_NodeInterface $body, \Twig_Node_Expression_Array $vars)
{
if ($body instanceof \Twig_Node_Expression_Constant) {
$msg = $body->getAttribute('value');
} elseif ($body instanceof \Twig_Node_Text) {
$msg = $body->getAttribute('data');
} else {
return array($body, $vars);
}
preg_match_all('/(?<!%)%([^%]+)%/', $msg, $matches);
if (version_compare(\Twig_Environment::VERSION, '1.5', '>=')) {
foreach ($matches[1] as $var) {
$key = new \Twig_Node_Expression_Constant('%' . $var . '%', $body->getLine());
if (!$vars->hasElement($key)) {
$vars->addElement(new \Twig_Node_Expression_Name($var, $body->getLine()), $key);
}
}
} else {
$current = array();
foreach ($vars as $name => $var) {
$current[$name] = true;
}
foreach ($matches[1] as $var) {
if (!isset($current['%' . $var . '%'])) {
$vars->setNode('%' . $var . '%', new \Twig_Node_Expression_Name($var, $body->getLine()));
}
}
}
return array(new \Twig_Node_Expression_Constant(str_replace('%%', '%', trim($msg)), $body->getLine()), $vars);
}
示例2: compileString
protected function compileString(\Twig_NodeInterface $body, \Twig_Node_Expression_Array $vars)
{
if ($body instanceof \Twig_Node_Expression_Constant) {
$msg = $body->getAttribute('value');
} elseif ($body instanceof \Twig_Node_Text) {
$msg = $body->getAttribute('data');
} else {
return array($body, $vars);
}
$current = array();
foreach ($vars as $name => $var) {
$current[$name] = true;
}
preg_match_all('/\\%([^\\%]+)\\%/', $msg, $matches);
foreach ($matches[1] as $var) {
if (!isset($current['%' . $var . '%'])) {
$vars->setNode('%' . $var . '%', new \Twig_Node_Expression_Name($var, $body->getLine()));
}
}
return array(new \Twig_Node_Expression_Constant(trim($msg), $body->getLine()), $vars);
}