ClassDoc.php 1.94 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 12 13
 *
 * @author Carsten Brandt <mail@cebe.cc>
 * @since 2.0
14
 */
15
class ClassDoc extends TypeDoc
16 17 18 19 20 21 22 23
{
	public $parentClass;

	public $isAbstract;
	public $isFinal;

	public $interfaces = [];
	public $traits = [];
24 25
	// will be set by Context::updateReferences()
	public $subclasses = [];
26

27 28 29
	/**
	 * @var EventDoc[]
	 */
30
	public $events = [];
31 32 33
	/**
	 * @var ConstDoc[]
	 */
34 35 36
	public $constants = [];


37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
	/**
	 * @return EventDoc[]
	 */
	public function getNativeEvents()
	{
		$events = [];
		foreach($this->events as $name => $event) {
			if ($event->definedBy != $this->name) {
				continue;
			}
			$events[$name] = $event;
		}
		return $events;
	}

52 53 54 55
	/**
	 * @param \phpDocumentor\Reflection\ClassReflector $reflector
	 * @param array $config
	 */
56
	public function __construct($reflector = null, $config = [])
57
	{
58
		parent::__construct($reflector, $config);
59

60 61 62 63
		if ($reflector === null) {
			return;
		}

64 65 66 67 68 69 70 71 72 73 74 75 76
		$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, '\\');
		}
77
		foreach($reflector->getConstants() as $constantReflector) {
78 79
			$docblock = $constantReflector->getDocBlock();
			if ($docblock !== null && count($docblock->getTagsByName('event')) > 0) {
80 81
				$event = new EventDoc($constantReflector);
				$event->definedBy = $this->name;
82
				$this->events[$event->name] = $event;
83 84 85
			} else {
				$constant = new ConstDoc($constantReflector);
				$constant->definedBy = $this->name;
86
				$this->constants[$constant->name] = $constant;
87 88
			}
		}
89 90
	}
}