Skip to content

Commit 60888f6

Browse files
committed
json export working. Tidied up for Methods and Parameters.
1 parent 40efc32 commit 60888f6

7 files changed

Lines changed: 134 additions & 35 deletions

File tree

docgen/export.php

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

docgen/index.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,7 @@ function dirToArray($dir) {
4949
$index = str_replace($src, "", $path);
5050
$index = substr($index, 1);
5151

52-
// $slash = strrpos($index, DIRECTORY_SEPARATOR);
53-
54-
// if ($slash > 0)
55-
// {
56-
// // $index = substr($index, 0, $slash);
57-
// }
58-
5952
$result[substr($value, 0, -3)] = $index;
60-
61-
// $result[$index] = substr($value, 0, -3);
62-
// $result[] = [ substr($value, 0, -3), $index ];
6353
}
6454
}
6555
}
@@ -89,7 +79,8 @@ function displaySection($title, $files) {
8979
}
9080
else
9181
{
92-
echo "<li><a href=\"view.php?src=$file\">$name</a></li>";
82+
echo "<li><a href=\"view.php?src=$file\">$name</a>";
83+
echo " &nbsp;&nbsp; [ <a href=\"export.php?src=$file\">json</a> ]</li>";
9384
}
9485
}
9586

docgen/src/ClassDesc.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,19 @@ public function __construct($block)
4444

4545
public function getArray()
4646
{
47+
$params = [];
48+
49+
for ($i = 0; $i < count($this->parameters); $i++)
50+
{
51+
$params[] = $this->parameters[$i]->getArray();
52+
}
53+
4754
return array(
4855
'name' => $this->name,
4956
'extends' => $this->extends,
5057
'static' => $this->isStatic,
5158
'constructor' => $this->hasConstructor,
52-
'parameters' => $this->parameters,
59+
'parameters' => $params,
5360
'help' => implode('\n', $this->help)
5461
);
5562

docgen/src/Method.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Method
66
public $title = [];
77
public $parameters = []; // an array containing the parameters
88
public $help = [];
9-
public $returns = false;
9+
public $returns = null;
1010

1111
public $isPublic = true;
1212
public $isProtected = false;
@@ -101,16 +101,23 @@ public function getVisibility()
101101

102102
public function getArray()
103103
{
104+
$params = [];
105+
106+
foreach ($this->parameters as $key => $value)
107+
{
108+
$params[] = $value->getArray();
109+
}
110+
104111
return array(
105-
'title' => $this->title,
112+
'name' => $this->title['name'],
106113
'static' => $this->isStatic,
107114
'returns' => $this->returns,
108115
'help' => implode('\n', $this->help),
109116
'line' => $this->line,
110117
'public' => $this->isPublic,
111118
'protected' => $this->isProtected,
112119
'private' => $this->isPrivate,
113-
'parameters' => $this->parameters
120+
'parameters' => $params
114121
);
115122

116123
}

docgen/src/Parameter.php

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class Parameter
55
public $types = []; // an array containing all possible types it can be: string, number, etc
66
public $help = [];
77
public $optional = false;
8-
public $default = false; // assigned value is the default value
8+
public $default = null; // assigned value is the default value
99
public $debug = '';
1010

1111
public function __construct($line)
@@ -28,23 +28,18 @@ public function parsePhaser($output)
2828
{
2929
$name = $output[3];
3030

31-
// $this->debug = $name . " -- ";
32-
3331
if ($name[0] === '[')
3432
{
3533
$this->optional = true;
3634
$name = substr($name, 1, -1);
3735

38-
// $this->debug .= $name . " -- ";
39-
4036
// Default?
4137
$equals = strpos($name, '=');
4238

4339
if ($equals > 0)
4440
{
4541
$this->default = (string) substr($name, $equals + 1);
4642
$name = substr($name, 0, $equals);
47-
// $this->debug .= $name . " -eq- " . $equals . " -def- " . $this->default;
4843
}
4944
}
5045

@@ -71,7 +66,7 @@ public function parsePhaser($output)
7166
}
7267
}
7368

74-
$this->help = $output[5];
69+
$this->help[] = $output[5];
7570

7671
}
7772

@@ -82,10 +77,26 @@ public function parsePixi($output)
8277

8378
if (isset($output[4]))
8479
{
85-
$this->help = $output[4];
86-
80+
$this->help[] = $output[4];
8781
}
8882
}
8983

84+
public function getArray()
85+
{
86+
return array(
87+
'name' => $this->name,
88+
'type' => $this->types,
89+
'help' => implode('\n', $this->help),
90+
'optional' => $this->optional,
91+
'default' => $this->default
92+
);
93+
94+
}
95+
96+
public function getJSON()
97+
{
98+
return json_encode($this->getArray());
99+
}
100+
90101
}
91102
?>

