diff --git a/extensions/yii/apidoc/components/OfflineRenderer.php b/extensions/yii/apidoc/components/OfflineRenderer.php
index 3f2df90..bb06141 100644
--- a/extensions/yii/apidoc/components/OfflineRenderer.php
+++ b/extensions/yii/apidoc/components/OfflineRenderer.php
@@ -8,10 +8,12 @@
namespace yii\apidoc\components;
+use yii\apidoc\models\BaseDoc;
use yii\apidoc\models\ConstDoc;
use yii\apidoc\models\EventDoc;
use yii\apidoc\models\MethodDoc;
use yii\apidoc\models\PropertyDoc;
+use yii\apidoc\models\TypeDoc;
use yii\base\ViewContextInterface;
use yii\console\Controller;
use yii\helpers\Console;
@@ -94,24 +96,36 @@ class OfflineRenderer extends BaseRenderer implements ViewContextInterface
* @param string $title
* @return string
*/
- public function typeLink($types, $title = null)
+ public function typeLink($types, $context = null)
{
if (!is_array($types)) {
$types = [$types];
}
$links = [];
foreach($types as $type) {
- if (!is_object($type) && ($t = $this->context->getType($type)) !== null) {
- $type = $t;
+ $postfix = '';
+ if (!is_object($type)) {
+ if (substr($type, -2, 2) == '[]') {
+ $postfix = '[]';
+ $type = substr($type, 0, -2);
+ }
+
+ if (($t = $this->context->getType(ltrim($type, '\\'))) !== null) {
+ $type = $t;
+ } elseif ($type[0] !== '\\' && ($t = $this->context->getType($this->resolveNamespace($context) . '\\' . ltrim($type, '\\'))) !== null) {
+ $type = $t;
+ } else {
+ ltrim($type, '\\');
+ }
}
if (!is_object($type)) {
$links[] = $type;
} else {
$links[] = Html::a(
- $title !== null ? $title : $type->name,
+ $type->name,
null,
['href' => $this->generateFileName($type->name)]
- );
+ ) . $postfix;
}
}
return implode('|', $links);
@@ -131,8 +145,35 @@ class OfflineRenderer extends BaseRenderer implements ViewContextInterface
if (($type = $this->context->getType($subject->definedBy)) === null) {
return $subject->name;
} else {
- return Html::a($title, null, ['href' => $this->generateFileName($type->name) . '#' . $subject->name . '-detail']);
+ $link = $this->generateFileName($type->name);
+ if ($subject instanceof MethodDoc) {
+ $link .= '#' . $subject->name . '()';
+ } else {
+ $link .= '#' . $subject->name;
+ }
+ $link .= '-detail';
+ return Html::a($title, null, ['href' => $link]);
+ }
+ }
+
+ /**
+ * @param BaseDoc $context
+ */
+ private function resolveNamespace($context)
+ {
+ if ($context === null) {
+ return '';
+ }
+ if ($context instanceof TypeDoc) {
+ return $context->namespace;
}
+ if ($context->hasProperty('definedBy')) {
+ $type = $this->context->getType($context);
+ if ($type !== null) {
+ return $type->namespace;
+ }
+ }
+ return '';
}
/**
@@ -208,6 +249,50 @@ class OfflineRenderer extends BaseRenderer implements ViewContextInterface
return implode(', ',$classes);
}
+ /**
+ * @param PropertyDoc $property
+ * @return string
+ */
+ public function renderPropertySignature($property)
+ {
+ return $this->typeLink($property->types) . ' ' . $property->name . ' = ' . ($property->defaultValue === null ? 'null' : $property->defaultValue);
+ // TODO
+ if(!empty($property->signature))
+ return $property->signature;
+ $sig='';
+ if(!empty($property->getter))
+ $sig=$property->getter->signature;
+ if(!empty($property->setter))
+ {
+ if($sig!=='')
+ $sig.='
';
+ $sig.=$property->setter->signature;
+ }
+ return $sig;
+ }
+
+ /**
+ * @param MethodDoc $method
+ * @return string
+ */
+ public function renderMethodSignature($method)
+ {
+ $params = [];
+ foreach($method->params as $param) {
+ $params[] = (empty($param->typeHint) ? '' : $param->typeHint . ' ')
+ . ($param->isPassedByReference ? '&' : '')
+ . $param->name
+ . ($param->isOptional ? ' = ' . $param->defaultValue : '');
+ }
+
+ //signature);
+
+ return ($method->isReturnByReference ? '&' : '')
+ . ($method->returnType === null ? 'void' : $this->typeLink($method->returnTypes))
+ . ' ' . $method->name . '( '
+ . implode(', ', $params)
+ . ' )';
+ }
public function generateFileName($typeName)
{
diff --git a/extensions/yii/apidoc/models/BaseDoc.php b/extensions/yii/apidoc/models/BaseDoc.php
index 6715015..d52011c 100644
--- a/extensions/yii/apidoc/models/BaseDoc.php
+++ b/extensions/yii/apidoc/models/BaseDoc.php
@@ -25,6 +25,9 @@ class BaseDoc extends Object
public $deprecatedSince;
public $deprecatedReason;
+ /**
+ * @var \phpDocumentor\Reflection\DocBlock\Tag[]
+ */
public $tags = [];
diff --git a/extensions/yii/apidoc/models/ClassDoc.php b/extensions/yii/apidoc/models/ClassDoc.php
index c0d27b5..82da1d5 100644
--- a/extensions/yii/apidoc/models/ClassDoc.php
+++ b/extensions/yii/apidoc/models/ClassDoc.php
@@ -33,13 +33,32 @@ class ClassDoc extends TypeDoc
/**
+ * @return EventDoc[]
+ */
+ public function getNativeEvents()
+ {
+ $events = [];
+ foreach($this->events as $name => $event) {
+ if ($event->definedBy != $this->name) {
+ continue;
+ }
+ $events[$name] = $event;
+ }
+ return $events;
+ }
+
+ /**
* @param \phpDocumentor\Reflection\ClassReflector $reflector
* @param array $config
*/
- public function __construct($reflector, $config = [])
+ public function __construct($reflector = null, $config = [])
{
parent::__construct($reflector, $config);
+ if ($reflector === null) {
+ return;
+ }
+
$this->parentClass = ltrim($reflector->getParentClass(), '\\');
if (empty($this->parentClass)) {
$this->parentClass = null;
@@ -54,7 +73,8 @@ class ClassDoc extends TypeDoc
$this->traits[] = ltrim($trait, '\\');
}
foreach($reflector->getConstants() as $constantReflector) {
- if (strncmp($constantReflector->getShortName(), 'EVENT_', 6) == 0) {
+ $docblock = $constantReflector->getDocBlock();
+ if ($docblock !== null && count($docblock->getTagsByName('event')) > 0) {
$event = new EventDoc($constantReflector);
$event->definedBy = $this->name;
$this->events[$event->name] = $event;
diff --git a/extensions/yii/apidoc/models/ConstDoc.php b/extensions/yii/apidoc/models/ConstDoc.php
index 5eb99a9..b1d3a93 100644
--- a/extensions/yii/apidoc/models/ConstDoc.php
+++ b/extensions/yii/apidoc/models/ConstDoc.php
@@ -10,4 +10,20 @@ namespace yii\apidoc\models;
class ConstDoc extends BaseDoc
{
public $definedBy;
+ public $value;
+
+ /**
+ * @param \phpDocumentor\Reflection\ClassReflector\ConstantReflector $reflector
+ * @param array $config
+ */
+ public function __construct($reflector = null, $config = [])
+ {
+ parent::__construct($reflector, $config);
+
+ if ($reflector === null) {
+ return;
+ }
+
+ $this->value = $reflector->getValue();
+ }
}
\ No newline at end of file
diff --git a/extensions/yii/apidoc/models/Context.php b/extensions/yii/apidoc/models/Context.php
index d16c41f..89bfcfd 100644
--- a/extensions/yii/apidoc/models/Context.php
+++ b/extensions/yii/apidoc/models/Context.php
@@ -34,6 +34,7 @@ class Context extends Component
public function getType($type)
{
+ $type = ltrim($type, '\\');
if (isset($this->classes[$type])) {
return $this->classes[$type];
} elseif (isset($this->interfaces[$type])) {
diff --git a/extensions/yii/apidoc/models/EventDoc.php b/extensions/yii/apidoc/models/EventDoc.php
index fbdc4d8..78aee19 100644
--- a/extensions/yii/apidoc/models/EventDoc.php
+++ b/extensions/yii/apidoc/models/EventDoc.php
@@ -7,6 +7,39 @@
namespace yii\apidoc\models;
+use phpDocumentor\Reflection\DocBlock\Tag\ParamTag;
+use phpDocumentor\Reflection\DocBlock\Tag\ReturnTag;
+
class EventDoc extends ConstDoc
{
+ public $type;
+ public $types;
+
+ /**
+ * @param \phpDocumentor\Reflection\ClassReflector\ConstantReflector $reflector
+ * @param array $config
+ */
+ public function __construct($reflector = null, $config = [])
+ {
+ parent::__construct($reflector, $config);
+
+ if ($reflector === null) {
+ return;
+ }
+
+ foreach($this->tags as $i => $tag) {
+ if ($tag->getName() == 'event') {
+ $eventTag = new ReturnTag('event', $tag->getContent(), $tag->getDocBlock(), $tag->getLocation());
+ $this->type = $eventTag->getType();
+ $this->types = $eventTag->getTypes();
+ $this->description = ucfirst($eventTag->getDescription());
+ if (($pos = strpos($this->description, '.')) !== false) {
+ $this->shortDescription = substr($this->description, 0, $pos);
+ } else {
+ $this->shortDescription = $this->description;
+ }
+ unset($this->tags[$i]);
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/extensions/yii/apidoc/models/FunctionDoc.php b/extensions/yii/apidoc/models/FunctionDoc.php
index d84fd01..30338a6 100644
--- a/extensions/yii/apidoc/models/FunctionDoc.php
+++ b/extensions/yii/apidoc/models/FunctionDoc.php
@@ -8,8 +8,10 @@
namespace yii\apidoc\models;
use phpDocumentor\Reflection\DocBlock\Tag\ParamTag;
+use phpDocumentor\Reflection\DocBlock\Tag\PropertyTag;
use phpDocumentor\Reflection\DocBlock\Tag\ReturnTag;
use phpDocumentor\Reflection\DocBlock\Tag\ThrowsTag;
+use yii\base\Exception;
class FunctionDoc extends BaseDoc
{
@@ -27,10 +29,14 @@ class FunctionDoc extends BaseDoc
* @param \phpDocumentor\Reflection\FunctionReflector $reflector
* @param array $config
*/
- public function __construct($reflector, $config = [])
+ public function __construct($reflector = null, $config = [])
{
parent::__construct($reflector, $config);
+ if ($reflector === null) {
+ return;
+ }
+
$this->isReturnByReference = $reflector->isByRef();
foreach($reflector->getArguments() as $arg) {
@@ -39,19 +45,24 @@ class FunctionDoc extends BaseDoc
}
foreach($this->tags as $i => $tag) {
- if ($tag instanceof ReturnTag) {
- $this->returnType = $tag->getType();
- $this->returnTypes = $tag->getTypes();
- $this->return = $tag->getDescription();
+ if ($tag instanceof ThrowsTag) {
+ $this->exceptions[$tag->getType()] = $tag->getDescription();
unset($this->tags[$i]);
+ } elseif ($tag instanceof PropertyTag) {
+ // TODO handle property tag
} elseif ($tag instanceof ParamTag) {
$paramName = $tag->getVariableName();
+ if (!isset($this->params[$paramName])) {
+ echo 'undefined parameter documented: ' . $paramName . ' in ' . $this->name . "\n"; // todo add this to a log file
+ }
$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();
+ } elseif ($tag instanceof ReturnTag) {
+ $this->returnType = $tag->getType();
+ $this->returnTypes = $tag->getTypes();
+ $this->return = $tag->getDescription();
unset($this->tags[$i]);
}
}
diff --git a/extensions/yii/apidoc/models/InterfaceDoc.php b/extensions/yii/apidoc/models/InterfaceDoc.php
index 8a99661..8aea744 100644
--- a/extensions/yii/apidoc/models/InterfaceDoc.php
+++ b/extensions/yii/apidoc/models/InterfaceDoc.php
@@ -18,10 +18,14 @@ class InterfaceDoc extends TypeDoc
* @param \phpDocumentor\Reflection\InterfaceReflector $reflector
* @param array $config
*/
- public function __construct($reflector, $config = [])
+ public function __construct($reflector = null, $config = [])
{
parent::__construct($reflector, $config);
+ if ($reflector === null) {
+ return;
+ }
+
foreach($reflector->getParentInterfaces() as $interface) {
$this->parentInterfaces[] = ltrim($interface, '\\');
}
diff --git a/extensions/yii/apidoc/models/MethodDoc.php b/extensions/yii/apidoc/models/MethodDoc.php
index 70d67ce..96ca5c3 100644
--- a/extensions/yii/apidoc/models/MethodDoc.php
+++ b/extensions/yii/apidoc/models/MethodDoc.php
@@ -23,10 +23,14 @@ class MethodDoc extends FunctionDoc
* @param \phpDocumentor\Reflection\ClassReflector\MethodReflector $reflector
* @param array $config
*/
- public function __construct($reflector, $config = [])
+ public function __construct($reflector = null, $config = [])
{
parent::__construct($reflector, $config);
+ if ($reflector === null) {
+ return;
+ }
+
$this->isAbstract = $reflector->isAbstract();
$this->isFinal = $reflector->isFinal();
$this->isStatic = $reflector->isStatic();
diff --git a/extensions/yii/apidoc/models/ParamDoc.php b/extensions/yii/apidoc/models/ParamDoc.php
index b5b664c..da5127b 100644
--- a/extensions/yii/apidoc/models/ParamDoc.php
+++ b/extensions/yii/apidoc/models/ParamDoc.php
@@ -26,14 +26,18 @@ class ParamDoc extends Object
* @param \phpDocumentor\Reflection\FunctionReflector\ArgumentReflector $reflector
* @param array $config
*/
- public function __construct($reflector, $config = [])
+ public function __construct($reflector = null, $config = [])
{
parent::__construct($config);
+ if ($reflector === null) {
+ return;
+ }
+
$this->name = $reflector->getName();
$this->typeHint = $reflector->getType();
$this->isOptional = $reflector->getDefault() !== null;
- $this->defaultValue = $reflector->getDefault(); // TODO what about null value?
+ $this->defaultValue = $reflector->getDefault();
$this->isPassedByReference = $reflector->isByRef();
}
}
\ No newline at end of file
diff --git a/extensions/yii/apidoc/models/PropertyDoc.php b/extensions/yii/apidoc/models/PropertyDoc.php
index 3a9b447..68fc414 100644
--- a/extensions/yii/apidoc/models/PropertyDoc.php
+++ b/extensions/yii/apidoc/models/PropertyDoc.php
@@ -56,8 +56,12 @@ class PropertyDoc extends BaseDoc
if ($tag instanceof VarTag) {
$this->type = $tag->getType();
$this->types = $tag->getTypes();
- $this->description = $tag->getDescription();
- // TODO set shortDescription
+ $this->description = ucfirst($tag->getDescription());
+ if (($pos = strpos($this->description, '.')) !== false) {
+ $this->shortDescription = substr($this->description, 0, $pos);
+ } else {
+ $this->shortDescription = $this->description;
+ }
}
}
}
diff --git a/extensions/yii/apidoc/models/TraitDoc.php b/extensions/yii/apidoc/models/TraitDoc.php
index 13ee9b9..347640a 100644
--- a/extensions/yii/apidoc/models/TraitDoc.php
+++ b/extensions/yii/apidoc/models/TraitDoc.php
@@ -19,10 +19,14 @@ class TraitDoc extends TypeDoc
* @param \phpDocumentor\Reflection\TraitReflector $reflector
* @param array $config
*/
- public function __construct($reflector, $config = [])
+ public function __construct($reflector = null, $config = [])
{
parent::__construct($reflector, $config);
+ if ($reflector === null) {
+ return;
+ }
+
foreach($reflector->getTraits() as $trait) {
$this->traits[] = ltrim($trait, '\\');
}
diff --git a/extensions/yii/apidoc/models/TypeDoc.php b/extensions/yii/apidoc/models/TypeDoc.php
index c2ccd33..d892a3d 100644
--- a/extensions/yii/apidoc/models/TypeDoc.php
+++ b/extensions/yii/apidoc/models/TypeDoc.php
@@ -9,6 +9,7 @@ namespace yii\apidoc\models;
use phpDocumentor\Reflection\DocBlock\Tag\AuthorTag;
use yii\base\Exception;
+use yii\helpers\StringHelper;
class TypeDoc extends BaseDoc
{
@@ -22,48 +23,95 @@ class TypeDoc extends BaseDoc
*/
public $properties = [];
+ public $namespace;
+ /**
+ * @return MethodDoc[]
+ */
+ public function getNativeMethods()
+ {
+ return $this->getFilteredMethods(null, $this->name);
+ }
+
+ /**
+ * @return MethodDoc[]
+ */
public function getPublicMethods()
{
return $this->getFilteredMethods('public');
}
+ /**
+ * @return MethodDoc[]
+ */
public function getProtectedMethods()
{
return $this->getFilteredMethods('protected');
}
- private function getFilteredMethods($visibility)
+ /**
+ * @param null $visibility
+ * @param null $definedBy
+ * @return MethodDoc[]
+ */
+ private function getFilteredMethods($visibility = null, $definedBy = null)
{
$methods = [];
foreach($this->methods as $name => $method) {
- if ($method->visibility == $visibility) {
- $methods[$name] = $method;
+ if ($visibility !== null && $method->visibility != $visibility) {
+ continue;
+ }
+ if ($definedBy !== null && $method->definedBy != $definedBy) {
+ continue;
}
+ $methods[$name] = $method;
}
return $methods;
}
+ /**
+ * @return PropertyDoc[]
+ */
+ public function getNativeProperties()
+ {
+ return $this->getFilteredProperties(null, $this->name);
+ }
+
+ /**
+ * @return PropertyDoc[]
+ */
public function getPublicProperties()
{
return $this->getFilteredProperties('public');
}
+ /**
+ * @return PropertyDoc[]
+ */
public function getProtectedProperties()
{
return $this->getFilteredProperties('protected');
}
- private function getFilteredProperties($visibility)
+ /**
+ * @param null $visibility
+ * @param null $definedBy
+ * @return PropertyDoc[]
+ */
+ private function getFilteredProperties($visibility = null, $definedBy = null)
{
if ($this->properties === null) {
return [];
}
$properties = [];
foreach($this->properties as $name => $property) {
- if ($property->visibility == $visibility) {
- $properties[$name] = $property;
+ if ($visibility !== null && $property->visibility != $visibility) {
+ continue;
+ }
+ if ($definedBy !== null && $property->definedBy != $definedBy) {
+ continue;
}
+ $properties[$name] = $property;
}
return $properties;
}
@@ -72,10 +120,12 @@ class TypeDoc extends BaseDoc
* @param \phpDocumentor\Reflection\InterfaceReflector $reflector
* @param array $config
*/
- public function __construct($reflector, $config = [])
+ public function __construct($reflector = null, $config = [])
{
parent::__construct($reflector, $config);
+ $this->namespace = StringHelper::basename($this->name);
+
if ($reflector === null) {
return;
}
diff --git a/extensions/yii/apidoc/views/constSummary.php b/extensions/yii/apidoc/views/constSummary.php
index abac8c4..63dbbfb 100644
--- a/extensions/yii/apidoc/views/constSummary.php
+++ b/extensions/yii/apidoc/views/constSummary.php
@@ -21,14 +21,15 @@ if (empty($type->constants)) {
description; ?>
+ + = $this->render('seeAlso', ['object' => $event]); ?> + + diff --git a/extensions/yii/apidoc/views/eventSummary.php b/extensions/yii/apidoc/views/eventSummary.php index 9493846..56cb0fa 100644 --- a/extensions/yii/apidoc/views/eventSummary.php +++ b/extensions/yii/apidoc/views/eventSummary.php @@ -21,13 +21,19 @@ if (empty($type->events)) {
+
+ = $this->context->renderMethodSignature($method) ?>
+
+ | ||
= $param->name ?> | += $this->context->typeLink($param->types) ?> | += $param->description ?> | +
= '{return}'; ?> | += $this->context->typeLink($method->returnTypes); ?> | += $method->return; ?> | +
= $method->shortDescription ?>
+= nl2br($method->description) ?>
+ + = $this->render('seeAlso', ['object' => $method]); ?> + + \ No newline at end of file diff --git a/extensions/yii/apidoc/views/methodSummary.php b/extensions/yii/apidoc/views/methodSummary.php index 19f3e61..e597d53 100644 --- a/extensions/yii/apidoc/views/methodSummary.php +++ b/extensions/yii/apidoc/views/methodSummary.php @@ -29,7 +29,7 @@ if ($protected && count($type->getProtectedMethods()) == 0 || !$protected && cou methods as $method): ?> visibility == 'protected' || !$protected && $method->visibility != 'protected'): ?> -= nl2br($property->description) ?>
+ + = $this->render('seeAlso', ['object' => $property]); ?> + + diff --git a/extensions/yii/apidoc/views/propertySummary.php b/extensions/yii/apidoc/views/propertySummary.php index 4b1e935..ae95850 100644 --- a/extensions/yii/apidoc/views/propertySummary.php +++ b/extensions/yii/apidoc/views/propertySummary.php @@ -1,10 +1,9 @@ tags as $tag) { + /** @var $tag phpDocumentor\Reflection\DocBlock\Tag\SeeTag */ + if (get_class($tag) == 'phpDocumentor\Reflection\DocBlock\Tag\SeeTag') { + $see[] = $tag->getReference(); + } +} +if (empty($see)) { + return; +} +?> +