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

namespace yii\apidoc\models;

10 11 12 13
use phpDocumentor\Reflection\DocBlock\Tag\ParamTag;
use phpDocumentor\Reflection\DocBlock\Tag\ReturnTag;
use phpDocumentor\Reflection\DocBlock\Tag\ThrowsTag;

14 15
class FunctionDoc extends BaseDoc
{
16 17 18 19 20 21 22 23 24 25 26 27 28 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
	/**
	 * @var ParamDoc[]
	 */
	public $params = [];
	public $exceptions = [];
	public $return;
	public $returnType;
	public $returnTypes;
	public $isReturnByReference;

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

		$this->isReturnByReference = $reflector->isByRef();

		foreach($reflector->getArguments() as $arg) {
			$arg = new ParamDoc($arg);
			$this->params[$arg->name] = $arg;
		}

		foreach($this->tags as $i => $tag) {
			if ($tag instanceof ReturnTag) {
				$this->returnType = $tag->getType();
				$this->returnTypes = $tag->getTypes();
				$this->return = $tag->getDescription();
				unset($this->tags[$i]);
			} elseif ($tag instanceof ParamTag) {
				$paramName = $tag->getVariableName();
				$this->params[$paramName]->description = $tag->getDescription();
				$this->params[$paramName]->type = $tag->getType();
				$this->params[$paramName]->types = $tag->getTypes();
				unset($this->tags[$i]);
			} elseif ($tag instanceof ThrowsTag) {
				$this->exceptions[$tag->getType()] = $tag->getDescription();
				unset($this->tags[$i]);
			}
		}
	}
59
}