|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: olive |
|
5
|
|
|
* Date: 14/05/2017 |
|
6
|
|
|
* Time: 12:04 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace eXpansion\Framework\Core\Model\Gui; |
|
10
|
|
|
|
|
11
|
|
|
use FML\Types\Renderable; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Class ManiaScript |
|
15
|
|
|
* |
|
16
|
|
|
* @TODO add other helper methods to clean escape script stuff. |
|
17
|
|
|
* |
|
18
|
|
|
* @package eXpansion\Framework\Core\Model\Gui; |
|
19
|
|
|
* @author oliver de Cramer <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class ManiaScript implements Renderable |
|
22
|
|
|
{ |
|
23
|
|
|
/** @var string */ |
|
24
|
|
|
protected $filePath; |
|
25
|
|
|
|
|
26
|
|
|
/** @var string */ |
|
27
|
|
|
protected $id; |
|
28
|
|
|
|
|
29
|
|
|
/** @var array */ |
|
30
|
|
|
public $params; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* ManiaScript constructor. |
|
34
|
|
|
* |
|
35
|
|
|
* @param string $filePath |
|
36
|
|
|
* @param array $params |
|
37
|
|
|
*/ |
|
38
|
|
|
public function __construct($filePath, $params) |
|
39
|
|
|
{ |
|
40
|
|
|
$this->filePath = $filePath; |
|
41
|
|
|
$this->id = spl_object_hash($this); |
|
42
|
|
|
$this->params = $params; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Get unique variable name. |
|
47
|
|
|
* |
|
48
|
|
|
* @param string $name |
|
49
|
|
|
* |
|
50
|
|
|
* @return string |
|
51
|
|
|
*/ |
|
52
|
|
|
public function getVarN($name) |
|
53
|
|
|
{ |
|
54
|
|
|
return "exp_".$this->id."_$name"; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Generate script content |
|
59
|
|
|
* |
|
60
|
|
|
* @return string |
|
61
|
|
|
*/ |
|
62
|
|
|
public function __toString() |
|
63
|
|
|
{ |
|
64
|
|
|
ob_start(); |
|
65
|
|
|
echo "\n"; |
|
66
|
|
|
echo "/**************************************************\n"; |
|
67
|
|
|
echo " * eXpansion : 2.*.*\n"; |
|
68
|
|
|
echo "**************************************************/\n"; |
|
69
|
|
|
echo "\n"; |
|
70
|
|
|
|
|
71
|
|
|
/** @noinspection PhpIncludeInspection */ |
|
72
|
|
|
include $this->filePath; |
|
73
|
|
|
|
|
74
|
|
|
$script = ob_get_contents(); |
|
75
|
|
|
ob_end_clean(); |
|
76
|
|
|
|
|
77
|
|
|
return $script; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Render the XML element |
|
82
|
|
|
* |
|
83
|
|
|
* @param \DOMDocument $domDocument DOMDocument for which the XML element should be rendered |
|
84
|
|
|
* |
|
85
|
|
|
* @return \DOMElement |
|
86
|
|
|
*/ |
|
87
|
|
|
public function render(\DOMDocument $domDocument) |
|
88
|
|
|
{ |
|
89
|
|
|
$scriptXml = $domDocument->createElement("script"); |
|
90
|
|
|
$scriptText = $this->__toString(); |
|
91
|
|
|
|
|
92
|
|
|
$scriptComment = $domDocument->createComment($scriptText); |
|
93
|
|
|
$scriptXml->appendChild($scriptComment); |
|
94
|
|
|
|
|
95
|
|
|
return $scriptXml; |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|