docgen/src/Processor.php

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Processor
1818
public function __construct($file)
1919
{
2020
$this->consts = [];
21-
$this->methhods = [];
21+
$this->methods = [];
2222
$this->properties = [];
2323
$this->file = $file;
2424

@@ -92,7 +92,11 @@ private function scanFile() {
9292
else if ($this->blocks[$i]->isProperty)
9393
{
9494
$tempProperty = new Property($this->blocks[$i]);
95-
$this->properties[$tempProperty->name] = $tempProperty;
95+
96+
if ($tempProperty->corrupted === false)
97+
{
98+
$this->properties[$tempProperty->name] = $tempProperty;
99+
}
96100
}
97101
}
98102

@@ -103,6 +107,41 @@ private function scanFile() {
103107

104108
}
105109

110+
public function getArray()
111+
{
112+
$consts = [];
113+
$methods = [];
114+
$properties = [];
115+
116+
foreach ($this->consts as $key => $value)
117+
{
118+
$consts[] = $value->getArray();
119+
}
120+
121+
foreach ($this->methods as $key => $value)
122+
{
123+
$methods[] = $value->getArray();
124+
}
125+
126+
foreach ($this->properties as $key => $value)
127+
{
128+
$properties[] = $value->getArray();
129+
}
130+
131+
return array(
132+
'class' => $this->class->getArray(),
133+
'consts' => $consts,
134+
'methods' => $methods,
135+
'properties' => $properties
136+
);
137+
138+
}
139+
140+
public function getJSON()
141+
{
142+
return json_encode($this->getArray());
143+
}
144+
106145
public function getConstsArray()
107146
{
108147
$out = [];

docgen/src/Property.php

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
<?php
22
class Property
33
{
4-
public $line; // number, line number in the source file this is found on?
5-
public $name; // visible, name, parent
6-
public $types = []; // an array containing all possible types it can be: string, number, etc
7-
public $default = false; // assigned value is the default value
4+
public $line; // number, line number in the source file this is found on
5+
public $name; // visible, name, parent
6+
public $types = []; // an array containing all possible types it can be: string, number, etc
7+
public $default = null; // assigned value is the default value
88
public $help = [];
99
public $inlineHelp = '';
1010

1111
public $isPublic = true;
1212
public $isProtected = false;
1313
public $isPrivate = false;
14-
1514
public $isReadOnly = false;
1615

16+
public $corrupted = false;
17+
1718
public function __construct($block)
1819
{
1920
// Because zero offset + allowing for final line
@@ -23,12 +24,19 @@ public function __construct($block)
2324

2425
if (count($output) > 3)
2526
{
26-
$this->parsePhaser($output, $block);
27+
$result = $this->parsePhaser($output, $block);
2728
}
2829
else
2930
{
3031
preg_match("/(@.*) (.*)/", $block->getLine('@property'), $output);
31-
$this->parsePixi($output, $block);
32+
$result = $this->parsePixi($output, $block);
33+
}
34+
35+
if ($result === false)
36+
{
37+
// Bail out, tell the Process we've a duff Property here
38+
$this->corrupted = true;
39+
return false;
3240
}
3341

3442
if ($block->getTypeBoolean('@protected'))
@@ -42,13 +50,15 @@ public function __construct($block)
4250
$this->isPrivate = true;
4351
}
4452

45-
if ($block->getTypeBoolean('@readonly'))
53+
if ($block->getTypeBoolean('@readonly') || $block->getTypeBoolean('@readOnly'))
4654
{
4755
$this->isReadOnly = true;
4856
}
4957

5058
$this->help = $block->cleanContent();
5159

60+
return true;
61+
5262
}
5363

5464
public function parsePhaser($output, $block)
@@ -68,11 +78,20 @@ public function parsePhaser($output, $block)
6878
}
6979
}
7080

81+
return true;
82+
7183
}
7284

7385
public function parsePixi($output, $block)
7486
{
75-
$this->name = $output[2];
87+
if (isset($output[2]))
88+
{
89+
$this->name = $output[2];
90+
}
91+
else
92+
{
93+
return false;
94+
}
7695

7796
if ($block->getTypeBoolean('@type'))
7897
{
@@ -84,6 +103,8 @@ public function parsePixi($output, $block)
84103
$this->default = $block->getTag('@default');
85104
}
86105

106+
return true;
107+
87108
}
88109

89110
public function getArray()

0 commit comments

Comments
 (0)