TrackManiaControl/libs/FML/Stylesheet/Stylesheet.php

101 lines
2.2 KiB
PHP
Raw Normal View History

2014-01-19 19:30:21 +01:00
<?php
namespace FML\Stylesheet;
/**
2014-06-21 03:18:21 +02:00
* Class representing a ManiaLink Stylesheet
2014-01-19 19:30:21 +01:00
*
2014-05-20 15:44:45 +02:00
* @author steeffeen <mail@steeffeen.com>
2014-04-13 18:21:40 +02:00
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
2014-05-14 23:24:00 +02:00
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
2014-01-19 19:30:21 +01:00
*/
class Stylesheet {
2014-01-21 20:30:40 +01:00
/*
2014-06-21 03:18:21 +02:00
* Protected properties
2014-01-19 19:30:21 +01:00
*/
protected $tagName = 'stylesheet';
2014-06-21 03:18:21 +02:00
/** @var Style3d[] $styles3d */
2014-01-19 19:30:21 +01:00
protected $styles3d = array();
2014-05-14 23:24:00 +02:00
/** @var Mood $mood */
2014-01-19 19:30:21 +01:00
protected $mood = null;
/**
2014-06-21 03:18:21 +02:00
* Create a new Stylesheet object
2014-01-19 19:30:21 +01:00
*
2014-07-03 22:34:47 +02:00
* @return static
2014-01-19 19:30:21 +01:00
*/
public static function create() {
2014-06-21 03:18:21 +02:00
return new static();
2014-01-19 19:30:21 +01:00
}
/**
* Add a new Style3d
*
2014-06-21 03:18:21 +02:00
* @param Style3d $style3d Style3d object
2014-07-03 22:34:47 +02:00
* @return static
2014-01-19 19:30:21 +01:00
*/
public function addStyle3d(Style3d $style3d) {
if (!in_array($style3d, $this->styles3d, true)) {
array_push($this->styles3d, $style3d);
}
return $this;
}
/**
2014-06-21 03:18:21 +02:00
* Remove all Style3ds
2014-01-19 19:30:21 +01:00
*
2014-07-03 22:34:47 +02:00
* @return static
2014-01-19 19:30:21 +01:00
*/
public function removeStyles() {
$this->styles3d = array();
return $this;
}
/**
2014-06-21 03:18:21 +02:00
* Set the Mood object of the Stylesheet
2014-01-19 19:30:21 +01:00
*
2014-06-21 03:18:21 +02:00
* @param Mood $mood Mood object
2014-07-03 22:34:47 +02:00
* @return static
2014-01-19 19:30:21 +01:00
*/
public function setMood(Mood $mood) {
$this->mood = $mood;
return $this;
}
/**
2014-06-21 03:18:21 +02:00
* Get the Mood object
2014-01-19 19:30:21 +01:00
*
2014-06-21 03:18:21 +02:00
* @param bool $createIfEmpty (optional) Whether the Mood object should be created if it's not set
2014-01-19 19:30:21 +01:00
* @return \FML\Stylesheet\Mood
*/
public function getMood($createIfEmpty = true) {
if (!$this->mood && $createIfEmpty) {
2014-04-13 18:21:40 +02:00
$this->setMood(new Mood());
2014-01-19 19:30:21 +01:00
}
return $this->mood;
}
/**
2014-06-21 03:18:21 +02:00
* Render the Stylesheet XML element
2014-01-19 19:30:21 +01:00
*
2014-06-21 03:18:21 +02:00
* @param \DOMDocument $domDocument DOMDocument for which the Stylesheet XML element should be rendered
2014-01-19 19:30:21 +01:00
* @return \DOMElement
*/
public function render(\DOMDocument $domDocument) {
$stylesheetXml = $domDocument->createElement($this->tagName);
if ($this->styles3d) {
$stylesXml = $domDocument->createElement('frame3dstyles');
$stylesheetXml->appendChild($stylesXml);
foreach ($this->styles3d as $style3d) {
$style3dXml = $style3d->render($domDocument);
$stylesXml->appendChild($style3dXml);
}
}
if ($this->mood) {
$moodXml = $this->mood->render($domDocument);
$stylesheetXml->appendChild($moodXml);
}
return $stylesheetXml;
}
}