Skip to content

Commit f45f19c

Browse files
committed
Now merging and sorting extended methods and properties correctly. JSON export tidied up.
1 parent ecfed2b commit f45f19c

6 files changed

Lines changed: 164 additions & 63 deletions

File tree

docgen/export.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
<?php
2+
if (isset($_GET['src']))
3+
{
4+
$src = $_GET['src'];
5+
}
6+
27
require 'src/Block.php';
38
require 'src/ClassDesc.php';
49
require 'src/Constant.php';
@@ -44,6 +49,7 @@
4449
echo $sprite;
4550

4651

52+
4753
// foreach ($gen->classes as $key => $processor)
4854
// {
4955
// echo $key . " = " . $processor . "\n";

docgen/json.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
if (isset($_GET['src']))
3+
{
4+
$src = $_GET['src'];
5+
}
6+
7+
require 'src/Block.php';
8+
require 'src/ClassDesc.php';
9+
require 'src/Constant.php';
10+
require 'src/Method.php';
11+
require 'src/Parameter.php';
12+
require 'src/Property.php';
13+
require 'src/ReturnType.php';
14+
require 'src/Processor.php';
15+
require 'src/PhaserDocGen.php';
16+
17+
header('Content-Type: application/json');
18+
19+
$gen = new PhaserDocGen();
20+
$gen->start();
21+
22+
$sprite = $gen->get('Phaser.Sprite');
23+
24+
$gen->extend('Phaser.Sprite');
25+
26+
echo $sprite->getJSON();
27+
28+
?>

docgen/src/Exclude.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
/*
4+
PIXI.DisplayObject
5+
6+
click
7+
mousedown
8+
mouseout
9+
mouseover
10+
mouseup
11+
mouseupoutside
12+
rightclick
13+
rightdown
14+
rightup
15+
rightupoutside
16+
setInteractive
17+
tap
18+
touchend
19+
touchendoutside
20+
touchstart
21+
*/
22+
23+
?>

docgen/src/Method.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ public function getArray()
126126
'public' => $this->isPublic,
127127
'protected' => $this->isProtected,
128128
'private' => $this->isPrivate,
129-
'parameters' => $params
129+
'parameters' => $params,
130+
'inherited' => $this->inherited,
131+
'inheritedFrom' => $this->inheritedFrom
130132
);
131133

132134
}

docgen/src/PhaserDocGen.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function extend($classKey = '')
3030
{
3131
if ($classKey !== '')
3232
{
33-
echo "Extending $classKey\n";
33+
// echo "Extending $classKey\n";
3434
$this->classes[$classKey]->extend();
3535
}
3636
else
@@ -40,7 +40,7 @@ public function extend($classKey = '')
4040
{
4141
$processor->extend();
4242

43-
echo "Extended $key\n";
43+
// echo "Extended $key\n";
4444
}
4545
}
4646

docgen/src/Processor.php

Lines changed: 102 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,7 @@ private function scanFile() {
158158
$this->corrupted = true;
159159
}
160160

161-
// Alphabetically sort the arrays based on the key
162-
ksort($this->consts);
163-
164-
ksort($this->methods['public']);
165-
ksort($this->methods['protected']);
166-
ksort($this->methods['private']);
167-
ksort($this->methods['static']);
168-
169-
ksort($this->properties['public']);
170-
ksort($this->properties['protected']);
171-
ksort($this->properties['private']);
161+
$this->sortArrays();
172162

173163
}
174164

@@ -177,28 +167,9 @@ public function getPublicProperties()
177167
return $this->properties['public'];
178168
}
179169

180-
public function getPublicMethods($exclude = null)
170+
public function getPublicMethods()
181171
{
182-
if (is_array($exclude))
183-
{
184-
// Get everything not already in the given array
185-
$output = [];
186-
187-
foreach ($this->methods as $key => $value)
188-
{
189-
if (!array_key_exists($key, $exclude))
190-
{
191-
$output[$key] = $value;
192-
}
193-
}
194-
195-
return $output;
196-
}
197-
else
198-
{
199-
return $this->methods['public'];
200-
}
201-
172+
return $this->methods['public'];
202173
}
203174

204175
public function getArray()
@@ -212,14 +183,52 @@ public function getArray()
212183
$consts[] = $value->getArray();
213184
}
214185

215-
foreach ($this->methods as $key => $value)
186+
// Methods
187+
188+
$methods['public'] = [];
189+
$methods['protected'] = [];
190+
$methods['private'] = [];
191+
$methods['static'] = [];
192+
193+
foreach ($this->methods['public'] as $key => $value)
194+
{
195+
$methods['public'][] = $value->getArray();
196+
}
197+
198+
foreach ($this->methods['protected'] as $key => $value)
199+
{
200+
$methods['protected'][] = $value->getArray();
201+
}
202+
203+
foreach ($this->methods['private'] as $key => $value)
216204
{
217-
$methods[] = $value->getArray();
205+
$methods['private'][] = $value->getArray();
218206
}
219207

