TrackManiaControl/application/core/Libs/FML/Elements/SimpleScript.php

67 lines
1.4 KiB
PHP
Raw Normal View History

<?php
namespace FML\Elements;
use FML\Types\Renderable;
/**
2014-01-12 00:51:46 +01:00
* Class representing a ManiaLink Script Tag with a simple Script Text
*
* @author steeffeen
2014-04-13 18:21:40 +02:00
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class SimpleScript implements Renderable {
2014-01-21 20:30:40 +01:00
/*
2013-12-31 02:55:19 +01:00
* Protected Properties
*/
protected $tagName = 'script';
protected $text = '';
2014-01-19 19:30:21 +01:00
/**
* Create a new SimpleScript Element
*
* @param string $text (optional) Script Text
* @return \FML\Elements\SimpleScript
*/
public static function create($text = null) {
$simpleScript = new SimpleScript($text);
return $simpleScript;
}
/**
* Construct a new SimpleScript Element
*
* @param string $text (optional) Script Text
*/
public function __construct($text = null) {
if ($text !== null) {
$this->setText($text);
}
}
/**
2013-12-31 02:55:19 +01:00
* Set Script Text
*
2014-01-12 00:51:46 +01:00
* @param string $text The Complete Script Text
* @return \FML\Script\Script
*/
public function setText($text) {
2014-01-19 19:30:21 +01:00
$this->text = (string) $text;
return $this;
}
/**
*
* @see \FML\Types\Renderable::render()
*/
public function render(\DOMDocument $domDocument) {
2014-01-12 00:51:46 +01:00
$xmlElement = $domDocument->createElement($this->tagName);
2014-01-19 19:30:21 +01:00
if ($this->text) {
$scriptComment = $domDocument->createComment($this->text);
$xmlElement->appendChild($scriptComment);
}
2014-01-12 00:51:46 +01:00
return $xmlElement;
}
}