ClassDoc.php 3.01 KB
Newer Older
1
<?php
2 3 4 5 6
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */
7

8
namespace yii\apidoc\models;
9 10

/**
11
 * Represents API documentation information for a `class`.
12
 *
13 14
 * @property EventDoc[] $nativeEvents This property is read-only.
 *
15 16
 * @author Carsten Brandt <mail@cebe.cc>
 * @since 2.0
17
 */
18
class ClassDoc extends TypeDoc
19
{
20
    public $parentClass;
21

22 23
    public $isAbstract;
    public $isFinal;
24

25 26 27 28 29 30 31
    /**
     * @var string[]
     */
    public $interfaces = [];
    public $traits = [];
    // will be set by Context::updateReferences()
    public $subclasses = [];
32

33 34 35 36 37 38 39 40
    /**
     * @var EventDoc[]
     */
    public $events = [];
    /**
     * @var ConstDoc[]
     */
    public $constants = [];
41

42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
    public function findSubject($subjectName)
    {
        if (($subject = parent::findSubject($subjectName)) !== null) {
            return $subject;
        }
        foreach ($this->events as $name => $event) {
            if ($subjectName == $name) {
                return $event;
            }
        }
        foreach ($this->constants as $name => $constant) {
            if ($subjectName == $name) {
                return $constant;
            }
        }
57

58 59
        return null;
    }
60

61 62 63 64 65 66 67 68 69 70 71 72
    /**
     * @return EventDoc[]
     */
    public function getNativeEvents()
    {
        $events = [];
        foreach ($this->events as $name => $event) {
            if ($event->definedBy != $this->name) {
                continue;
            }
            $events[$name] = $event;
        }
73

74 75
        return $events;
    }
76

77 78
    /**
     * @param \phpDocumentor\Reflection\ClassReflector $reflector
79 80
     * @param Context $context
     * @param array $config
81 82 83 84
     */
    public function __construct($reflector = null, $context = null, $config = [])
    {
        parent::__construct($reflector, $context, $config);
85

86 87 88
        if ($reflector === null) {
            return;
        }
89

90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
        $this->parentClass = ltrim($reflector->getParentClass(), '\\');
        if (empty($this->parentClass)) {
            $this->parentClass = null;
        }
        $this->isAbstract = $reflector->isAbstract();
        $this->isFinal = $reflector->isFinal();

        foreach ($reflector->getInterfaces() as $interface) {
            $this->interfaces[] = ltrim($interface, '\\');
        }
        foreach ($reflector->getTraits() as $trait) {
            $this->traits[] = ltrim($trait, '\\');
        }
        foreach ($reflector->getConstants() as $constantReflector) {
            $docblock = $constantReflector->getDocBlock();
            if ($docblock !== null && count($docblock->getTagsByName('event')) > 0) {
                $event = new EventDoc($constantReflector);
                $event->definedBy = $this->name;
                $this->events[$event->name] = $event;
            } else {
                $constant = new ConstDoc($constantReflector);
                $constant->definedBy = $this->name;
                $this->constants[$constant->name] = $constant;
            }
        }
    }
AlexGx committed
116
}