本文整理汇总了PHP中Twig_Node_Expression_Array::hasElement方法的典型用法代码示例。如果您正苦于以下问题:PHP Twig_Node_Expression_Array::hasElement方法的具体用法?PHP Twig_Node_Expression_Array::hasElement怎么用?PHP Twig_Node_Expression_Array::hasElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Twig_Node_Expression_Array
的用法示例。
在下文中一共展示了Twig_Node_Expression_Array::hasElement方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: escapeContextVariables
/**
* @param string $msg
* @param \Twig_Node_Expression_Array $vars
* @param int $lineno
* @return \Twig_Node_Expression_Array
*/
protected function escapeContextVariables($msg, $vars, $lineno)
{
preg_match_all('/(?<!%)%([^%]+)%/', $msg, $matches);
foreach ($matches[1] as $var) {
$key = new \Twig_Node_Expression_Constant('%' . $var . '%', $lineno);
if (!$vars->hasElement($key)) {
$node = new \Twig_Node_Expression_Name($var, $lineno);
$node = $this->escapeNodeIfNecessary($node, $lineno);
$vars->addElement($node, $key);
}
}
return $vars;
}
示例3: 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);
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);
}
}
return array(new \Twig_Node_Expression_Constant(str_replace('%%', '%', trim($msg)), $body->getLine()), $vars);
}
示例4: compileString
protected function compileString(\Twig_NodeInterface $body, \Twig_Node_Expression_Array $vars, $ignoreStrictCheck = false)
{
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);
foreach ($matches[1] as $var) {
$key = new \Twig_Node_Expression_Constant('%' . $var . '%', $body->getLine());
if (!$vars->hasElement($key)) {
if ('count' === $var && null !== $this->getNode('count')) {
$vars->addElement($this->getNode('count'), $key);
} else {
$varExpr = new \Twig_Node_Expression_Name($var, $body->getLine());
$varExpr->setAttribute('ignore_strict_check', $ignoreStrictCheck);
$vars->addElement($varExpr, $key);
}
}
}
return array(new \Twig_Node_Expression_Constant(str_replace('%%', '%', trim($msg)), $body->getLine()), $vars);
}