2013-11-25 00:02:07 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace FML\Elements;
|
|
|
|
|
|
|
|
use FML\Types\Renderable;
|
|
|
|
|
|
|
|
/**
|
2014-06-21 03:18:21 +02:00
|
|
|
* Class representing a ManiaLink script tag with a simple script text
|
2013-11-25 00:02:07 +01:00
|
|
|
*
|
2014-05-20 15:44:45 +02:00
|
|
|
* @author steeffeen <mail@steeffeen.com>
|
2017-03-25 18:40:15 +01:00
|
|
|
* @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder
|
2014-05-18 19:45:50 +02:00
|
|
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
2013-11-25 00:02:07 +01:00
|
|
|
*/
|
2017-03-25 18:40:15 +01:00
|
|
|
class SimpleScript implements Renderable
|
|
|
|
{
|
2013-11-25 00:02:07 +01:00
|
|
|
|
2017-03-25 18:40:15 +01:00
|
|
|
/**
|
|
|
|
* @var string $text Script text
|
|
|
|
*/
|
|
|
|
protected $text = null;
|
2014-01-19 19:30:21 +01:00
|
|
|
|
2017-03-25 18:40:15 +01:00
|
|
|
/**
|
|
|
|
* Create a new SimpleScript
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
* @param string $text (optional) Script text
|
|
|
|
* @return static
|
|
|
|
*/
|
|
|
|
public static function create($text = null)
|
|
|
|
{
|
|
|
|
return new static($text);
|
|
|
|
}
|
2014-01-19 19:30:21 +01:00
|
|
|
|
2017-03-25 18:40:15 +01:00
|
|
|
/**
|
|
|
|
* Construct a new SimpleScript
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
* @param string $text (optional) Script text
|
|
|
|
*/
|
|
|
|
public function __construct($text = null)
|
|
|
|
{
|
|
|
|
if ($text) {
|
|
|
|
$this->setText($text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the script text
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getText()
|
|
|
|
{
|
|
|
|
return $this->text;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the script text
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
* @param string $text Complete script text
|
|
|
|
* @return static
|
|
|
|
*/
|
|
|
|
public function setText($text)
|
|
|
|
{
|
|
|
|
$this->text = (string)$text;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see Renderable::render()
|
|
|
|
*/
|
|
|
|
public function render(\DOMDocument $domDocument)
|
|
|
|
{
|
|
|
|
$domElement = $domDocument->createElement("script");
|
|
|
|
if ($this->text) {
|
|
|
|
$scriptComment = $domDocument->createComment($this->text);
|
|
|
|
$domElement->appendChild($scriptComment);
|
|
|
|
}
|
|
|
|
return $domElement;
|
|
|
|
}
|
2013-11-25 00:02:07 +01:00
|
|
|
|
|
|
|
}
|