TrackManiaControl/libs/FML/Controls/Frame.php

160 lines
3.4 KiB
PHP
Raw Permalink Normal View History

<?php
namespace FML\Controls;
2014-01-19 19:30:21 +01:00
use FML\Elements\Format;
2017-04-02 16:32:57 +02:00
use FML\Stylesheet\Style;
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>
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
*/
2017-03-25 18:40:15 +01:00
class Frame extends Control implements Container
{
/**
* @var Renderable[] $children Children
*/
protected $children = array();
/**
* @var Format $format Format
2017-04-02 16:32:57 +02:00
* @deprecated
2017-03-25 18:40:15 +01:00
*/
protected $format = null;
/**
* @see Container::getChildren()
*/
public function getChildren()
{
return $this->children;
}
/**
2017-04-02 16:32:57 +02:00
* @deprecated Use addChild()
* @see Frame::addChild()
2017-03-25 18:40:15 +01:00
*/
public function add(Renderable $child)
{
return $this->addChild($child);
}
/**
* @see Container::addChild()
*/
public function addChild(Renderable $child)
{
if (!in_array($child, $this->children, true)) {
array_push($this->children, $child);
}
return $this;
}
/**
* @see Container::addChildren()
*/
public function addChildren(array $children)
{
foreach ($children as $child) {
$this->addChild($child);
}
return $this;
}
2017-04-02 16:32:57 +02:00
/**
* @deprecated Use removeAllChildren()
* @see Frame::removeAllChildren()
*/
public function removeChildren()
{
return $this->removeAllChildren();
}
2017-03-25 18:40:15 +01:00
/**
* @see Container::removeAllChildren()
*/
public function removeAllChildren()
{
$this->children = array();
return $this;
}
/**
2017-04-02 16:32:57 +02:00
* @deprecated Use Style
* @see Style
2017-03-25 18:40:15 +01:00
*/
2017-04-02 16:32:57 +02:00
public function getFormat($createIfEmpty = true)
2017-03-25 18:40:15 +01:00
{
2017-04-02 16:32:57 +02:00
if (!$this->format && $createIfEmpty) {
$this->setFormat(new Format());
}
2017-03-25 18:40:15 +01:00
return $this->format;
}
/**
2017-04-02 16:32:57 +02:00
* @deprecated Use Style
* @see Style
2017-03-25 18:40:15 +01:00
*/
public function setFormat(Format $format = null)
{
$this->format = $format;
return $this;
}
/**
* @see Control::getTagName()
*/
public function getTagName()
{
return "frame";
}
/**
* @see Control::getManiaScriptClass()
*/
public function getManiaScriptClass()
{
return "CMlFrame";
}
/**
* @see 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;
}
/**
* @see Renderable::render()
*/
public function render(\DOMDocument $domDocument)
{
$domElement = parent::render($domDocument);
if ($this->format) {
$formatXml = $this->format->render($domDocument);
$domElement->appendChild($formatXml);
}
foreach ($this->children as $child) {
$childXmlElement = $child->render($domDocument);
$domElement->appendChild($childXmlElement);
}
return $domElement;
}
}