TrackManiaControl/libs/FML/Controls/Frame.php

100 lines
2.2 KiB
PHP
Raw Normal View History

<?php
namespace FML\Controls;
2014-01-19 19:30:21 +01:00
use FML\Elements\Format;
2014-05-14 23:24:00 +02:00
use FML\Types\Container;
use FML\Types\Renderable;
2014-04-27 14:44:40 +02:00
use FML\Types\ScriptFeatureable;
/**
2014-01-19 19:30:21 +01:00
* Frame Control
2014-01-12 00:51:46 +01:00
* (CMlFrame)
*
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
*/
class Frame extends Control implements Container {
2014-01-21 20:30:40 +01:00
/*
2014-06-21 03:18:21 +02:00
* Protected properties
*/
2014-06-21 03:18:21 +02:00
protected $tagName = 'frame';
/** @var Renderable[] $children */
protected $children = array();
2014-05-14 23:24:00 +02:00
/** @var Format $format */
2014-01-19 19:30:21 +01:00
protected $format = null;
/**
2014-05-16 22:44:22 +02:00
* @see \FML\Controls\Control::getManiaScriptClass()
*/
2014-05-16 22:44:22 +02:00
public function getManiaScriptClass() {
return 'CMlFrame';
}
/**
* @see \FML\Types\Container::add()
*/
2014-05-14 23:24:00 +02:00
public function add(Renderable $child) {
2014-01-12 14:47:17 +01:00
if (!in_array($child, $this->children, true)) {
2014-01-12 00:51:46 +01:00
array_push($this->children, $child);
}
return $this;
}
/**
* @see \FML\Types\Container::removeChildren()
*/
public function removeChildren() {
$this->children = array();
return $this;
}
2014-01-19 19:30:21 +01:00
/**
* @see \FML\Types\Container::getFormat()
*/
public function getFormat($createIfEmpty = true) {
if (!$this->format && $createIfEmpty) {
2014-04-13 18:21:40 +02:00
$this->setFormat(new Format());
2014-01-19 19:30:21 +01:00
}
return $this->format;
}
2014-05-16 22:44:22 +02:00
/**
* @see \FML\Types\Container::setFormat()
*/
public function setFormat(Format $format) {
$this->format = $format;
return $this;
}
2014-04-27 14:44:40 +02:00
/**
* @see \FML\Controls\Control::getScriptFeatures()
*/
public function getScriptFeatures() {
$scriptFeatures = $this->scriptFeatures;
foreach ($this->children as $child) {
if ($child instanceof ScriptFeatureable) {
$scriptFeatures = array_merge($scriptFeatures, $child->getScriptFeatures());
}
}
return $scriptFeatures;
}
/**
2014-07-03 22:34:47 +02:00
* @see \FML\Types\Renderable::render()
*/
public function render(\DOMDocument $domDocument) {
2014-01-12 00:51:46 +01:00
$xmlElement = parent::render($domDocument);
2014-01-19 19:30:21 +01:00
if ($this->format) {
$formatXml = $this->format->render($domDocument);
$xmlElement->appendChild($formatXml);
}
foreach ($this->children as $child) {
2014-01-12 00:51:46 +01:00
$childXmlElement = $child->render($domDocument);
$xmlElement->appendChild($childXmlElement);
}
2014-01-12 00:51:46 +01:00
return $xmlElement;
}
}