Skip to content

Commit a79cafe

Browse files
committed
docgen is now adding inherited classes into the results properly.
1 parent 473e9a1 commit a79cafe

6 files changed

Lines changed: 96 additions & 28 deletions

File tree

docgen/export.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,15 @@
3434
<?php
3535
$gen = new PhaserDocGen();
3636
$gen->start();
37+
38+
$sprite = $gen->get('Phaser.Sprite');
39+
40+
echo $sprite;
41+
3742
$gen->extend('Phaser.Sprite');
3843

44+
echo $sprite;
45+
3946

4047

4148
// foreach ($gen->classes as $key => $processor)

docgen/src/ClassDesc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function __construct($processor, $block)
4444
{
4545
$this->extends = $block->getLineContent('@extends');
4646

47-
if (substr($this->extends, 0, 6) !== 'Phaser')
47+
if (substr($this->extends, 0, 6) !== 'Phaser' && substr($this->extends, 0, 4) !== 'PIXI')
4848
{
4949
$this->extends = 'PIXI.' . $this->extends;
5050
}

docgen/src/Method.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class Method
88
public $parameters = []; // an array containing the parameters
99
public $help = [];
1010
public $returns = null;
11+
public $inherited = false;
1112

1213
public $isPublic = true;
1314
public $isProtected = false;

docgen/src/PhaserDocGen.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,19 @@ public function __construct()
1919
$this->src = realpath('../src');
2020

2121
$this->classes = [];
22-
2322
}
2423

2524
public function start()
2625
{
27-
ob_start();
28-
2926
$this->files = $this->dirToArray($this->src);
30-
31-
ob_end_flush();
3227
}
3328

3429
public function extend($classKey = '')
3530
{
3631
if ($classKey !== '')
3732
{
3833
echo "Extending $classKey\n";
39-
$this->classes[classKey]->extend();
34+
$this->classes[$classKey]->extend();
4035
}
4136
else
4237
{
@@ -46,12 +41,21 @@ public function extend($classKey = '')
4641
$processor->extend();
4742

4843
echo "Extended $key\n";
49-
ob_flush();
5044
}
5145
}
5246

5347
}
5448

49+
public function get($classKey)
50+
{
51+
if (array_key_exists($classKey, $this->classes))
52+
{
53+
return $this->classes[$classKey];
54+
}
55+
56+
return null;
57+
}
58+
5559
private function dirToArray($dir)
5660
{
5761
set_time_limit(60);
@@ -101,7 +105,6 @@ private function dirToArray($dir)
101105

102106
// Dump to log
103107
// echo $index . "\n";
104-
ob_flush();
105108
}
106109
}
107110
}

docgen/src/Processor.php

Lines changed: 75 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -172,18 +172,16 @@ private function scanFile() {
172172

173173
}
174174

175-
public function __toString()
175+
public function getPublicProperties()
176176
{
177-
if ($this->corrupted)
178-
{
179-
return "JSDoc Corrupted Class";
180-
}
181-
else
182-
{
183-
return "Class: " . $this->class->name . ", Methods: " . count($this->methods['public']);
184-
}
177+
return $this->properties['public'];
185178
}
186-
179+
180+
public function getPublicMethods()
181+
{
182+
return $this->methods['public'];
183+
}
184+
187185
public function getArray()
188186
{
189187
$consts = [];
@@ -233,23 +231,63 @@ public function getConstsArray()
233231

234232
public function extend()
235233
{
236-
// Need to iterate through all of the classes this may extend from, in order, and build it up
234+
// Quick bailout
235+
if (!$this->class->extendsFrom())
236+
{
237+
echo "quick bailout\n";
238+
return;
239+
}
237240

238241
$proc = $this;
239-
$parents = [];
240242

241-
// while ($proc->class->extendsFrom)
242-
// {
243-
// $parents[$proc->class->name] = $proc->getArray();
244-
// $proc = $this->docgen->get();
243+
do
244+
{
245+
$extends = $proc->class->extends;
246+
$proc = $this->docgen->get($extends);
247+
echo "\n\nextend found: " . $proc->getName() . "\n";
248+
249+
$this->merge($proc);
250+
}
251+
while ($proc->class->extendsFrom());
252+
253+
}
254+
255+
public function merge($processor)
256+
{
257+
echo "Merging ...\n\n";
258+
259+
// We only want to merge in public methods and properties.
260+
// Technically JavaScript merges in bloody everything, but for the sake of docs we'll keep them #public# only.
261+
262+
echo "Methods\n";
263+
echo "-------\n";
245264

246-
// }
265+
$inheritedMethods = $processor->getPublicMethods();
247266

248-
// Is there anything to extend anyway?
249-
if ($this->class->extendsFrom)
267+
// Flag them as inherited!
268+
foreach ($inheritedMethods as $key => $method)
250269
{
270+
echo $method->name . "\n";
271+
$method->inherited = true;
272+
}
273+
274+
$this->methods['public'] = array_merge($this->methods['public'], $inheritedMethods);
275+
276+
echo "\n";
277+
echo "Properties\n";
278+
echo "----------\n";
251279

280+
$inheritedProperties = $processor->getPublicProperties();
281+
282+
// Flag them as inherited!
283+
foreach ($inheritedProperties as $key => $property)
284+
{
285+
echo $property->name . "\n";
286+
$property->inherited = true;
252287
}
288+
289+
$this->properties['public'] = array_merge($this->properties['public'], $inheritedProperties);
290+
253291
}
254292

255293
/**
@@ -273,5 +311,23 @@ public function getLog() {
273311

274312
}
275313

314+
public function getName() {
315+
316+
return $this->class->name;
317+
318+
}
319+
320+
public function __toString()
321+
{
322+
if ($this->corrupted)
323+
{
324+
return "JSDoc Corrupted Class";
325+
}
326+
else
327+
{
328+
return "Class: " . $this->class->name . ", Methods: " . count($this->methods['public']) . ", Properties: " . count($this->properties['public']) . "\n";
329+
}
330+
}
331+
276332
}
277333
?>

docgen/src/Property.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class Property
88
public $default = null; // assigned value is the default value
99
public $help = [];
1010
public $inlineHelp = '';
11+
public $inherited = false;
1112

1213
public $isPublic = true;
1314
public $isProtected = false;

0 commit comments

Comments
 (0)