本文整理汇总了PHP中XenForo_Template_Compiler::prepareSegmentsForIteration方法的典型用法代码示例。如果您正苦于以下问题:PHP XenForo_Template_Compiler::prepareSegmentsForIteration方法的具体用法?PHP XenForo_Template_Compiler::prepareSegmentsForIteration怎么用?PHP XenForo_Template_Compiler::prepareSegmentsForIteration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XenForo_Template_Compiler
的用法示例。
在下文中一共展示了XenForo_Template_Compiler::prepareSegmentsForIteration方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _getStandardAdminTagData
/**
* Gets the standard data out of a list of segments. Data will be pulled from tags
* in that list and their attributes only.
*
* @param XenForo_Template_Compiler
* @param array List of segments
* @param array An optional list of additional tags that are allowed
*
* @return array Keys are standard data types that were found
*/
protected function _getStandardAdminTagData(XenForo_Template_Compiler $compiler, array $segments, array $extraAllowedTags = array())
{
$segments = $compiler->prepareSegmentsForIteration($segments);
$output = array();
$foundContent = false;
foreach ($segments as $segment) {
if (is_string($segment)) {
if (trim($segment) !== '') {
$foundContent = true;
}
continue;
} else {
if (!isset($segment['type']) || $segment['type'] != 'TAG') {
$foundContent = true;
continue;
}
}
switch ($segment['name']) {
case 'label':
$attributes = $segment['attributes'];
if (isset($attributes['hidden'])) {
$output['labelHidden'] = $attributes['hidden'];
}
if (isset($attributes['hint'])) {
$output['hint'] = $attributes['hint'];
}
$output['label'] = $segment['children'];
break;
case 'hint':
case 'explain':
case 'html':
$output[$segment['name']] = $segment['children'];
break;
default:
if (!$extraAllowedTags || !in_array($segment['name'], $extraAllowedTags)) {
// all other tags are "content" tags
$foundContent = true;
}
}
}
if ($output && $foundContent) {
// found some known tags, some content -- error
throw $compiler->getNewCompilerException(new XenForo_Phrase('found_unexpected_content_within_an_admin_control_tag'));
} else {
if ($foundContent) {
// content only -- treat it as HTML tag
$output = array('html' => $segments);
}
}
return $output;
}
示例2: compile
/**
* Compile the function and return PHP handle it.
*
* @param XenForo_Template_Compiler The invoking compiler
* @param string Name of the function called
* @param array Arguments to the function (should have at least 1)
* @param array Compilation options
*
* @return string
*/
public function compile(XenForo_Template_Compiler $compiler, $function, array $arguments, array $options)
{
if (count($arguments) != 1) {
throw $compiler->getNewCompilerArgumentException();
}
$placeholders = array();
if (is_string($arguments[0])) {
$expression = $arguments[0];
} else {
$expression = '';
foreach ($compiler->prepareSegmentsForIteration($arguments[0]) as $segment) {
if (is_string($segment)) {
if (strpos($segment, '?') !== false) {
throw $compiler->getNewCompilerException(new XenForo_Phrase('invalid_math_expression'));
}
$expression .= $segment;
} else {
$expression .= '?';
$placeholders[] = $compiler->compileSegment($segment, array_merge($options, array('varEscape' => false)));
}
}
}
return $this->_parseMathExpression($compiler, $expression, $placeholders);
}