forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhaserDocGen.php
More file actions
155 lines (134 loc) · 4.62 KB
/
Copy pathPhaserDocGen.php
File metadata and controls
155 lines (134 loc) · 4.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
class PhaserDocGen
{
private $src;
private $ignore = array('.', '..');
private $fileIgnore = array('Intro.js', 'Outro.js', 'Pixi.js', 'Spine.js', 'p2.js');
public $log;
public $files;
public $classes;
public $uniqueTypes;
/**
* Processes the Phaser / Pixi source code
*
* @return PhaserDocGen
*/
public function __construct()
{
$this->src = realpath('../src');
$this->uniqueTypes = [];
$this->classes = [];
}
public function start()
{
$this->files = $this->dirToArray($this->src);
}
public function extend($classKey = '')
{
if ($classKey !== '')
{
// echo "Extending $classKey\n";
$this->classes[$classKey]->extend();
}
else
{
// This will go through each class and add in inherited properties, etc
foreach ($this->classes as $key => $processor)
{
if ($processor !== 'corrupted')
{
// echo "Extended $key\n";
$processor->extend();
}
}
}
}
public function export($path, $classKey = '')
{
if ($classKey !== '')
{
$this->classes[$classKey]->export($path);
}
else
{
// This will go through each class and add in inherited properties, etc
foreach ($this->classes as $key => $processor)
{
if ($processor !== 'corrupted')
{
$processor->export($path);
echo "Exported $key\n";
// echo $processor . "\n";
}
}
}
}
public function get($classKey)
{
if (array_key_exists($classKey, $this->classes))
{
return $this->classes[$classKey];
}
return null;
}
private function dirToArray($dir)
{
set_time_limit(60);
$result = [];
$root = scandir($dir);
$dirs = array_diff($root, $this->ignore);
foreach ($dirs as $key => $value)
{
$path = realpath($dir . DIRECTORY_SEPARATOR . $value);
if (is_dir($path))
{
$result[$value] = $this->dirToArray($path);
}
else
{
if (substr($value, -3) === '.js')
{
if (!in_array($value, $this->fileIgnore))
{
$index = str_replace($this->src, "", $path);
$index = substr($index, 1);
$tempProcessor = new Processor($this, "../src/$index");
if ($tempProcessor->corrupted === false)
{
if ($tempProcessor->class)
{
$classKey = $tempProcessor->class->name;
}
else
{
$classKey = 'wtf' . rand();
}
// $classKey = substr($value, 0, -3);
// $classKey = str_replace(DIRECTORY_SEPARATOR, ".", $index);
$result[$classKey] = $index;
// echo "Class key: $classKey \n";
$this->classes[$classKey] = $tempProcessor;
}
else
{
$this->classes[$index] = 'corrupted';
// echo "CORRUPTED \n";
}
// Dump to log
// echo $index . "\n";
}
else
{
// echo "Ignored: $value \n";
}
}
else
{
// echo "NOT A JS FILE\n";
}
}
}
return $result;
}
}
?>