Final Class yii\apidoc\helpers\MarkdownContext

Inheritanceyii\apidoc\helpers\MarkdownContext
Available since extension's version4.0.2
Source Code https://github.com/yiisoft/yii2-apidoc/blob/master/helpers/MarkdownContext.php

Builds the API context needed for Markdown links without full documentation or source code.

Public Methods

Hide inherited methods

Method Description Defined By
create() Returns an independent context for link resolution, preserving shared inherited members. yii\apidoc\helpers\MarkdownContext

Method Details

Hide inherited methods

create() public static method

Returns an independent context for link resolution, preserving shared inherited members.

The supplied context must have its cross-references resolved before copying.

public static yii\apidoc\models\Context create ( yii\apidoc\models\Context $context )
$context yii\apidoc\models\Context

                public static function create(Context $context): Context
{
    $result = new Context();
    $subjects = new SplObjectStorage();
    foreach (['classes', 'interfaces', 'traits'] as $category) {
        foreach ($context->$category as $name => $type) {
            $class = $type::class;
            $copy = new $class();
            $copy->name = $type->name;
            $copy->namespace = $type->namespace;
            $copy->phpDocContext = $type->phpDocContext;
            $copy->sourceFile = $type->sourceFile;
            if ($type instanceof ClassDoc) {
                $copy->parentClass = $type->parentClass;
                $copy->interfaces = $type->interfaces;
                $copy->traits = $type->traits;
            } elseif ($type instanceof InterfaceDoc) {
                $copy->parentInterfaces = $type->parentInterfaces;
            }
            $result->{$category}[$name] = $copy;
        }
    }
    foreach (['classes', 'interfaces', 'traits'] as $category) {
        foreach ($context->$category as $name => $type) {
            $copy = $result->{$category}[$name];
            foreach (['methods', 'properties', 'constants', 'events'] as $members) {
                if (!property_exists($type, $members)) {
                    continue;
                }
                foreach ($type->$members as $memberName => $member) {
                    // Inherited members are shared by many types. Keep that sharing in the cache.
                    if (!isset($subjects[$member])) {
                        $memberClass = $member::class;
                        $parent = $result->getType($member->definedBy);
                        $subject = new $memberClass($parent ?? $copy);
                        $subject->name = $member->name;
                        $subject->definedBy = $member->definedBy;
                        $subjects[$member] = $subject;
                    }
                    $copy->{$members}[$memberName] = $subjects[$member];
                }
            }
        }
    }
    return $result;
}