private function parseBlock(&$content, $sort = false)
{
$regex = $this->getRegex('block');
$result = [];
if (preg_match_all($regex, $content, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE)) {
$right = $keys = [];
foreach ($matches as $match) {
if (empty($match['name'][0])) {
if (count($right) > 0) {
$tag = array_pop($right);
$start = $tag['offset'] + strlen($tag['tag']);
$length = $match[0][1] - $start;
$result[$tag['name']] = ['begin' => $tag['tag'], 'content' => substr($content, $start, $length), 'end' => $match[0][0], 'parent' => count($right) ? end($right)['name'] : ''];
$keys[$tag['name']] = $match[0][1];
}
} else {
// 标签头压入栈
$right[] = ['name' => $match[2][0], 'offset' => $match[0][1], 'tag' => $match[0][0]];
}
}
unset($right, $matches);
if ($sort) {
// 按block标签结束符在模板中的位置排序
array_multisort($keys, $result);
}
}
return $result;
}