TrackManiaControl/libs/FML/Script/Features/ScriptFeature.php

74 lines
2.3 KiB
PHP
Raw Permalink Normal View History

2014-04-27 14:44:40 +02:00
<?php
namespace FML\Script\Features;
use FML\Script\Script;
2014-05-16 22:44:22 +02:00
use FML\Types\ScriptFeatureable;
2014-04-27 14:44:40 +02:00
/**
* ManiaLink Script Feature Class
*
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-16 22:44:22 +02:00
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
2014-04-27 14:44:40 +02:00
*/
2017-03-25 18:40:15 +01:00
abstract class ScriptFeature
{
2014-07-03 22:34:47 +02:00
2017-03-25 18:40:15 +01:00
/**
* Collect the Script Features of the given objects
*
* @return ScriptFeature[]
*/
public static function collect()
{
$params = func_get_args();
$scriptFeatures = array();
foreach ($params as $object) {
2017-06-21 19:43:38 +02:00
if ($object instanceof ScriptFeature) {
$scriptFeatures = static::addScriptFeature($scriptFeatures, $object);
} else if ($object instanceof ScriptFeatureable) {
$scriptFeatures = static::addScriptFeature($scriptFeatures, $object->getScriptFeatures());
} else if (is_array($object)) {
foreach ($object as $subObject) {
$scriptFeatures = static::addScriptFeature($scriptFeatures, static::collect($subObject));
}
}
}
return $scriptFeatures;
}
/**
* Add one or more Script Features to an Array of Features if they are not already contained
*
* @param array $scriptFeatures
* @param ScriptFeature||ScriptFeature[] $newScriptFeatures
* @return array
*/
public static function addScriptFeature(array $scriptFeatures, $newScriptFeatures)
{
if (!$newScriptFeatures) {
return $scriptFeatures;
}
if ($newScriptFeatures instanceof ScriptFeature) {
if (!in_array($newScriptFeatures, $scriptFeatures, true)) {
array_push($scriptFeatures, $newScriptFeatures);
}
} else if (is_array($newScriptFeatures)) {
foreach ($newScriptFeatures as $newScriptFeature) {
$scriptFeatures = static::addScriptFeature($scriptFeatures, $newScriptFeature);
2017-03-25 18:40:15 +01:00
}
}
return $scriptFeatures;
}
/**
* Prepare the given Script for rendering by adding the needed Labels, etc.
*
* @param Script $script Script to prepare
* @return static
*/
public abstract function prepare(Script $script);
2014-05-16 22:44:22 +02:00
2014-04-27 14:44:40 +02:00
}