本文整理汇总了PHP中XenForo_Template_Compiler::getVariableMap方法的典型用法代码示例。如果您正苦于以下问题:PHP XenForo_Template_Compiler::getVariableMap方法的具体用法?PHP XenForo_Template_Compiler::getVariableMap怎么用?PHP XenForo_Template_Compiler::getVariableMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XenForo_Template_Compiler
的用法示例。
在下文中一共展示了XenForo_Template_Compiler::getVariableMap方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: compile
/**
* Compile the specified tag and return PHP code to handle it.
*
* @param XenForo_Template_Compiler The invoking compiler
* @param string Name of the tag called
* @param array Attributes for the tag (may be empty)
* @param array Nodes (tags/curlies/text) within this tag (may be empty)
* @param array Compilation options
*
* @return string
*/
public function compile(XenForo_Template_Compiler $compiler, $tag, array $attributes, array $children, array $options)
{
if (empty($options['allowRawStatements'])) {
throw $compiler->getNewCompilerException(new XenForo_Phrase('x_tags_only_used_where_full_statements_allowed', array('tag' => 'include')));
}
if (empty($attributes['template']) || count($attributes['template']) != 1 || !is_string($attributes['template'][0])) {
throw $compiler->getNewCompilerException(new XenForo_Phrase('invalid_template_include_specified'));
}
$include = $attributes['template'][0];
$template = $compiler->includeParsedTemplate($include);
$statement = $compiler->getNewRawStatement();
$tempVars = array();
$mapVars = array();
foreach ($children as $child) {
if ($compiler->isSegmentNamedTag($child, 'map')) {
$childAttr = $child['attributes'];
if (empty($childAttr['from']) || empty($childAttr['to'])) {
throw $compiler->getNewCompilerException(new XenForo_Phrase('included_template_variable_mappings_must_include_from_and_to_attributes'));
}
$from = $compiler->compileVarRef($childAttr['from'], $options);
if (count($childAttr['to']) != 1 || !is_string($childAttr['to'][0])) {
throw $compiler->getNewCompilerException(new XenForo_Phrase('invalid_template_include_variable_mapping_specified'));
}
if (!preg_match('#^\\$([a-zA-Z_][a-zA-Z0-9_]*)$#', $childAttr['to'][0])) {
throw $compiler->getNewCompilerException(new XenForo_Phrase('invalid_template_include_variable_mapping_specified'));
}
// "from $outer" and "to $inner"; when processed (within inner template), need to map the other direction.
$mapVars[substr($childAttr['to'][0], 1)] = substr($from, 1);
} else {
if ($compiler->isSegmentNamedTag($child, 'set')) {
// take var as "to" and compile into a temporary variable
$childAttr = $child['attributes'];
if (empty($childAttr['var'])) {
throw $compiler->getNewCompilerException(new XenForo_Phrase('included_template_variable_assignments_must_include_var_attribute'));
}
if (count($childAttr['var']) != 1 || !is_string($childAttr['var'][0])) {
throw $compiler->getNewCompilerException(new XenForo_Phrase('invalid_template_include_variable_assignment_specified'));
}
$mapRegex = '#^\\$([a-zA-Z_][a-zA-Z0-9_]*)$#';
if (!preg_match($mapRegex, $childAttr['var'][0])) {
throw $compiler->getNewCompilerException(new XenForo_Phrase('invalid_template_include_variable_assignment_specified'));
}
if (!empty($childAttr['value'])) {
if ($child['children']) {
throw $compiler->getNewCompilerException(new XenForo_Phrase('tag_contained_children_and_value_attribute'));
}
$value = $compiler->compileAndCombineSegments($childAttr['value'], array_merge($options, array('varEscape' => false)));
$setVar = $compiler->getUniqueVar();
$childOutput = '$' . $setVar . ' = ' . $value . ";\n";
} else {
$childOutput = $compiler->compileIntoVariable($child['children'], $setVar, $options);
}
$statement->addStatement($childOutput);
$mapVars[substr($childAttr['var'][0], 1)] = $setVar;
$tempVars[] = $setVar;
}
}
}
if ($template) {
$oldMap = $compiler->getVariableMap();
$compiler->setVariableMap($mapVars, true);
$compiled = $compiler->compileIntoVariable($template, $var, $options);
$tempVars[] = $var;
$compiler->setVariableMap($oldMap);
$statement->addStatement($compiled);
$statement->addStatement('$' . $compiler->getOutputVar() . ' .= $' . $var . ";\n" . 'unset($' . implode(', $', $tempVars) . ");\n");
return $statement;
} else {
return '';
}
}