Class yii\apidoc\templates\json\ApiRenderer

Inheritanceyii\apidoc\templates\json\ApiRenderer » yii\apidoc\renderers\ApiRenderer » yii\apidoc\renderers\BaseRenderer » yii\base\Component
Implementsyii\base\ViewContextInterface
Available since extension's version2.0.5
Source Code https://github.com/yiisoft/yii2-apidoc/blob/master/templates/json/ApiRenderer.php

The class for outputting documentation data structures as a JSON text.

Constants

Hide inherited constants

Constant Value Description Defined By
PHPSTAN_TYPE_BASE_URL 'https://phpstan.org/writing-php-code/phpdoc-types#' yii\apidoc\renderers\BaseRenderer
PHP_CLASS_BASE_URL 'https://www.php.net/class.' yii\apidoc\renderers\BaseRenderer
PHP_TYPES [ 'callable', 'array', 'string', 'boolean', 'bool', 'integer', 'int', 'float', 'object', 'resource', 'null', 'false', 'true', 'iterable', 'mixed', 'never', 'void', ] yii\apidoc\renderers\BaseRenderer
PHP_TYPE_ALIASES [ 'true' => 'boolean', 'false' => 'boolean', 'bool' => 'boolean', 'int' => 'integer', ] yii\apidoc\renderers\BaseRenderer
PHP_TYPE_BASE_URL 'https://www.php.net/language.types.' yii\apidoc\renderers\BaseRenderer
PHP_TYPE_DISPLAY_ALIASES [ 'bool' => 'boolean', 'int' => 'integer', ] yii\apidoc\renderers\BaseRenderer
PSALM_TYPE_BASE_URL 'https://psalm.dev/docs/annotating_code/type_syntax/' yii\apidoc\renderers\BaseRenderer

Method Details

Hide inherited methods

createSubjectLink() public method

Defined in: yii\apidoc\renderers\BaseRenderer::createSubjectLink()

Creates a link to a subject

public string createSubjectLink ( yii\apidoc\models\BaseDoc|yii\apidoc\models\PseudoTypeDoc|yii\apidoc\models\PseudoTypeImportDoc $subject, string|null $title null, array $options = [], yii\apidoc\models\TypeDoc|null $type null )
$subject yii\apidoc\models\BaseDoc|yii\apidoc\models\PseudoTypeDoc|yii\apidoc\models\PseudoTypeImportDoc
$title string|null
$options array

Additional HTML attributes for the link.

$type yii\apidoc\models\TypeDoc|null

createTypeLink() public method

Defined in: yii\apidoc\renderers\BaseRenderer::createTypeLink()

Creates a link to a type (class, interface or trait)

public string createTypeLink ( yii\apidoc\models\BaseDoc|yii\apidoc\models\BaseDoc[]|\phpDocumentor\Reflection\Type|\phpDocumentor\Reflection\Type[]|string|string[]|null $types, yii\apidoc\models\BaseDoc|null $context null, string|null $title null, array $options = [], ?\yii\apidoc\models\TypeDoc $currentTypeDoc null )
$types yii\apidoc\models\BaseDoc|yii\apidoc\models\BaseDoc[]|\phpDocumentor\Reflection\Type|\phpDocumentor\Reflection\Type[]|string|string[]|null
$context yii\apidoc\models\BaseDoc|null
$title string|null

A title to be used for the link TODO check whether [[yii...|Class]] is supported

$options array

Additional HTML attributes for the link.

$currentTypeDoc ?\yii\apidoc\models\TypeDoc

generateApiUrl() public method

Generate an url to a type in apidocs

public mixed generateApiUrl ( mixed $typeName )
$typeName mixed

                public function generateApiUrl($typeName)
{
}

            
generateFileName() protected method

protected generateFileName ( mixed $typeName )
$typeName mixed

                protected function generateFileName($typeName)
{
}

            
generateGuideUrl() public method

Defined in: yii\apidoc\renderers\BaseRenderer::generateGuideUrl()

Generate an url to a guide page

public string generateGuideUrl ( string $file )
$file string

                public function generateGuideUrl($file)
{
    //skip parsing external url
    if ((str_contains($file, 'https://')) || (str_contains($file, 'http://'))) {
        return $file;
    }
    $hash = '';
    if (($pos = strpos($file, '#')) !== false) {
        $hash = substr($file, $pos);
        $file = substr($file, 0, $pos);
    }
    return rtrim((string) $this->guideUrl, '/') . '/' . $this->guidePrefix . basename($file, '.md') . '.html' . $hash;
}

            
generateLink() protected method

Generate link markup

protected mixed generateLink ( mixed $text, mixed $href, mixed $options = [] )
$text mixed
$href mixed
$options mixed

Additional HTML attributes for the link.

getSourceUrl() public method

public getSourceUrl ( mixed $type, mixed $line null )
$type mixed
$line mixed

                public function getSourceUrl($type, $line = null)
{
}

            
getViewPath() public method

public getViewPath ( )

                public function getViewPath()
{
    return '';
}

            
init() public method
public mixed init ( )

                public function init()
{
    ApiMarkdown::$renderer = $this;
    ApiMarkdownLaTeX::$renderer = $this;
}

            
render() public method

Writes a given yii\apidoc\models\Context as JSON text to file 'types.json'.

public mixed render ( yii\apidoc\models\Context $context, mixed $targetDir )
$context yii\apidoc\models\Context

The api documentation context to render.

$targetDir mixed

                public function render($context, $targetDir)
{
    $types = array_merge($context->classes, $context->interfaces, $context->traits);
    foreach ($types as $name => $type) {
        $types[$name] = (array) $this->removeParentFieldsRecursive($type);
        if ($type instanceof ClassDoc) {
            $types[$name]['type'] = 'class';
        } elseif ($type instanceof InterfaceDoc) {
            $types[$name]['type'] = 'interface';
        } elseif ($type instanceof TraitDoc) {
            $types[$name]['type'] = 'trait';
        }
    }
    file_put_contents($targetDir . '/types.json', json_encode($types, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR));
}