ClassDoc.php 2.52 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 21 22 23 24
{
	public $parentClass;

	public $isAbstract;
	public $isFinal;

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

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


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

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

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

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

89 90 91 92 93 94 95
		$this->parentClass = ltrim($reflector->getParentClass(), '\\');
		if (empty($this->parentClass)) {
			$this->parentClass = null;
		}
		$this->isAbstract = $reflector->isAbstract();
		$this->isFinal = $reflector->isFinal();

AlexGx committed
96
		foreach ($reflector->getInterfaces() as $interface) {
97 98
			$this->interfaces[] = ltrim($interface, '\\');
		}
AlexGx committed
99
		foreach ($reflector->getTraits() as $trait) {
100 101
			$this->traits[] = ltrim($trait, '\\');
		}
AlexGx committed
102
		foreach ($reflector->getConstants() as $constantReflector) {
103 104
			$docblock = $constantReflector->getDocBlock();
			if ($docblock !== null && count($docblock->getTagsByName('event')) > 0) {
105 106
				$event = new EventDoc($constantReflector);
				$event->definedBy = $this->name;
107
				$this->events[$event->name] = $event;
108 109 110
			} else {
				$constant = new ConstDoc($constantReflector);
				$constant->definedBy = $this->name;
111
				$this->constants[$constant->name] = $constant;
112 113
			}
		}
114
	}
AlexGx committed
115
}