Skip to content

Commit efc5ea8

Browse files
hiqsolcebe
authored andcommitted
Added ApiRenderer::renderDefaultValue, fixed #38
close #122
1 parent e1c1cb1 commit efc5ea8

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Yii Framework 2 apidoc extension Change Log
44
2.1.1 under development
55
-----------------------
66

7-
- no changes in this release.
7+
- Enh #38: Fixed display of default values given as octal or hex notation (hiqsol)
88

99

1010
2.1.0 November 22, 2016

templates/html/ApiRenderer.php

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public function renderPropertySignature($property, $context = null)
247247
return '<span class="signature-defs">' . implode(' ', $definition) . '</span> '
248248
. '<span class="signature-type">' . $this->createTypeLink($property->types, $context) . '</span>'
249249
. ' ' . $this->createSubjectLink($property, $property->name) . ' '
250-
. ApiMarkdown::highlight('= ' . ($property->defaultValue === null ? 'null' : $property->defaultValue), 'php');
250+
. ApiMarkdown::highlight('= ' . $this->renderDefaultValue($property->defaultValue), 'php');
251251
}
252252

253253
/**
@@ -262,7 +262,7 @@ public function renderMethodSignature($method, $context = null)
262262
. ($param->isPassedByReference ? '<b>&</b>' : '')
263263
. ApiMarkdown::highlight(
264264
$param->name
265-
. ($param->isOptional ? ' = ' . $param->defaultValue : ''),
265+
. ($param->isOptional ? ' = ' . $this->renderDefaultValue($param->defaultValue) : ''),
266266
'php'
267267
);
268268
}
@@ -283,6 +283,38 @@ public function renderMethodSignature($method, $context = null)
283283
. str_replace(' ', ' ', ' ( ' . implode(', ', $params) . ' )');
284284
}
285285

286+
/**
287+
* Renders the default value.
288+
* @param mixed $value
289+
* @return string
290+
* @since 2.1.1
291+
*/
292+
public function renderDefaultValue($value)
293+
{
294+
if ($value === null) {
295+
return 'null';
296+
}
297+
298+
// special numbers which are usually used in octal or hex notation
299+
static $specials = [
300+
// file permissions
301+
'420' => '0644',
302+
'436' => '0664',
303+
'438' => '0666',
304+
'493' => '0755',
305+
'509' => '0775',
306+
'511' => '0777',
307+
// colors used in yii\captcha\CaptchaAction
308+
'2113696' => '0x2040A0',
309+
'16777215' => '0xFFFFFF',
310+
];
311+
if (isset($specials[$value])) {
312+
return $specials[$value];
313+
}
314+
315+
return $value;
316+
}
317+
286318
/**
287319
* @inheritdoc
288320
*/

0 commit comments

Comments
 (0)