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

8
namespace yii\apidoc\models;
9

10 11
use phpDocumentor\Reflection\DocBlock\Tag\VarTag;

12 13 14 15 16
/**
 *
 * @author Carsten Brandt <mail@cebe.cc>
 * @since 2.0
 */
17 18
class PropertyDoc extends BaseDoc
{
19
	public $visibility;
20 21 22
	public $isStatic;

	public $type;
23 24
	public $types;
	public $defaultValue;
25

26
	// will be set by creating class
27 28
	public $getter;
	public $setter;
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63

	// will be set by creating class
	public $definedBy;

	public function getIsReadOnly()
	{
		return $this->getter !== null && $this->setter === null;
	}

	public function getIsWriteOnly()
	{
		return $this->getter === null && $this->setter !== null;
	}

	/**
	 * @param \phpDocumentor\Reflection\ClassReflector\PropertyReflector $reflector
	 * @param array $config
	 */
	public function __construct($reflector = null, $config = [])
	{
		parent::__construct($reflector, $config);

		if ($reflector === null) {
			return;
		}

		$this->visibility = $reflector->getVisibility();
		$this->isStatic = $reflector->isStatic();

		$this->defaultValue = $reflector->getDefault();

		foreach($this->tags as $i => $tag) {
			if ($tag instanceof VarTag) {
				$this->type = $tag->getType();
				$this->types = $tag->getTypes();
64 65 66 67 68 69
				$this->description = ucfirst($tag->getDescription());
				if (($pos = strpos($this->description, '.')) !== false) {
					$this->shortDescription = substr($this->description, 0, $pos);
				} else {
					$this->shortDescription = $this->description;
				}
70 71 72
			}
		}
	}
73
}