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


PHP Element::getAttributes方法代码示例

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


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

 public function getAttributes()
 {
     $attributes = parent::getAttributes();
     $attributes['r'] = $this->r;
     $attributes['cx'] = $this->cx;
     $attributes['cy'] = $this->cy;
     return $attributes;
 }
开发者ID:tarcisio,项目名称:svg,代码行数:8,代码来源:Circle.php

示例3: getAttributes

 public function getAttributes()
 {
     $attributes = parent::getAttributes();
     $attributes['x1'] = $this->x1;
     $attributes['y1'] = $this->y1;
     $attributes['x2'] = $this->x2;
     $attributes['y2'] = $this->y2;
     return $attributes;
 }
开发者ID:tarcisio,项目名称:svg,代码行数:9,代码来源:Line.php

示例4: formatTagPrefix

 /**
  * 開始タグまたは空要素タグの共通部分を書式化します.
  * @param  Element $element 書式化対象の要素
  * @return string           "<elementName ... "
  */
 protected final function formatTagPrefix(Element $element)
 {
     $tag = "<";
     $tag .= $element->getName();
     foreach ($element->getAttributes() as $name => $value) {
         $tag .= " ";
         $tag .= $value === null ? $this->formatBooleanAttribute($name) : $this->formatAttribute($name, $value);
     }
     return $tag;
 }
开发者ID:trashtoy,项目名称:peach2,代码行数:15,代码来源:AbstractRenderer.php

示例5: build

 /**
  * @param Element $element
  * @param \DOMNode $node
  */
 protected function build(Element $element, \DOMNode $node)
 {
     $dom = $this->getEngine();
     if ($element->getValue() instanceof Collection) {
         $newElement = $dom->createElement($element->getName());
         foreach ($element->getValue()->getElements() as $child) {
             $this->build($child, $newElement);
         }
     } else {
         $newElement = $dom->createElement($element->getName(), $element->getValue()->getValue());
     }
     foreach ($element->getAttributes()->getValues() as $attr => $value) {
         $newElement->setAttribute($attr, $value);
     }
     $node->appendChild($newElement);
 }
开发者ID:boyhagemann,项目名称:html,代码行数:20,代码来源:Renderer.php

示例6: 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

示例7: testSetAttributes

 /** Tests for {@link Element::setAttributes}. */
 public function testSetAttributes()
 {
     $e = new Element('img');
     $e->setAttributes(['alt' => 'Blue sky', 'id' => 'photo1']);
     $a = $e->getAttributes();
     $this->assertSame(2, count($a), 'Element has incorrect number of attributes.');
     $this->assertSame('Blue sky', $a['alt'], 'First attribute value incorrect.');
     $this->assertSame('photo1', $a['id'], 'Second attribute value incorrect.');
 }
开发者ID:kwebble,项目名称:hadroton,代码行数:10,代码来源:ElementTest.php

示例8: testInterpolationInsideBraces

 public function testInterpolationInsideBraces()
 {
     $el = new Element('%script(type = "text/javascript" src = "#{url::site(\'files/js/html5.js\')}")', $this->compiler);
     $this->assertEquals(array('type' => array('t' => 'str', 'v' => '"text/javascript"'), 'src' => array('t' => 'str', 'v' => '"#{url::site(\'files/js/html5.js\')}"')), $el->getAttributes());
     $html = trim($this->compiler->parseString('%script(type = "text/javascript" src = "#{url::site(\'files/js/html5.js\')}")'));
     $this->assertEquals('<script type="text/javascript" src="<?php echo url::site(\'files/js/html5.js\'); ?>"></script>', $html);
 }
开发者ID:hamlphp,项目名称:hamlphp,代码行数:7,代码来源:AttributesTest.php

示例9: 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

示例10: open

 /**
  * Html open tag
  *
  * @param Element  $element  Element
  *
  * @return string
  */
 public static function open(Element $element)
 {
     $xhtmlAttributes = self::attributes($element->getAttributes());
     $tag = $element->getTag();
     return $tag == 'input' ? "<input {$xhtmlAttributes} />" : "<{$tag} {$xhtmlAttributes}>";
 }
开发者ID:mrjulio,项目名称:spartan-php,代码行数:13,代码来源:Render.php

示例11: renderHtml

 private function renderHtml(Element $element)
 {
     $output = '';
     if ($this->getIndentationLevel() > 0) {
         $output .= $this->getSpaces() . '<' . $element->getTag();
     } else {
         $output .= '<' . $element->getTag();
     }
     if ($element->useAttsHelper()) {
         $output .= ' <?php atts(array(';
         if (($atts = $element->getAttributes()) != null) {
             if (isset($atts['id'])) {
                 $output .= "'id' => " . $this->_renderArrayValue($atts['id'], '_', 'php') . ', ';
                 unset($atts['id']);
             }
             if (isset($atts['class'])) {
                 $output .= "'class' => " . $this->_renderArrayValue($atts['class'], ' ', 'php') . ', ';
                 unset($atts['class']);
             }
             foreach ($atts as $name => $att) {
                 $output .= "";
                 switch ($att['t']) {
                     case 'str':
                         $interpolation = new Interpolation($att['v'], true);
                         $att_value = $interpolation->render();
                         $output .= "'{$name}' => {$att_value}, ";
                         continue;
                     case 'php':
                         if (is_array($att['v'])) {
                             $output .= "'{$name}' => array(" . join(',', $att['v']) . ')';
                         } else {
                             $output .= "'{$name}' => {$att['v']}, ";
                         }
                         continue;
                     case 'static':
                         $output .= "'{$name}' => '{$name}', ";
                         continue;
                     case 'function':
                         $output .= "{$att['v']}, ";
                         continue;
                 }
             }
         }
         $output = rtrim($output, ', ');
         $output .= ')); ?>';
     } else {
         if (($atts = $element->getAttributes()) !== null) {
             if (isset($atts['id'])) {
                 $output .= ' id="' . $this->_renderArrayValue($atts['id'], '_', 'txt') . '"';
                 unset($atts['id']);
             }
             if (isset($atts['class'])) {
                 $output .= ' class="' . $this->_renderArrayValue($atts['class'], ' ', 'txt') . '"';
                 unset($atts['class']);
             }
             foreach ($atts as $name => $att) {
                 switch ($att['t']) {
                     case 'str':
                         $output .= " {$name}={$att['v']}";
                         continue;
                     case 'php':
                         $output .= " {$name}=<?php {$att['v']}; ?>";
                         continue;
                     case 'static':
                         $output .= " {$name}=\"{$name}\"";
                         continue;
                 }
             }
         }
     }
     $interpolation = new Interpolation($output);
     $output = $interpolation->render();
     if ($this->_el->isSelfClosing()) {
         $output .= ' />';
     } else {
         // render inline content
         $content = $this->renderTagContent($element->getInlineContent());
         $output .= '>' . $content . '</' . $element->getTag() . '>';
     }
     return $output . "\n";
 }
开发者ID:hamlphp,项目名称:hamlphp,代码行数:81,代码来源:ElementNode.php


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