diff --git a/CHANGELOG.md b/CHANGELOG.md index 6994f9e9..8551f837 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,11 +17,12 @@ Yii Framework 2 apidoc extension Change Log - Bug #179: Fixed incorrect output when string type hint is used in method parameters (arogachev) - Bug #199: Fixed processing of nullable return types (arogachev) - Bug #148: Fixed processing of code containing uniform variable syntax (arogachev) -- Enh #143: Do not include methods and properties marked as internal (arogachev) -- Bug #197: Adapted fixing of Markdown links for multiple links (arogachev) -- Bug #128: Fixed extracting of first sentence from the text containing backticks (arogachev) -- Enh #209: Added support for todos in properties and methods (arogachev) - Enh #18: Added pretty print for arrays (arogachev) +- Enh #209: Added support for todos in properties and methods (arogachev) +- Bug #128: Fixed extracting of first sentence from the text containing backticks (arogachev) +- Bug #197: Adapted fixing of Markdown links for multiple links (arogachev) +- Enh #143: Do not include methods and properties marked as internal (arogachev) +- Enh #147: Added feature of viewing method source code without external links (arogachev) 2.1.6 May 05, 2021 diff --git a/models/BaseDoc.php b/models/BaseDoc.php index ab8fbd4b..324064ba 100644 --- a/models/BaseDoc.php +++ b/models/BaseDoc.php @@ -50,7 +50,7 @@ class BaseDoc extends BaseObject /** * @param Type|null $aggregatedType - * @return string[]|array + * @return string[] */ protected function splitTypes($aggregatedType) { diff --git a/models/MethodDoc.php b/models/MethodDoc.php index 226cbd03..1006459b 100644 --- a/models/MethodDoc.php +++ b/models/MethodDoc.php @@ -24,6 +24,10 @@ class MethodDoc extends FunctionDoc public $visibility; // will be set by creating class public $definedBy; + /** + * @var string + */ + public $sourceCode = ''; /** @@ -44,5 +48,10 @@ public function __construct($reflector = null, $context = null, $config = []) $this->isStatic = $reflector->isStatic(); $this->visibility = $reflector->getVisibility(); + + $lines = file($this->sourceFile); + for ($i = $this->startLine - 1; $i <= $this->endLine - 1; $i++) { + $this->sourceCode .= substr($lines[$i], 4); + } } } diff --git a/templates/html/ApiRenderer.php b/templates/html/ApiRenderer.php index 3fdc35d4..34b617fb 100644 --- a/templates/html/ApiRenderer.php +++ b/templates/html/ApiRenderer.php @@ -7,6 +7,7 @@ namespace yii\apidoc\templates\html; +use Highlight\Highlighter; use yii\apidoc\helpers\ApiMarkdown; use yii\apidoc\models\MethodDoc; use yii\apidoc\models\PropertyDoc; @@ -102,12 +103,16 @@ public function render($context, $targetDir) if ($this->controller !== null) { Console::startProgress(0, $typeCount, 'Rendering files: ', false); } + $done = 0; + $higlighter = new Highlighter; + foreach ($types as $type) { $fileContent = $this->renderWithLayout($this->typeView, [ 'type' => $type, 'apiContext' => $context, 'types' => $types, + 'highlighter' => $higlighter, ]); file_put_contents($targetDir . '/' . $this->generateFileName($type->name), $fileContent); diff --git a/templates/html/views/methodDetails.php b/templates/html/views/methodDetails.php index ae6392d6..72500f7b 100644 --- a/templates/html/views/methodDetails.php +++ b/templates/html/views/methodDetails.php @@ -8,6 +8,7 @@ /* @var $type ClassDoc|TraitDoc */ /* @var $this yii\web\View */ /* @var $renderer \yii\apidoc\templates\html\ApiRenderer */ +/* @var $highlighter \Highlight\Highlighter */ $renderer = $this->context; @@ -90,6 +91,25 @@ + sourceCode; + $collapseId = 'collapse' . ucfirst($method->name); + ?> + +
+ + Source code + +
+
+ = $highlighter->highlight('php', $sourceCode)->value ?>
+
+