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>
|
2017-03-25 18:40:15 +01:00
|
|
|
* @copyright FancyManiaLinks Copyright © 2017 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
|
|
|
*/
|
2017-03-25 18:40:15 +01:00
|
|
|
class Stylesheet
|
|
|
|
{
|
2014-01-19 19:30:21 +01:00
|
|
|
|
2017-04-02 16:32:57 +02:00
|
|
|
/**
|
|
|
|
* @var Style[] $styles Styles
|
|
|
|
*/
|
|
|
|
protected $styles = array();
|
|
|
|
|
2017-03-25 18:40:15 +01:00
|
|
|
/**
|
|
|
|
* @var Style3d[] $styles3d 3d Styles
|
|
|
|
*/
|
|
|
|
protected $styles3d = array();
|
2014-01-19 19:30:21 +01:00
|
|
|
|
2017-03-25 18:40:15 +01:00
|
|
|
/**
|
|
|
|
* @var Mood $mood Mood
|
|
|
|
*/
|
|
|
|
protected $mood = null;
|
2014-01-19 19:30:21 +01:00
|
|
|
|
2017-03-25 18:40:15 +01:00
|
|
|
/**
|
|
|
|
* Create a new Stylesheet
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
* @return static
|
|
|
|
*/
|
|
|
|
public static function create()
|
|
|
|
{
|
|
|
|
return new static();
|
|
|
|
}
|
2014-01-19 19:30:21 +01:00
|
|
|
|
2017-04-02 16:32:57 +02:00
|
|
|
/**
|
|
|
|
* Get the Styles
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
* @return Style[]
|
|
|
|
*/
|
|
|
|
public function getStyles()
|
|
|
|
{
|
|
|
|
return $this->styles;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a new Style
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
* @param Style $style The Style to be added
|
|
|
|
* @return static
|
|
|
|
*/
|
|
|
|
public function addStyle(Style $style)
|
|
|
|
{
|
|
|
|
if (!in_array($style, $this->styles, true)) {
|
|
|
|
array_push($this->styles, $style);
|
|
|
|
}
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove all Styles
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
* @return static
|
|
|
|
*/
|
|
|
|
public function removeAllStyles()
|
|
|
|
{
|
|
|
|
$this->styles = array();
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2017-03-25 18:40:15 +01:00
|
|
|
/**
|
|
|
|
* Get the Styles3d
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
* @return Style3d[]
|
|
|
|
*/
|
|
|
|
public function getStyles3d()
|
|
|
|
{
|
|
|
|
return $this->styles3d;
|
|
|
|
}
|
2014-01-19 19:30:21 +01:00
|
|
|
|
2017-03-25 18:40:15 +01:00
|
|
|
/**
|
|
|
|
* Add a new Style3d
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
* @param Style3d $style3d The Style3d to be added
|
|
|
|
* @return static
|
|
|
|
*/
|
|
|
|
public function addStyle3d(Style3d $style3d)
|
|
|
|
{
|
|
|
|
if (!in_array($style3d, $this->styles3d, true)) {
|
|
|
|
array_push($this->styles3d, $style3d);
|
|
|
|
}
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove all Style3ds
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
* @return static
|
|
|
|
*/
|
|
|
|
public function removeAllStyles3d()
|
|
|
|
{
|
|
|
|
$this->styles3d = array();
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2017-04-02 16:32:57 +02:00
|
|
|
/**
|
|
|
|
* Remove all Style3ds
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
* @return static
|
|
|
|
* @deprecated Use removeAllStyles3d()
|
|
|
|
* @see Stylesheet::removeAllStyles3d()
|
|
|
|
*/
|
|
|
|
public function removeStyles()
|
|
|
|
{
|
|
|
|
return $this->removeAllStyles()
|
|
|
|
->removeAllStyles3d();
|
|
|
|
}
|
|
|
|
|
2017-03-25 18:40:15 +01:00
|
|
|
/**
|
|
|
|
* Get the Mood
|
|
|
|
*
|
|
|
|
* @api
|
2017-04-02 16:32:57 +02:00
|
|
|
* @param bool $createIfEmpty (optional) If the Mood should be created if it doesn't exist yet
|
2017-03-25 18:40:15 +01:00
|
|
|
* @return Mood
|
|
|
|
*/
|
2017-04-02 16:32:57 +02:00
|
|
|
public function getMood($createIfEmpty = true)
|
2017-03-25 18:40:15 +01:00
|
|
|
{
|
2017-04-02 16:32:57 +02:00
|
|
|
if (!$this->mood && $createIfEmpty) {
|
|
|
|
$this->createMood();
|
|
|
|
}
|
2017-03-25 18:40:15 +01:00
|
|
|
return $this->mood;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the Mood
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
* @param Mood $mood Mood
|
|
|
|
* @return static
|
|
|
|
*/
|
|
|
|
public function setMood(Mood $mood = null)
|
|
|
|
{
|
|
|
|
$this->mood = $mood;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new Mood if necessary
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
* @return Mood
|
|
|
|
*/
|
|
|
|
public function createMood()
|
|
|
|
{
|
|
|
|
if ($this->mood) {
|
|
|
|
return $this->mood;
|
|
|
|
}
|
|
|
|
$mood = new Mood();
|
|
|
|
$this->setMood($mood);
|
|
|
|
return $this->mood;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render the Stylesheet
|
|
|
|
*
|
|
|
|
* @param \DOMDocument $domDocument DOMDocument for which the Stylesheet should be rendered
|
|
|
|
* @return \DOMElement
|
|
|
|
*/
|
|
|
|
public function render(\DOMDocument $domDocument)
|
|
|
|
{
|
|
|
|
$stylesheetXml = $domDocument->createElement("stylesheet");
|
|
|
|
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;
|
|
|
|
}
|
2014-01-19 19:30:21 +01:00
|
|
|
|
|
|
|
}
|