220-
foreach ($this->properties as $key => $value)
208+
foreach ($this->methods['static'] as $key => $value)
221209
{
222-
$properties[] = $value->getArray();
210+
$methods['static'][] = $value->getArray();
211+
}
212+
213+
// Properties
214+
215+
$properties['public'] = [];
216+
$properties['protected'] = [];
217+
$properties['private'] = [];
218+
219+
foreach ($this->properties['public'] as $key => $value)
220+
{
221+
$properties['public'][] = $value->getArray();
222+
}
223+
224+
foreach ($this->properties['protected'] as $key => $value)
225+
{
226+
$properties['protected'][] = $value->getArray();
227+
}
228+
229+
foreach ($this->properties['private'] as $key => $value)
230+
{
231+
$properties['private'][] = $value->getArray();
223232
}
224233

225234
return array(
@@ -253,7 +262,6 @@ public function extend()
253262
// Quick bailout
254263
if (!$this->class->extendsFrom())
255264
{
256-
echo "quick bailout\n";
257265
return;
258266
}
259267

@@ -263,53 +271,87 @@ public function extend()
263271
{
264272
$extends = $proc->class->extends;
265273
$proc = $this->docgen->get($extends);
266-
echo "\n\nextend found: " . $proc->getName() . "\n";
274+
// echo "\n\nextend found: " . $proc->getName() . "\n";
267275

268276
$this->merge($proc);
269277
}
270278
while ($proc->class->extendsFrom());
271279

280+
$this->sortArrays();
281+
272282
}
273283

274-
public function merge($processor)
284+
public function sortArrays()
285+
{
286+
// Alphabetically sort the arrays based on the key
287+
ksort($this->consts);
288+
289+
ksort($this->methods['public']);
290+
ksort($this->methods['protected']);
291+
ksort($this->methods['private']);
292+
ksort($this->methods['static']);
293+
294+
ksort($this->properties['public']);
295+
ksort($this->properties['protected']);
296+
ksort($this->properties['private']);
297+
}
298+
299+
public function getMethodNames()
300+
{
301+
$output = [];
302+
303+
foreach ($this->methods['public'] as $key => $method)
304+
{
305+
$output[$method->name] = true;
306+
}
307+
308+
return $output;
309+
}
310+
311+
public function getPropertyNames()
275312
{
276-
echo "Merging ...\n\n";
313+
$output = [];
314+
315+
foreach ($this->properties['public'] as $key => $property)
316+
{
317+
$output[$property->name] = true;
318+
}
277319

320+
return $output;
321+
}
322+
323+
public function merge($processor)
324+
{
278325
// We only want to merge in public methods and properties.
279326
// Technically JavaScript merges in bloody everything, but for the sake of docs we'll keep them #public# only.
280327

281-
echo "Methods\n";
282-
echo "-------\n";
283-
284-
$inheritedMethods = $processor->getPublicMethods($this->getPublicMethods());
328+
$inheritedMethods = $processor->getPublicMethods();
329+
$currentMethods = $this->getMethodNames();
285330

286331
// Flag them as inherited
287332
foreach ($inheritedMethods as $key => $method)
288333
{
289-
echo $method->name . "\n";
290-
$method->inherited = true;
291-
$method->inheritedFrom = $processor->getName();
334+
if (!array_key_exists($method->name, $currentMethods))
335+
{
336+
$method->inherited = true;
337+
$method->inheritedFrom = $processor->getName();
338+
$this->methods['public'][$method->name] = $method;
339+
}
292340
}
293341

294-
// We should only merge methods not already defined
295-
$this->methods['public'] = array_merge($this->methods['public'], $inheritedMethods);
296-
297-
echo "\n";
298-
echo "Properties\n";
299-
echo "----------\n";
300-
301342
$inheritedProperties = $processor->getPublicProperties();
343+
$currentProperties = $this->getPropertyNames();
302344

303345
// Flag them as inherited!
304346
foreach ($inheritedProperties as $key => $property)
305347
{
306-
echo $property->name . "\n";
307-
$property->inherited = true;
308-
$property->inheritedFrom = $processor->getName();
348+
if (!array_key_exists($property->name, $currentProperties))
349+
{
350+
$property->inherited = true;
351+
$property->inheritedFrom = $processor->getName();
352+
$this->properties['public'][$property->name] = $property;
353+
}
309354
}
310-
311-
$this->properties['public'] = array_merge($this->properties['public'], $inheritedProperties);
312-
313355
}
314356

315357
/**

0 commit comments

Comments
 (0)