getAttributes() 공개 메소드

public getAttributes ( )
예제 #1
0
파일: Builder.php 프로젝트: tarcisio/svg
 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;
 }
예제 #2
0
파일: Circle.php 프로젝트: tarcisio/svg
 public function getAttributes()
 {
     $attributes = parent::getAttributes();
     $attributes['r'] = $this->r;
     $attributes['cx'] = $this->cx;
     $attributes['cy'] = $this->cy;
     return $attributes;
 }
예제 #3
0
파일: Line.php 프로젝트: tarcisio/svg
 public function getAttributes()
 {
     $attributes = parent::getAttributes();
     $attributes['x1'] = $this->x1;
     $attributes['y1'] = $this->y1;
     $attributes['x2'] = $this->x2;
     $attributes['y2'] = $this->y2;
     return $attributes;
 }
예제 #4
0
 /**
  * 開始タグまたは空要素タグの共通部分を書式化します.
  * @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;
 }
예제 #5
0
 /**
  * @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);
 }
예제 #6
0
 /** 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;
 }
예제 #7
0
 /** 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.');
 }
예제 #8
0
 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);
 }
예제 #9
0
 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;
 }
예제 #10
0
 /**
  * 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}>";
 }
예제 #11
0
 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";
 }