Skip to content

Commit 9cd2d3e

Browse files
committed
add type information to JSON renderer
keep information on whether an item is a class, interface or trait
1 parent 66ee578 commit 9cd2d3e

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Yii Framework 2 apidoc extension Change Log
88
- Enh #38: Fixed display of default values given as octal or hex notation (hiqsol)
99
- Enh: Display TOC only if there is more than one headline (cebe)
1010
- Enh: Extracted markdown code highlighting to a trait `MarkdownHighlightTrait` (cebe)
11+
- Enh: Added "type" attribute to JSON renderer to keep information about whether an entry is a class, interface or trait (cebe)
1112

1213

1314
2.1.0 November 22, 2016

Diff for: templates/json/ApiRenderer.php

+13
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77

88
namespace yii\apidoc\templates\json;
99

10+
use yii\apidoc\models\ClassDoc;
1011
use yii\apidoc\models\Context;
12+
use yii\apidoc\models\InterfaceDoc;
13+
use yii\apidoc\models\TraitDoc;
1114
use yii\apidoc\renderers\ApiRenderer as BaseApiRenderer;
1215
use yii\base\ViewContextInterface;
1316
use Yii;
@@ -29,6 +32,16 @@ class ApiRenderer extends BaseApiRenderer implements ViewContextInterface
2932
public function render($context, $targetDir)
3033
{
3134
$types = array_merge($context->classes, $context->interfaces, $context->traits);
35+
foreach($types as $name => $type) {
36+
$types[$name] = (array) $type;
37+
if ($type instanceof ClassDoc) {
38+
$types[$name]['type'] = 'class';
39+
} elseif ($type instanceof InterfaceDoc) {
40+
$types[$name]['type'] = 'interface';
41+
} elseif ($type instanceof TraitDoc) {
42+
$types[$name]['type'] = 'trait';
43+
}
44+
}
3245
file_put_contents($targetDir . '/types.json', json_encode($types, JSON_PRETTY_PRINT));
3346
}
3447

0 commit comments

Comments
 (0)