Skip to content

Commit d6ee749

Browse files
committed
Now generates Methods, parameters and Properties.
1 parent d9cbdd1 commit d6ee749

1 file changed

Lines changed: 169 additions & 64 deletions

File tree

docgen/gen.php

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

22-
<textarea spellcheck="false">
22+
<pre spellcheck="false">
2323
<?php
24-
2524
class Block
2625
{
2726
public $start = 0;
@@ -71,9 +70,9 @@ public function getLine($scan)
7170
}
7271
}
7372

74-
public function getContentIndex($scan)
73+
public function getContentIndex($scan, $offset = 0)
7574
{
76-
for ($i = 0; $i < count($this->content); $i++)
75+
for ($i = $offset; $i < count($this->content); $i++)
7776
{
7877
preg_match("/(@\w*)/", $this->content[$i], $output);
7978

@@ -86,6 +85,148 @@ public function getContentIndex($scan)
8685
return -1;
8786
}
8887

88+
public function getLines($scan)
89+
{
90+
$output = [];
91+
92+
for ($i = 0; $i < count($this->content); $i++)
93+
{
94+
preg_match("/(@\w*)/", $this->content[$i], $line);
95+
96+
if ($line && $line[0] === $scan)
97+
{
98+
$output[] = $this->content[$i];
99+
}
100+
}
101+
102+
return $output;
103+
}
104+
105+
public function cleanContent()
106+
{
107+
$output = [];
108+
109+
for ($i = 0; $i < count($this->content); $i++)
110+
{
111+
$line = trim($this->content[$i]);
112+
113+
// remove * from the start
114+
if (substr($line, 0, 1) === '*')
115+
{
116+
$line = substr($line, 1);
117+
$line = trim($line);
118+
}
119+
120+
// Have we got a @ next?
121+
if (substr($line, 0, 1) !== '@')
122+
{
123+
$output[] = $line;
124+
}
125+
}
126+
127+
// Trim off the final element if empty
128+
if (count($output) > 0 && $output[count($output) - 1] === '')
129+
{
130+
array_pop($output);
131+
}
132+
133+
return $output;
134+
}
135+
136+
137+
}
138+
139+
class Parameter
140+
{
141+
public $name; // rect, copy, etc
142+
public $types = []; // an array containing all possible types it can be: string, number, etc
143+
public $help = [];
144+
public $optional = false;
145+
public $default = false; // assigned value is the default value
146+
147+
public function __construct($line)
148+
{
149+
preg_match("/.*(@param)\s?{(\S*)} (\S*)( - ?)?(.*)/", $line, $output);
150+
151+
$this->types = explode('|', $output[2]);
152+
$this->help = $output[5];
153+
154+
$name = $output[3];
155+
156+
if ($name[0] === '[')
157+
{
158+
$this->optional = true;
159+
$name = substr($name, 1, -1);
160+
161+
// Default?
162+
$equals = strpos($name, '=');
163+
164+
if ($equals > 0)
165+
{
166+
$name = substr($name, 0, $equals - 1);
167+
$this->default = substr($name, $equals + 1);
168+
}
169+
}
170+
171+
$this->name = $name;
172+
}
173+
174+
}
175+
176+
class Method
177+
{
178+
public $line; // number, line number in the source file this is found on?
179+
public $name; // bringToTop, kill, etc
180+
public $parameters = []; // an array containing the parameters
181+
public $help = [];
182+
public $returnType = '';
183+
public $returnHelp = '';
184+
185+
public $isPublic = true;
186+
public $isProtected = false;
187+
public $isPrivate = false;
188+
189+
public function __construct($block)
190+
{
191+
// Because zero offset + allowing for final line
192+
$this->line = $block->end + 2;
193+
194+
$name = $block->getLine('@method');
195+
196+
$equals = strpos($name, '#');
197+
198+
if ($equals > 0)
199+
{
200+
$name = substr($name, $equals + 1);
201+
}
202+
203+
$this->name = $name;
204+
205+
$params = $block->getLines('@param');
206+
207+
for ($i = 0; $i < count($params); $i++)
208+
{
209+
$this->parameters[] = new Parameter($params[$i]);
210+
}
211+
212+
// parameter match
213+
// preg_match("/.*(@param)\s?{(\S*)} (\S*)( - ?)?(.*)/", $block->getLine('@property'), $output);
214+
215+
if ($block->getTypeBoolean('@protected'))
216+
{
217+
$this->isPublic = false;
218+
$this->isProtected = true;
219+
}
220+
else if ($block->getTypeBoolean('@private'))
221+
{
222+
$this->isPublic = false;
223+
$this->isPrivate = true;
224+
}
225+
226+
$this->help = $block->cleanContent();
227+
228+
}
229+
89230
}
90231

