Texy\HtmlElement::toString PHP Method

toString() final public method

Renders element's start tag, content and end tag to internal string representation.
final public toString ( Texy $texy ) : string
$texy Texy
return string
    public final function toString(Texy $texy)
    {
        $ct = $this->getContentType();
        $s = $texy->protect($this->startTag(), $ct);
        // empty elements are finished now
        if ($this->isEmpty) {
            return $s;
        }
        // add content
        foreach ($this->children as $child) {
            if (is_object($child)) {
                $s .= $child->toString($texy);
            } else {
                $s .= $child;
            }
        }
        // add end tag
        return $s . $texy->protect($this->endTag(), $ct);
    }

Usage Example

示例#1
0
文件: LinkModule.php 项目: dg/texy
 /**
  * Callback for: [ref].
  * @return Texy\HtmlElement|string|FALSE
  */
 public function patternReference(LineParser $parser, array $matches)
 {
     list(, $mRef) = $matches;
     // [1] => [ref]
     $texy = $this->texy;
     $name = substr($mRef, 1, -1);
     $link = $this->getReference($name);
     if (!$link) {
         return $texy->invokeAroundHandlers('newReference', $parser, [$name]);
     }
     $link->type = $link::BRACKET;
     if ($link->label != '') {
         // NULL or ''
         // prevent circular references
         if (isset(self::$livelock[$link->name])) {
             $content = $link->label;
         } else {
             self::$livelock[$link->name] = TRUE;
             $el = new Texy\HtmlElement();
             $lineParser = new LineParser($texy, $el);
             $lineParser->parse($link->label);
             $content = $el->toString($texy);
             unset(self::$livelock[$link->name]);
         }
     } else {
         $content = $this->textualUrl($link);
         $content = $this->texy->protect($content, $texy::CONTENT_TEXTUAL);
     }
     return $texy->invokeAroundHandlers('linkReference', $parser, [$link, $content]);
 }