BaseDoc.php 1.35 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 14 15 16 17 18 19 20 21 22 23 24

use yii\base\Object;

class BaseDoc extends Object
{
	public $name;

	public $since;

	public $shortDescription;
	public $description;

	public $sourceFile;
	public $startLine;
	public $endLine;

25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
	/**
	 * @param \phpDocumentor\Reflection\BaseReflector $reflector
	 * @param array $config
	 */
	public function __construct($reflector, $config = [])
	{
		// base properties
		$this->name = ltrim($reflector->getName(), '\\');
		$this->startLine = $reflector->getNode()->getAttribute('startLine');
		$this->endLine = $reflector->getNode()->getAttribute('endLine');

		// TODO docblock

		parent::__construct($config);
	}


42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
	public function loadSource($reflection)
	{
		$this->sourcePath=str_replace('\\','/',str_replace(YII_PATH,'',$reflection->getFileName()));
		$this->startLine=$reflection->getStartLine();
		$this->endLine=$reflection->getEndLine();
	}

	public function getSourceUrl($baseUrl,$line=null)
	{
		if($line===null)
			return $baseUrl.$this->sourcePath;
		else
			return $baseUrl.$this->sourcePath.'#'.$line;
	}

	public function getSourceCode()
	{
		$lines=file(YII_PATH.$this->sourcePath);
		return implode("",array_slice($lines,$this->startLine-1,$this->endLine-$this->startLine+1));
	}
}