Browse Source

short array syntax

tags/2.0.0-beta
Carsten Brandt 11 years ago
parent
commit
2245a7e36d
  1. 13
      extensions/yii/apidoc/helpers/Markdown.php
  2. 41
      extensions/yii/apidoc/helpers/PrettyPrinter.php
  3. 4
      extensions/yii/apidoc/models/Context.php
  4. 3
      extensions/yii/apidoc/models/FunctionDoc.php
  5. 7
      extensions/yii/apidoc/models/ParamDoc.php
  6. 6
      extensions/yii/apidoc/models/PropertyDoc.php

13
extensions/yii/apidoc/helpers/Markdown.php

@ -1,19 +1,22 @@
<?php
/**
*
*
* @author Carsten Brandt <mail@cebe.cc>
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\apidoc\helpers;
use phpDocumentor\Reflection\DocBlock\Type\Collection;
use yii\apidoc\models\MethodDoc;
use yii\apidoc\models\TypeDoc;
use yii\apidoc\templates\BaseRenderer;
use yii\helpers\Html;
/**
*
* @author Carsten Brandt <mail@cebe.cc>
* @since 2.0
*/
class Markdown extends \yii\helpers\Markdown
{
/**

41
extensions/yii/apidoc/helpers/PrettyPrinter.php

@ -0,0 +1,41 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\apidoc\helpers;
use PHPParser_Node_Expr;
use PHPParser_Node_Expr_Array;
/**
* Enhances the phpDocumentor PrettyPrinter with short array syntax
*
* @author Carsten Brandt <mail@cebe.cc>
* @since 2.0
*/
class PrettyPrinter extends \phpDocumentor\Reflection\PrettyPrinter
{
public function pExpr_Array(PHPParser_Node_Expr_Array $node)
{
return '[' . $this->pCommaSeparated($node->items) . ']';
}
/**
* Returns a simple human readable output for a value.
*
* @param PHPParser_Node_Expr $value The value node as provided by PHP-Parser.
* @return string
*/
public static function getRepresentationOfValue(PHPParser_Node_Expr $value)
{
if ($value === null) {
return '';
}
$printer = new static();
return $printer->prettyPrintExpr($value);
}
}

4
extensions/yii/apidoc/models/Context.php

@ -160,7 +160,7 @@ class Context extends Component
if (isset($class->properties[$propertyName])) {
$property = $class->properties[$propertyName];
if ($property->getter === null && $property->setter === null) {
echo "Property $propertyName conflicts with a defined getter {$method->name} in {$class->name}."; // TODO log these messages somewhere
echo "Property $propertyName conflicts with a defined getter {$method->name} in {$class->name}.\n"; // TODO log these messages somewhere
}
$property->getter = $method;
} else {
@ -184,7 +184,7 @@ class Context extends Component
if (isset($class->properties[$propertyName])) {
$property = $class->properties[$propertyName];
if ($property->getter === null && $property->setter === null) {
echo "Property $propertyName conflicts with a defined setter {$method->name} in {$class->name}."; // TODO log these messages somewhere
echo "Property $propertyName conflicts with a defined setter {$method->name} in {$class->name}.\n"; // TODO log these messages somewhere
}
$property->setter = $method;
} else {

3
extensions/yii/apidoc/models/FunctionDoc.php

@ -58,7 +58,8 @@ class FunctionDoc extends BaseDoc
} 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
echo 'undefined parameter documented: ' . $paramName . ' in ' . $this->name . "()\n"; // TODO log these messages somewhere
continue;
}
$this->params[$paramName]->description = ucfirst($tag->getDescription());
$this->params[$paramName]->type = $tag->getType();

7
extensions/yii/apidoc/models/ParamDoc.php

@ -7,6 +7,7 @@
namespace yii\apidoc\models;
use yii\apidoc\helpers\PrettyPrinter;
use yii\base\Object;
/**
@ -42,7 +43,11 @@ class ParamDoc extends Object
$this->name = $reflector->getName();
$this->typeHint = $reflector->getType();
$this->isOptional = $reflector->getDefault() !== null;
$this->defaultValue = $reflector->getDefault();
// bypass $reflector->getDefault() for short array syntax
if ($reflector->getNode()->default) {
$this->defaultValue = PrettyPrinter::getRepresentationOfValue($reflector->getNode()->default);
}
$this->isPassedByReference = $reflector->isByRef();
}
}

6
extensions/yii/apidoc/models/PropertyDoc.php

@ -8,6 +8,7 @@
namespace yii\apidoc\models;
use phpDocumentor\Reflection\DocBlock\Tag\VarTag;
use yii\apidoc\helpers\PrettyPrinter;
/**
*
@ -55,7 +56,10 @@ class PropertyDoc extends BaseDoc
$this->visibility = $reflector->getVisibility();
$this->isStatic = $reflector->isStatic();
$this->defaultValue = $reflector->getDefault();
// bypass $reflector->getDefault() for short array syntax
if ($reflector->getNode()->default) {
$this->defaultValue = PrettyPrinter::getRepresentationOfValue($reflector->getNode()->default);
}
foreach($this->tags as $i => $tag) {
if ($tag instanceof VarTag) {

Loading…
Cancel
Save