Location: PHPKode > scripts > Redstart Templating > Redstart-Templating-master/Redstart/Templating/Core/Html/Tag.php
<?php

namespace Redstart\Templating\Core\Html;

/**
 * Html Tag Plugin
 *
 * @package Redstart    
 * @subpackage Redstart_Templating_Core_Html
 *
 * @author Hyyan Abo Fakher
 * @since Redstart 1.0
 * @version 1.0
 */
class Tag {

    private $attrs;
    protected $tagName;
    protected $isHtml5;
    protected $unaryTagArray = array('input', 'img', 'hr', 'br', 'meta', 'link');
    protected $content;
    protected $attrsManager;

    /**
     * Constrcut New Tag 
     * 
     * @param string $name tag name
     * @param array $attrs array of attrsbutes
     * @param boolean $html5 true to enbale html5 tag mode
     */
    public function __construct($name = '', array $attrs = array(), $html5 = false) {
        $this->setTagName($name);
        $this->setHtml5Mode($html5);
        $this->setAttributes($attrs);
        $this->attrsManager = new Attributes();
    }

    /**
     * Set tag attributes
     * @param array $attrs
     * @return \Redstart\Templating\Core\Html\Tag
     */
    public function setAttributes(array $attrs) {
        $this->attrs = $attrs;
        return $this;
    }

    /**
     * Get tag attributes
     * @return array
     */
    public function getAttributes() {
        return $this->attrs;
    }

    /**
     * Set tag name
     * @param string $name tag name
     * @return \Redstart\Templating\Core\Html\Tag
     */
    public function setTagName($type) {
        $this->tagName = strtolower($type);
        return $this;
    }

    /**
     * Get tag name
     * @return string
     */
    public function getTagName() {
        return $this->tagName;
    }

    /**
     * Set Html5 Mode 
     * @param boolean $boolean true to enable htl5 mode or false to disable
     * @return \Redstart\Templating\Core\Html\Tag
     */
    public function setHtml5Mode($boolean) {
        $this->isHtml5 = (boolean) $boolean;
        return $this;
    }

    /**
     * Check if the html5 mode is enabled
     * @return boolean
     */
    public function isHtml5Mode() {
        return $this->isHtml5;
    }

    /**
     * Update Tag Content
     * 
     * <b>Note : </b>
     * The content will not be escaped
     * 
     * @param string $content
     * @return \Redstart\Templating\Core\Html\Tag
     */
    public function update($content) {
        $this->content.=$content;
        return $this;
    }

    /**
     * Set tag content
     * 
     * <b>Note : </b>
     * The content will not be escaped
     * 
     * @param string $content
     * @return \Redstart\Templating\Core\Html\Tag
     */
    public function setContent($content) {
        $this->content = $content;
        return $this;
    }

    /**
     * Build tag
     * @return string
     */
    public function getString() {
        $build = trim(
                '<'
                . $this->getTagName()
                . $this->attrsManager->clear()->set(
                        $this->getAttributes()
                )->getString()
        );
        if (!in_array($this->getTagName(), $this->unaryTagArray)) {
            $build.= '>' . $this->content . '</' . $this->getTagName() . '>';
        } else {
            if ($this->isHtml5Mode()) {
                $build.= '>';
            } else {
                $build.= ' />';
            }
        }
        return $build;
    }

    /**
     * Build tag
     * @return string
     */
    public function __toString() {
        return $this->getString();
    }

}

Return current item: Redstart Templating