当前位置: 首页>>代码示例>>PHP>>正文


PHP Parser::braceSubstitution方法代码示例

本文整理汇总了PHP中Parser::braceSubstitution方法的典型用法代码示例。如果您正苦于以下问题:PHP Parser::braceSubstitution方法的具体用法?PHP Parser::braceSubstitution怎么用?PHP Parser::braceSubstitution使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Parser的用法示例。


在下文中一共展示了Parser::braceSubstitution方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: expand

 /**
  * @throws MWException
  * @param string|PPNode $root
  * @param int $flags
  * @return string
  */
 public function expand($root, $flags = 0)
 {
     static $expansionDepth = 0;
     if (is_string($root)) {
         return $root;
     }
     if (++$this->parser->mPPNodeCount > $this->parser->mOptions->getMaxPPNodeCount()) {
         $this->parser->limitationWarn('node-count-exceeded', $this->parser->mPPNodeCount, $this->parser->mOptions->getMaxPPNodeCount());
         return '<span class="error">Node-count limit exceeded</span>';
     }
     if ($expansionDepth > $this->parser->mOptions->getMaxPPExpandDepth()) {
         $this->parser->limitationWarn('expansion-depth-exceeded', $expansionDepth, $this->parser->mOptions->getMaxPPExpandDepth());
         return '<span class="error">Expansion depth limit exceeded</span>';
     }
     ++$expansionDepth;
     if ($expansionDepth > $this->parser->mHighestExpansionDepth) {
         $this->parser->mHighestExpansionDepth = $expansionDepth;
     }
     $outStack = array('', '');
     $iteratorStack = array(false, $root);
     $indexStack = array(0, 0);
     while (count($iteratorStack) > 1) {
         $level = count($outStack) - 1;
         $iteratorNode =& $iteratorStack[$level];
         $out =& $outStack[$level];
         $index =& $indexStack[$level];
         if (is_array($iteratorNode)) {
             if ($index >= count($iteratorNode)) {
                 // All done with this iterator
                 $iteratorStack[$level] = false;
                 $contextNode = false;
             } else {
                 $contextNode = $iteratorNode[$index];
                 $index++;
             }
         } elseif ($iteratorNode instanceof PPNode_Hash_Array) {
             if ($index >= $iteratorNode->getLength()) {
                 // All done with this iterator
                 $iteratorStack[$level] = false;
                 $contextNode = false;
             } else {
                 $contextNode = $iteratorNode->item($index);
                 $index++;
             }
         } else {
             // Copy to $contextNode and then delete from iterator stack,
             // because this is not an iterator but we do have to execute it once
             $contextNode = $iteratorStack[$level];
             $iteratorStack[$level] = false;
         }
         $newIterator = false;
         if ($contextNode === false) {
             // nothing to do
         } elseif (is_string($contextNode)) {
             $out .= $contextNode;
         } elseif (is_array($contextNode) || $contextNode instanceof PPNode_Hash_Array) {
             $newIterator = $contextNode;
         } elseif ($contextNode instanceof PPNode_Hash_Attr) {
             // No output
         } elseif ($contextNode instanceof PPNode_Hash_Text) {
             $out .= $contextNode->value;
         } elseif ($contextNode instanceof PPNode_Hash_Tree) {
             if ($contextNode->name == 'template') {
                 # Double-brace expansion
                 $bits = $contextNode->splitTemplate();
                 if ($flags & PPFrame::NO_TEMPLATES) {
                     $newIterator = $this->virtualBracketedImplode('{{', '|', '}}', $bits['title'], $bits['parts']);
                 } else {
                     $ret = $this->parser->braceSubstitution($bits, $this);
                     if (isset($ret['object'])) {
                         $newIterator = $ret['object'];
                     } else {
                         $out .= $ret['text'];
                     }
                 }
             } elseif ($contextNode->name == 'tplarg') {
                 # Triple-brace expansion
                 $bits = $contextNode->splitTemplate();
                 if ($flags & PPFrame::NO_ARGS) {
                     $newIterator = $this->virtualBracketedImplode('{{{', '|', '}}}', $bits['title'], $bits['parts']);
                 } else {
                     $ret = $this->parser->argSubstitution($bits, $this);
                     if (isset($ret['object'])) {
                         $newIterator = $ret['object'];
                     } else {
                         $out .= $ret['text'];
                     }
                 }
             } elseif ($contextNode->name == 'comment') {
                 # HTML-style comment
                 # Remove it in HTML, pre+remove and STRIP_COMMENTS modes
                 # Not in RECOVER_COMMENTS mode (msgnw) though.
                 if (($this->parser->ot['html'] || $this->parser->ot['pre'] && $this->parser->mOptions->getRemoveComments() || $flags & PPFrame::STRIP_COMMENTS) && !($flags & PPFrame::RECOVER_COMMENTS)) {
                     $out .= '';
//.........这里部分代码省略.........
开发者ID:mb720,项目名称:mediawiki,代码行数:101,代码来源:Preprocessor_Hash.php

示例2: expand

 /**
  * @throws MWException
  * @param string|PPNode_DOM|DOMDocument $root
  * @param int $flags
  * @return string
  */
 public function expand($root, $flags = 0)
 {
     static $expansionDepth = 0;
     if (is_string($root)) {
         return $root;
     }
     if (++$this->parser->mPPNodeCount > $this->parser->mOptions->getMaxPPNodeCount()) {
         $this->parser->limitationWarn('node-count-exceeded', $this->parser->mPPNodeCount, $this->parser->mOptions->getMaxPPNodeCount());
         return '<span class="error">Node-count limit exceeded</span>';
     }
     if ($expansionDepth > $this->parser->mOptions->getMaxPPExpandDepth()) {
         $this->parser->limitationWarn('expansion-depth-exceeded', $expansionDepth, $this->parser->mOptions->getMaxPPExpandDepth());
         return '<span class="error">Expansion depth limit exceeded</span>';
     }
     ++$expansionDepth;
     if ($expansionDepth > $this->parser->mHighestExpansionDepth) {
         $this->parser->mHighestExpansionDepth = $expansionDepth;
     }
     if ($root instanceof PPNode_DOM) {
         $root = $root->node;
     }
     if ($root instanceof DOMDocument) {
         $root = $root->documentElement;
     }
     $outStack = array('', '');
     $iteratorStack = array(false, $root);
     $indexStack = array(0, 0);
     while (count($iteratorStack) > 1) {
         $level = count($outStack) - 1;
         $iteratorNode =& $iteratorStack[$level];
         $out =& $outStack[$level];
         $index =& $indexStack[$level];
         if ($iteratorNode instanceof PPNode_DOM) {
             $iteratorNode = $iteratorNode->node;
         }
         if (is_array($iteratorNode)) {
             if ($index >= count($iteratorNode)) {
                 // All done with this iterator
                 $iteratorStack[$level] = false;
                 $contextNode = false;
             } else {
                 $contextNode = $iteratorNode[$index];
                 $index++;
             }
         } elseif ($iteratorNode instanceof DOMNodeList) {
             if ($index >= $iteratorNode->length) {
                 // All done with this iterator
                 $iteratorStack[$level] = false;
                 $contextNode = false;
             } else {
                 $contextNode = $iteratorNode->item($index);
                 $index++;
             }
         } else {
             // Copy to $contextNode and then delete from iterator stack,
             // because this is not an iterator but we do have to execute it once
             $contextNode = $iteratorStack[$level];
             $iteratorStack[$level] = false;
         }
         if ($contextNode instanceof PPNode_DOM) {
             $contextNode = $contextNode->node;
         }
         $newIterator = false;
         if ($contextNode === false) {
             // nothing to do
         } elseif (is_string($contextNode)) {
             $out .= $contextNode;
         } elseif (is_array($contextNode) || $contextNode instanceof DOMNodeList) {
             $newIterator = $contextNode;
         } elseif ($contextNode instanceof DOMNode) {
             if ($contextNode->nodeType == XML_TEXT_NODE) {
                 $out .= $contextNode->nodeValue;
             } elseif ($contextNode->nodeName == 'template') {
                 # Double-brace expansion
                 $xpath = new DOMXPath($contextNode->ownerDocument);
                 $titles = $xpath->query('title', $contextNode);
                 $title = $titles->item(0);
                 $parts = $xpath->query('part', $contextNode);
                 if ($flags & PPFrame::NO_TEMPLATES) {
                     $newIterator = $this->virtualBracketedImplode('{{', '|', '}}', $title, $parts);
                 } else {
                     $lineStart = $contextNode->getAttribute('lineStart');
                     $params = array('title' => new PPNode_DOM($title), 'parts' => new PPNode_DOM($parts), 'lineStart' => $lineStart);
                     $ret = $this->parser->braceSubstitution($params, $this);
                     if (isset($ret['object'])) {
                         $newIterator = $ret['object'];
                     } else {
                         $out .= $ret['text'];
                     }
                 }
             } elseif ($contextNode->nodeName == 'tplarg') {
                 # Triple-brace expansion
                 $xpath = new DOMXPath($contextNode->ownerDocument);
                 $titles = $xpath->query('title', $contextNode);
//.........这里部分代码省略.........
开发者ID:mb720,项目名称:mediawiki,代码行数:101,代码来源:Preprocessor_DOM.php

示例3: expand


//.........这里部分代码省略.........
         } elseif (is_array($contextNode) || $contextNode instanceof DOMNodeList) {
             $newIterator = $contextNode;
         } elseif ($contextNode instanceof DOMNode) {
             if ($contextNode->nodeType == XML_TEXT_NODE) {
                 # RTE (Rich Text Editor) - begin
                 global $wgRTEParserEnabled;
                 if (!empty($wgRTEParserEnabled)) {
                     if ($RTEext_2) {
                         if (strpos($contextNode->nodeValue, 'table') !== false) {
                             RTE::$edgeCases[] = 'COMPLEX.11';
                         }
                     }
                 }
                 # RTE - end
                 $out .= $contextNode->nodeValue;
             } elseif ($contextNode->nodeName == 'template') {
                 # Double-brace expansion
                 $xpath = new DOMXPath($contextNode->ownerDocument);
                 $titles = $xpath->query('title', $contextNode);
                 $title = $titles->item(0);
                 $parts = $xpath->query('part', $contextNode);
                 # RTE (Rich Text Editor) - begin
                 # @author: Inez Korczyński
                 global $wgRTEParserEnabled;
                 if (!empty($wgRTEParserEnabled)) {
                     $dataIdx = RTEData::put('placeholder', array('type' => 'double-brackets', 'wikitextIdx' => $contextNode->getAttribute('_rte_wikitextidx'), 'lineStart' => $contextNode->getAttribute('lineStart'), 'title' => $title->textContent));
                     $out .= RTEMarker::generate(RTEMarker::PLACEHOLDER, $dataIdx);
                 } else {
                     if ($flags & PPFrame::NO_TEMPLATES) {
                         $newIterator = $this->virtualBracketedImplode('{{', '|', '}}', $title, $parts);
                     } else {
                         $lineStart = $contextNode->getAttribute('lineStart');
                         $params = array('title' => new PPNode_DOM($title), 'parts' => new PPNode_DOM($parts), 'lineStart' => $lineStart);
                         $ret = $this->parser->braceSubstitution($params, $this);
                         if (isset($ret['object'])) {
                             $newIterator = $ret['object'];
                         } else {
                             $out .= $ret['text'];
                         }
                     }
                 }
                 # RTE - end
             } elseif ($contextNode->nodeName == 'tplarg') {
                 # Triple-brace expansion
                 $xpath = new DOMXPath($contextNode->ownerDocument);
                 $titles = $xpath->query('title', $contextNode);
                 $title = $titles->item(0);
                 $parts = $xpath->query('part', $contextNode);
                 # RTE (Rich Text Editor) - begin
                 # @author: Wladyslaw Bodzek
                 global $wgRTEParserEnabled;
                 if (!empty($wgRTEParserEnabled)) {
                     //var_dump($contextNode->getAttribute('_rte_wikitextidx'));
                     $dataIdx = RTEData::put('placeholder', array('type' => 'tplarg', 'wikitextIdx' => $contextNode->getAttribute('_rte_wikitextidx'), 'lineStart' => $contextNode->getAttribute('lineStart'), 'title' => $title->textContent));
                     $out .= RTEMarker::generate(RTEMarker::PLACEHOLDER, $dataIdx);
                 } else {
                     if ($flags & PPFrame::NO_ARGS) {
                         $newIterator = $this->virtualBracketedImplode('{{{', '|', '}}}', $title, $parts);
                     } else {
                         $params = array('title' => new PPNode_DOM($title), 'parts' => new PPNode_DOM($parts));
                         $ret = $this->parser->argSubstitution($params, $this);
                         if (isset($ret['object'])) {
                             $newIterator = $ret['object'];
                         } else {
                             $out .= $ret['text'];
                         }
开发者ID:schwarer2006,项目名称:wikia,代码行数:67,代码来源:Preprocessor_DOM.php


注:本文中的Parser::braceSubstitution方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。