Skip to content

Commit e945def

Browse files
committed
Mass export ability added to docgen.
1 parent d18f523 commit e945def

10 files changed

Lines changed: 175 additions & 22 deletions

File tree

docgen/export.php

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
<?php
2-
$src = "loader/Cache.js";
3-
4-
if (isset($_GET['src']))
5-
{
6-
$src = $_GET['src'];
7-
}
8-
92
require 'src/Block.php';
103
require 'src/ClassDesc.php';
114
require 'src/Constant.php';
@@ -14,10 +7,36 @@
147
require 'src/Property.php';
158
require 'src/ReturnType.php';
169
require 'src/Processor.php';
10+
require 'src/PhaserDocGen.php';
1711

18-
$data = new Processor("../src/$src");
12+
$gen = new PhaserDocGen();
13+
?>
14+
<!doctype html>
15+
<html>
16+
<head>
17+
<meta charset="UTF-8" />
18+
<title>Phaser Documentation Generator</title>
19+
<style type="text/css">
20+
body {
21+
font-family: Arial;
22+
font-size: 14px;
23+
background-color: #fff;
24+
color: #000;
25+
}
1926

20-
header('Content-Type: application/json');
27+
textarea {
28+
width: 100%;
29+
height: 1000px;
30+
}
31+
</style>
32+
</head>
33+
<body>
34+
35+
<pre>
36+
<?php
37+
$gen->start();
38+
?>
39+
</pre>
2140

22-
echo $data->getJSON();
23-
?>
41+
</body>
42+
</html>

docgen/index.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
</head>
2020
<body>
2121

22+
<a href="export.php">Export</a>
23+
2224
<?php
2325
// http://uk1.php.net/manual/en/class.splfileinfo.php
2426

