steeffeen/FancyManiaLinks

View on GitHub
FML/ManiaCode/Go_To.php

Summary

Maintainability
A
3 hrs
Test Coverage
A
100%
<?php

namespace FML\ManiaCode;

/**
 * ManiaCode Element for going to a link
 *
 * @author    steeffeen
 * @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder
 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 */
class Go_To implements Element
{

    /**
     * @var string $link Link
     */
    protected $link = null;

    /**
     * Create a new Go_To Element
     *
     * @api
     * @param string $link (optional) Link
     * @return static
     */
    public static function create($link = null)
    {
        return new static($link);
    }

    /**
     * Construct a new Go_To Element
     *
     * @api
     * @param string $link (optional) Link
     */
    public function __construct($link = null)
    {
        if ($link) {
            $this->setLink($link);
        }
    }

    /**
     * Get the link
     *
     * @api
     * @return string
     */
    public function getLink()
    {
        return $this->link;
    }

    /**
     * Set the link
     *
     * @api
     * @param string $link Link
     * @return static
     */
    public function setLink($link)
    {
        $this->link = (string)$link;
        return $this;
    }

    /**
     * @see Element::render()
     */
    public function render(\DOMDocument $domDocument)
    {
        $domElement = $domDocument->createElement("goto");

        $linkElement = $domDocument->createElement("link", $this->link);
        $domElement->appendChild($linkElement);

        return $domElement;
    }

}