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


PHP Element::getChildren方法代码示例

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


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

示例1: render

 private function render(\DOMDocument $doc, Element $element, $parent = null)
 {
     if ($element instanceof \tarcisio\svg\SVG) {
         $svgs = $doc->getElementsByTagName('svg');
         $svg = $svgs->item(0);
         $svg->setAttribute('width', $element->width);
         $svg->setAttribute('height', $element->height);
         $svg->setAttribute('viewBox', "0 0 {$element->width} {$element->height}");
         $gs = $doc->getElementsByTagName('g');
         $g = $gs->item(0);
         foreach ($element->getChildren() as $ch) {
             $this->render($doc, $ch, $g);
         }
         return $doc;
     }
     if (!is_null($element->getTitle())) {
         $element->appendChild(new Title('', $element->getTitle()));
     }
     $e = $doc->createElement($element->getElementName());
     $parent->appendChild($e);
     foreach ($element->getAttributes() as $k => $v) {
         if (!is_null($v)) {
             $e->setAttribute($k, $v);
         }
     }
     if (!is_null($element->getValue())) {
         $e->nodeValue = $element->getValue();
     }
     foreach ($element->getChildren() as $ch) {
         $this->render($doc, $ch, $e);
     }
     return $doc;
 }
开发者ID:tarcisio,项目名称:svg,代码行数:33,代码来源:Builder.php

示例2: testAppendMultipleNodes

 /** Tests for {@link Element::append}. */
 public function testAppendMultipleNodes()
 {
     $e = new Element('html');
     $e->append(new Element('head'), new Element('body'));
     $this->assertSame(2, count($e->getChildren()), 'Appended elements missing from children.');
     $e = new Element('div');
     $e->append('Some', 'text');
     $this->assertSame(2, count($e->getChildren()), 'Appended texts missing from children.');
     $this->assertTrue($e->getChildren()[0] instanceof TextNode, 'First text not appended as TextNode child.');
     $this->assertTrue($e->getChildren()[1] instanceof TextNode, 'Second text not appended as TextNode child.');
     $e = new Element('li');
     $e->append('Visit', new Element('a'), 'now');
     $this->assertSame(3, count($e->getChildren()), 'Appended mixed nodes missing from children.');
     $this->assertTrue($e->getChildren()[0] instanceof TextNode, 'First text not appended as TextNode child.');
     $this->assertTrue($e->getChildren()[1] instanceof Element, 'Second appended node has incorrect type.');
     $this->assertTrue($e->getChildren()[2] instanceof TextNode, 'Third text not appended as TextNode child.');
 }
开发者ID:kwebble,项目名称:hadroton,代码行数:18,代码来源:ElementTest.php

示例3: createHtml

 /** Returns a HTML representation of an element and its child nodes.
  * @param   Element                $element            the element to generate as HTML.
  * @return  string                                     the HTML. */
 public function createHtml($element)
 {
     $data = array_reduce($element->getChildren(), function ($carry, $child) {
         return $carry . $child->toHtml();
     }, '');
     $allAttributes = [];
     foreach ($element->getAttributes() as $name => $value) {
         $allAttributes[] = sprintf(static::ATTRIBUTE_TEMPLATE, htmlspecialchars($name, ENT_COMPAT), htmlspecialchars($value, ENT_COMPAT));
     }
     if (0 === count($allAttributes)) {
         $attributes = '';
     } else {
         $attributes = ' ' . implode(' ', $allAttributes);
     }
     if (in_array($element->getName(), static::VOID_ELEMENTS)) {
         $html = sprintf(static::VOID_ELEMENT_TEMPLATE, $element->getName(), $attributes);
     } else {
         $html = sprintf(static::ELEMENT_TEMPLATE, $element->getName(), $attributes, $data);
     }
     return $html;
 }
开发者ID:kwebble,项目名称:hadroton,代码行数:24,代码来源:HtmlGenerator.php

示例4: writeElement

 protected function writeElement(Element $element, $level)
 {
     $children = $element->getChildren();
     $childCount = count($children);
     $hasChildren = $childCount > 0;
     $newLine = $this->_pretty ? $this->_newLine : '';
     $indent = $this->_pretty ? str_repeat($this->_tabString, $level) : '';
     $str = $indent;
     $str .= $this->writeOpenTag($element->getTag(), $element->getAttributes(), $hasChildren);
     $writeCloseIndent = false;
     if ($hasChildren) {
         if ($childCount === 1 && $children[0] instanceof Text && mb_strlen($children[0]->getText(), 'utf-8') < $this->_textWrap) {
             $str .= $children[0]->getText();
         } else {
             $str .= $newLine;
             for ($i = 0; $i < $childCount; $i++) {
                 $child = $children[$i];
                 $str .= $this->writeLeaf($child, $level + 1);
                 $str .= $newLine;
             }
             $writeCloseIndent = true;
         }
     }
     if ($hasChildren || !empty($this->_selfClosingTags) && !in_array($element->getTag(), $this->_selfClosingTags)) {
         if ($hasChildren && $writeCloseIndent) {
             $str .= $indent;
         }
         $str .= $this->writeCloseTag($element->getTag());
     }
     return $str;
 }
开发者ID:talesoft,项目名称:tale-framework,代码行数:31,代码来源:Writer.php


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