91232
class Property
@@ -94,7 +235,7 @@ class Property
94235
public $name; // visible, name, parent
95236
public $types = []; // an array containing all possible types it can be: string, number, etc
96237
public $default = false; // assigned value is the default value
97-
public $help = '';
238+
public $help = [];
98239
public $inlineHelp = '';
99240

100241
public $isPublic = true;
@@ -133,57 +274,16 @@ public function __construct($block)
133274
}
134275
}
135276

277+
$this->help = $block->cleanContent();
278+
136279
}
137280

138281
}
139282

140-
function createProperty($block)
141-
{
142-
global $properties;
143-
144-
/**
145-
* @property {number} type - The const type of this object.
146-
* @readonly
147-
*/
148-
149-
/**
150-
* @property {number} z - The z-depth value of this object within its Group (remember the World is a Group as well). No two objects in a Group can have the same z value.
151-
*/
152-
153-
/**
154-
* @property {string|Phaser.RenderTexture|Phaser.BitmapData|PIXI.Texture} key - This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture, BitmapData or PIXI.Texture.
155-
*/
156-
157-
/**
158-
* Should this Sprite be automatically culled if out of range of the camera?
159-
* A culled sprite has its renderable property set to 'false'.
160-
* Be advised this is quite an expensive operation, as it has to calculate the bounds of the object every frame, so only enable it if you really need it.
161-
*
162-
* @property {boolean} autoCull - A flag indicating if the Sprite should be automatically camera culled or not.
163-
* @default
164-
*/
165-
166-
/**
167-
* By default Sprites won't add themselves to any physics system and their physics body will be `null`.
168-
* To enable them for physics you need to call `game.physics.enable(sprite, system)` where `sprite` is this object
169-
* and `system` is the Physics system you want to use to manage this body. Once enabled you can access all physics related properties via `Sprite.body`.
170-
*
171-
* Important: Enabling a Sprite for P2 or Ninja physics will automatically set `Sprite.anchor` to 0.5 so the physics body is centered on the Sprite.
172-
* If you need a different result then adjust or re-create the Body shape offsets manually, and/or reset the anchor after enabling physics.
173-
*
174-
* @property {Phaser.Physics.Arcade.Body|Phaser.Physics.P2.Body|Phaser.Physics.Ninja.Body|null} body
175-
* @default
176-
*/
177-
178-
$p = new Property();
179-
180-
$valueLine = $block[isProperty($block)];
181-
182-
183-
184-
}
185283

186284
$blocks = [];
285+
286+
$consts = [];
187287
$properties = [];
188288
$methods = [];
189289

@@ -230,8 +330,23 @@ function createProperty($block)
230330
// That's the whole file scanned, how many blocks did we get out of it?
231331
echo count($blocks) . " blocks found\n\n";
232332

233-
echo "Properties:\n\n";
333+
echo "\nMethods:\n\n";
234334

335+
for ($i = 0; $i < count($blocks); $i++)
336+
{
337+
if ($blocks[$i]->isMethod)
338+
{
339+
$method = new Method($blocks[$i]);
340+
341+
echo $method->name . "\n";
342+
echo "Help: " . "\n";
343+
// print_r($method->help);
344+
print_r($method->parameters);
345+
}
346+
}
347+
348+
349+
echo "\nProperties:\n\n";
235350

236351
for ($i = 0; $i < count($blocks); $i++)
237352
{
@@ -249,26 +364,16 @@ function createProperty($block)
249364

250365
echo "Source code line " . $property->line . "\n";
251366
echo "Default: " . $property->default . "\n";
367+
echo "Help: " . "\n";
368+
print_r($property->help);
252369

253370
echo "\n\n";
254371

255372
// echo $blocks[$i]->start . "\n";
256373
}
257374
}
258-
259-
/*
260-
echo "\nMethods:\n\n";
261-
262-
for ($i = 0; $i < count($blocks); $i++)
263-
{
264-
if ($blocks[$i]->isMethod)
265-
{
266-
echo $blocks[$i]->start . "\n";
267-
}
268-
}
269-
*/
270375
?>
271-
</textarea>
376+
</pre>
272377

273378
</body>
274379
</html>

0 commit comments

Comments
 (0)