docgen/src/ClassDesc.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
class ClassDesc
33
{
4+
public $processor;
45
public $name; // Phaser.Sprite
56
public $parameters = []; // an array containing the parameters
67
public $help = [];
@@ -9,15 +10,21 @@ class ClassDesc
910
public $hasConstructor = false;
1011
public $isStatic = false;
1112

12-
public function __construct($block)
13+
public function __construct($processor, $block)
1314
{
15+
$this->processor = $processor;
16+
1417
$this->name = $block->getLineContent('@class');
1518

19+
$this->processor->log("vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv");
20+
$this->processor->log("Class: $this->name");
21+
$this->processor->log("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
22+
1623
$params = $block->getLines('@param');
1724

1825
for ($i = 0; $i < count($params); $i++)
1926
{
20-
$this->parameters[] = new Parameter($params[$i]);
27+
$this->parameters[] = new Parameter($this->processor, $params[$i]);
2128
}
2229

2330
if ($block->getTypeBoolean('@extends'))

docgen/src/Constant.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
<?php
22
class Constant
33
{
4+
public $processor;
45
public $name; // TEXTURE_ATLAS_JSON_ARRAY, PHYSICS_PHASER_JSON, etc
56
public $types = []; // an array containing the one single type the const can be
67
public $help = [];
78
public $line; // number, line number in the source file this is found on?
89
9-
public function __construct($block)
10+
public function __construct($processor, $block)
1011
{
12+
$this->processor = $processor;
13+
1114
// Because zero offset + allowing for final line
1215
$this->line = $block->end + 2;
1316

docgen/src/Method.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
class Method
33
{
4+
public $processor;
45
public $line; // number, line number in the source file this is found on?
56
public $name; // bringToTop, kill, etc
67
public $title = [];
@@ -14,8 +15,10 @@ class Method
1415

1516
public $isStatic = false;
1617

17-
public function __construct($block)
18+
public function __construct($processor, $block)
1819
{
20+
$this->processor = $processor;
21+
1922
// Because zero offset + allowing for final line
2023
$this->line = $block->end + 2;
2124

@@ -47,13 +50,17 @@ public function __construct($block)
4750
}
4851
}
4952

53+
$this->processor->log("vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv");
54+
$this->processor->log("Method: $name");
55+
$this->processor->log("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
56+
5057
$this->name = $name;
5158

5259
$params = $block->getLines('@param');
5360

5461
for ($i = 0; $i < count($params); $i++)
5562
{
56-
$this->parameters[] = new Parameter($params[$i]);
63+
$this->parameters[] = new Parameter($this->processor, $params[$i]);
5764
}
5865

5966
if ($block->getTypeBoolean('@protected'))

docgen/src/Parameter.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,32 @@
11
<?php
22
class Parameter
33
{
4+
public $processor;
45
public $name; // rect, copy, etc
56
public $types = []; // an array containing all possible types it can be: string, number, etc
67
public $help = [];
78
public $optional = false;
89
public $default = null; // assigned value is the default value
910
public $debug = '';
1011

11-
public function __construct($line)
12+
public function __construct($processor, $line)
1213
{
14+
$this->processor = $processor;
15+
1316
preg_match("/.*(@param)\s?{(\S*)} (\S*)( - ?)?(.*)/", $line, $output);
1417

18+
// $this->processor->log("Parameter count: " . count($output));
19+
1520
if (count($output) > 2)
1621
{
22+
// $this->processor->log("parsePhaser parameter");
1723
$this->parsePhaser($output);
1824
}
1925
else
2026
{
2127
preg_match("/(@param)\s(\S*)\s{(\S*)}\s?(.*)?/", $line, $output);
28+
29+
// $this->processor->log("parsePixi parameter");
2230
$this->parsePixi($output);
2331
}
2432

@@ -27,6 +35,8 @@ public function __construct($line)
2735
public function parsePhaser($output)
2836
{
2937
$name = $output[3];
38+
39+
$this->processor->log("parameter: $name");
3040

3141
if ($name[0] === '[')
3242
{
@@ -75,6 +85,8 @@ public function parsePixi($output)
7585
$this->name = $output[2];
7686
$this->types[] = $output[3];
7787

88+
$this->processor->log("parameter: $this->name");
89+
7890
if (isset($output[4]))
7991
{
8092
$this->help[] = $output[4];

docgen/src/PhaserDocGen.php

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
class PhaserDocGen
3+
{
4+
private $src;
5+
private $ignore = array('.', '..');
6+
private $fileIgnore = array('p2.js');
7+
8+
public $log;
9+
public $files;
10+
public $classes;
11+
12+
/**
13+
* Processes the Phaser / Pixi source code
14+
*
15+
* @return PhaserDocGen
16+
*/
17+
public function __construct()
18+
{
19+
$this->src = realpath('../src');
20+
21+
$this->classes = [];
22+
23+
}
24+
25+
public function start()
26+
{
27+
ob_start();
28+
29+
$this->files = $this->dirToArray($this->src);
30+
31+
ob_end_flush();
32+
}
33+
34+
private function dirToArray($dir)
35+
{
36+
// set timeout
37+
set_time_limit(60);
38+
39+
$result = [];
40+
$root = scandir($dir);
41+
$dirs = array_diff($root, $this->ignore);
42+
43+
foreach ($dirs as $key => $value)
44+
{
45+
$path = realpath($dir . DIRECTORY_SEPARATOR . $value);
46+
47+
if (is_dir($path))
48+
{
49+
$result[$value] = $this->dirToArray($path);
50+
}
51+
else
52+
{
53+
if (substr($value, -3) === '.js')
54+
{
55+
if (!in_array($value, $this->fileIgnore))
56+
{
57+
$index = str_replace($this->src, "", $path);
58+
$index = substr($index, 1);
59+
$result[substr($value, 0, -3)] = $index;
60+
61+
$this->classes[substr($value, 0, -3)] = new Processor("../src/$index");
62+
63+
// Dump to log
64+
echo $index . "\n";
65+
66+
ob_flush();
67+
// $this->log[] = $value;
68+
}
69+
}
70+
}
71+
}
72+
73+
return $result;
74+
75+
}
76+
77+
}
78+
79+
?>

docgen/src/Processor.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class Processor
99
public $methods;
1010
public $properties;
1111

12+
public $processLog;
13+
1214
/**
1315
* Processes the given JS source file.
1416
*
@@ -25,6 +27,19 @@ public function __construct($file)
2527
$this->scanFile();
2628
}
2729

30+
public function log($text) {
31+
32+
$this->processLog[] = $text;
33+
34+
}
35+
36+
public function getLog() {
37+
38+
return $this->processLog;
39+
// return array_reverse($this->processLog);
40+
41+
}
42+
2843
/**
2944
* Scans the given JS source file and extracts blocks from it
3045
*/
@@ -77,21 +92,23 @@ private function scanFile() {
7792
{
7893
if ($this->blocks[$i]->isClass)
7994
{
80-
$this->class = new ClassDesc($this->blocks[$i]);
95+
$this->class = new ClassDesc($this, $this->blocks[$i]);
8196
}
8297
else if ($this->blocks[$i]->isConst)
8398
{
84-
$tempConst = new Constant($this->blocks[$i]);
99+
$tempConst = new Constant($this, $this->blocks[$i]);
100+
85101
$this->consts[$tempConst->name] = $tempConst;
86102
}
87103
else if ($this->blocks[$i]->isMethod)
88104
{
89-
$tempMethod = new Method($this->blocks[$i]);
105+
$tempMethod = new Method($this, $this->blocks[$i]);
106+
90107
$this->methods[$tempMethod->name] = $tempMethod;
91108
}
92109
else if ($this->blocks[$i]->isProperty)
93110
{
94-
$tempProperty = new Property($this->blocks[$i]);
111+
$tempProperty = new Property($this, $this->blocks[$i]);
95112

96113
if ($tempProperty->corrupted === false)
97114
{

docgen/src/Property.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
class Property
33
{
4+
public $processor;
45
public $line; // number, line number in the source file this is found on
56
public $name; // visible, name, parent
67
public $types = []; // an array containing all possible types it can be: string, number, etc
@@ -15,8 +16,10 @@ class Property
1516

1617
public $corrupted = false;
1718

18-
public function __construct($block)
19+
public function __construct($processor, $block)
1920
{
21+
$this->processor = $processor;
22+
2023
// Because zero offset + allowing for final line
2124
$this->line = $block->end + 2;
2225

docgen/view.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@
5656
<h1><?php echo $src ?></h1>
5757

5858
<?php
59+
echo "<pre>";
60+
print_r($data->getLog());
61+
echo "</pre>";
62+
5963
echo "<pre>";
6064
print_r($data->class->getArray());
6165
echo "</pre>";

0 commit comments

Comments
 (0)