Carsten Brandt
11 years ago
25 changed files with 1171 additions and 0 deletions
@ -0,0 +1,7 @@
|
||||
Yii Framework 2 phpdoc extension Change Log |
||||
=========================================== |
||||
|
||||
2.0.0 beta under development |
||||
---------------------------- |
||||
|
||||
- Initial release. |
@ -0,0 +1,32 @@
|
||||
The Yii framework is free software. It is released under the terms of |
||||
the following BSD License. |
||||
|
||||
Copyright © 2008 by Yii Software LLC (http://www.yiisoft.com) |
||||
All rights reserved. |
||||
|
||||
Redistribution and use in source and binary forms, with or without |
||||
modification, are permitted provided that the following conditions |
||||
are met: |
||||
|
||||
* Redistributions of source code must retain the above copyright |
||||
notice, this list of conditions and the following disclaimer. |
||||
* Redistributions in binary form must reproduce the above copyright |
||||
notice, this list of conditions and the following disclaimer in |
||||
the documentation and/or other materials provided with the |
||||
distribution. |
||||
* Neither the name of Yii Software LLC nor the names of its |
||||
contributors may be used to endorse or promote products derived |
||||
from this software without specific prior written permission. |
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
||||
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
||||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
||||
POSSIBILITY OF SUCH DAMAGE. |
@ -0,0 +1,28 @@
|
||||
API documentation generator for Yii 2 |
||||
===================================== |
||||
|
||||
This extension provides an API documentation generator for the Yii framework 2.0. |
||||
|
||||
Installation |
||||
------------ |
||||
|
||||
The preferred way to install this extension is through [composer](http://getcomposer.org/download/). |
||||
|
||||
Either run |
||||
|
||||
``` |
||||
php composer.phar require yiisoft/yii2-phpdoc "*" |
||||
``` |
||||
|
||||
or add |
||||
|
||||
```json |
||||
"yiisoft/yii2-phpdoc": "*" |
||||
``` |
||||
|
||||
to the require section of your composer.json. |
||||
|
||||
Usage |
||||
----- |
||||
|
||||
TDB |
@ -0,0 +1,105 @@
|
||||
pre { |
||||
color: #000000; |
||||
background-color: #FFF5E6; |
||||
font-family: "courier new", "times new roman", monospace; |
||||
line-height: 1.3em; |
||||
/* Put a nice border around it. */ |
||||
padding: 1px; |
||||
width: 90%; |
||||
/* Don't wrap its contents, and show scrollbars. */ |
||||
/* white-space: nowrap;*/ |
||||
overflow: auto; |
||||
/* Stop after about 24 lines, and just show a scrollbar. */ |
||||
/* max-height: 24em; */ |
||||
margin: 5px; |
||||
padding-left: 20px; |
||||
border: 1px solid #FFE6BF; |
||||
border-left: 6px solid #FFE6BF; |
||||
} |
||||
|
||||
div.code { |
||||
display: none; |
||||
color: #000000; |
||||
background-color: #FFF5E6; |
||||
font-family: "courier new", "times new roman", monospace; |
||||
line-height: 1.3em; |
||||
/* Put a nice border around it. */ |
||||
padding: 1px; |
||||
width: 90%; |
||||
/* Don't wrap its contents, and show scrollbars. */ |
||||
/* white-space: nowrap;*/ |
||||
overflow: auto; |
||||
/* Stop after about 24 lines, and just show a scrollbar. */ |
||||
/* max-height: 24em; */ |
||||
margin: 5px; |
||||
padding-left: 20px; |
||||
border-left: 6px solid #FFE6BF; |
||||
} |
||||
|
||||
table.summaryTable { |
||||
background: #E6ECFF; |
||||
border-collapse: collapse; |
||||
width: 100%; |
||||
} |
||||
|
||||
table.summaryTable th, table.summaryTable td { |
||||
border: 1px #BFCFFF solid; |
||||
padding: 0.2em; |
||||
} |
||||
|
||||
table.summaryTable th { |
||||
background: #CCD9FF; |
||||
text-align: left; |
||||
} |
||||
|
||||
#nav { |
||||
padding: 3px; |
||||
margin: 0 0 10px 0; |
||||
border-top: 1px #BFCFFF solid; |
||||
} |
||||
|
||||
#classDescription { |
||||
padding: 5px; |
||||
margin: 10px 0 20px 0; |
||||
border-bottom: 1px solid #BFCFFF; |
||||
} |
||||
|
||||
.detailHeader { |
||||
font-weight: bold; |
||||
font-size: 12pt; |
||||
margin: 30px 0 5px 0; |
||||
border-bottom: 1px solid #BFCFFF; |
||||
} |
||||
|
||||
.detailHeaderTag { |
||||
font-weight: normal; |
||||
font-size: 10pt; |
||||
} |
||||
|
||||
.signature, .signature2 { |
||||
padding: 3px; |
||||
color: #000000; |
||||
font-family: "courier new", "times new roman", monospace; |
||||
line-height: 1.3em; |
||||
} |
||||
|
||||
.signature { |
||||
margin: 10px 0 10px 0; |
||||
background: #E6ECFF; |
||||
border: 1px #BFCFFF solid; |
||||
} |
||||
|
||||
.paramNameCol { |
||||
width: 12%; |
||||
font-weight: bold; |
||||
} |
||||
|
||||
.paramTypeCol { |
||||
width: 12%; |
||||
} |
||||
|
||||
.sourceCode { |
||||
margin: 5px 0; |
||||
padding:5px; |
||||
background:#FFF5E6; |
||||
} |
@ -0,0 +1,32 @@
|
||||
body |
||||
{ |
||||
} |
||||
|
||||
body, div, span, p, input |
||||
{ |
||||
font-family: Verdana, sans-serif, Arial; |
||||
font-size: 10pt; |
||||
color: #333333; |
||||
} |
||||
|
||||
#apiPage { |
||||
} |
||||
|
||||
#apiHeader { |
||||
padding: 3px; |
||||
color: white; |
||||
background: #6078BF; |
||||
margin-bottom: 5px; |
||||
font-weight: bold; |
||||
} |
||||
|
||||
#apiHeader a { |
||||
color: white; |
||||
} |
||||
|
||||
#apiFooter { |
||||
margin-top: 5px; |
||||
padding: 3px; |
||||
border-top: 1px solid #BFCFFF; |
||||
text-align: center; |
||||
} |
@ -0,0 +1,89 @@
|
||||
<?php |
||||
/** |
||||
* @link http://www.yiiframework.com/ |
||||
* @copyright Copyright (c) 2008 Yii Software LLC |
||||
* @license http://www.yiiframework.com/license/ |
||||
*/ |
||||
|
||||
namespace yii\phpdoc\commands; |
||||
|
||||
use phpDocumentor\Reflection\FileReflector; |
||||
use yii\console\Controller; |
||||
use yii\helpers\Console; |
||||
use yii\helpers\FileHelper; |
||||
use yii\phpdoc\components\OfflineRenderer; |
||||
use yii\phpdoc\models\Context; |
||||
use Yii; |
||||
|
||||
/** |
||||
* |
||||
* @author Carsten Brandt <mail@cebe.cc> |
||||
* @author Qiang Xue <qiang.xue@gmail.com> |
||||
* @since 2.0 |
||||
*/ |
||||
class PhpdocController extends Controller |
||||
{ |
||||
public function actionIndex($targetDir) |
||||
{ |
||||
echo "hi\n"; |
||||
|
||||
$targetDir = Yii::getAlias($targetDir); |
||||
if (is_dir($targetDir) && !$this->confirm('TargetDirectory already exists. Overwrite?')) { |
||||
return 2; |
||||
} |
||||
|
||||
// TODO determine files to analyze |
||||
$this->stdout('Searching files to process... '); |
||||
$files = $this->findFiles(YII_PATH); |
||||
// $files = array_slice($files, 0, 42); // TODO remove this line |
||||
$this->stdout('done.' . PHP_EOL, Console::FG_GREEN); |
||||
|
||||
$fileCount = count($files); |
||||
Console::startProgress(0, $fileCount, 'Processing files... ', false); |
||||
$context = new Context(); |
||||
$done = 0; |
||||
foreach($files as $file) { |
||||
$context->addFile($file); |
||||
Console::updateProgress(++$done, $fileCount); |
||||
} |
||||
Console::endProgress(true); |
||||
$this->stdout('done.' . PHP_EOL, Console::FG_GREEN); |
||||
|
||||
$this->stdout('Updating cross references and backlinks... '); |
||||
$context->updateReferences(); |
||||
$this->stdout('done.' . PHP_EOL, Console::FG_GREEN); |
||||
|
||||
|
||||
// TODO LATER analyze for dead links and similar stuff |
||||
|
||||
// TODO render models |
||||
$renderer = new OfflineRenderer(); |
||||
$renderer->targetDir = $targetDir; |
||||
$renderer->render($context, $this); |
||||
} |
||||
|
||||
|
||||
protected function findFiles($path, $except = []) |
||||
{ |
||||
$path = FileHelper::normalizePath($path); |
||||
$options = [ |
||||
'filter' => function ($path) { |
||||
if (is_file($path)) { |
||||
$file = basename($path); |
||||
if ($file[0] < 'A' || $file[0] > 'Z') { |
||||
return false; |
||||
} |
||||
} |
||||
return null; |
||||
}, |
||||
'only' => ['.php'], |
||||
'except' => array_merge($except, [ |
||||
'/views/', |
||||
'/requirements/', |
||||
'/gii/generators/', |
||||
]), |
||||
]; |
||||
return FileHelper::findFiles($path, $options); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,38 @@
|
||||
<?php |
||||
/** |
||||
* |
||||
* |
||||
* @author Carsten Brandt <mail@cebe.cc> |
||||
*/ |
||||
|
||||
namespace yii\phpdoc\components; |
||||
|
||||
|
||||
use Yii; |
||||
use yii\base\Component; |
||||
use yii\console\Controller; |
||||
use yii\phpdoc\models\Context; |
||||
use yii\web\View; |
||||
|
||||
abstract class BaseRenderer extends Component |
||||
{ |
||||
|
||||
private $_view; |
||||
|
||||
|
||||
public function getView() |
||||
{ |
||||
if ($this->_view === null) { |
||||
$this->_view = new View(); |
||||
} |
||||
return $this->_view; |
||||
} |
||||
|
||||
/** |
||||
* @param Context $context |
||||
* @param Controller $controller |
||||
* @return mixed |
||||
*/ |
||||
public abstract function render($context, $controller); |
||||
|
||||
} |
@ -0,0 +1,182 @@
|
||||
<?php |
||||
/** |
||||
* |
||||
* |
||||
* @author Carsten Brandt <mail@cebe.cc> |
||||
*/ |
||||
|
||||
namespace yii\phpdoc\components; |
||||
|
||||
|
||||
use yii\base\ViewContextInterface; |
||||
use yii\console\Controller; |
||||
use yii\helpers\Console; |
||||
use yii\helpers\FileHelper; |
||||
use yii\helpers\Html; |
||||
use yii\phpdoc\models\ClassDoc; |
||||
use yii\phpdoc\models\Context; |
||||
use Yii; |
||||
use yii\phpdoc\models\InterfaceDoc; |
||||
use yii\phpdoc\models\TraitDoc; |
||||
|
||||
class OfflineRenderer extends BaseRenderer implements ViewContextInterface |
||||
{ |
||||
public $targetDir; |
||||
|
||||
public $layout = '@yii/phpdoc/views/layouts/offline.php'; |
||||
public $itemView = '@yii/phpdoc/views/class.php'; |
||||
public $indexView = '@yii/phpdoc/views/index.php'; |
||||
|
||||
public $pageTitle = 'Yii Framework 2.0 API Documentation'; |
||||
|
||||
/** |
||||
* @var Context |
||||
*/ |
||||
protected $context; |
||||
|
||||
/** |
||||
* @param Context $context |
||||
* @param Controller $controller |
||||
*/ |
||||
public function render($context, $controller) |
||||
{ |
||||
$this->context = $context; |
||||
$dir = Yii::getAlias($this->targetDir); |
||||
if (!is_dir($dir)) { |
||||
mkdir($dir); |
||||
} |
||||
|
||||
$items = array_merge($context->classes, $context->interfaces, $context->traits); |
||||
$itemCount = count($items) + 1; |
||||
Console::startProgress(0, $itemCount, 'Rendering files: ', false); |
||||
$done = 0; |
||||
foreach($items as $item) { |
||||
$fileContent = $this->renderWithLayout($this->itemView, [ |
||||
'item' => $item, |
||||
'docContext' => $context, |
||||
]); |
||||
file_put_contents($dir . '/' . $this->generateFileName($item->name), $fileContent); |
||||
Console::updateProgress(++$done, $itemCount); |
||||
} |
||||
$indexFileContent = $this->renderWithLayout($this->indexView, [ |
||||
'docContext' => $context, |
||||
'items' => $items, |
||||
]); |
||||
file_put_contents($dir . '/index.html', $indexFileContent); |
||||
Console::updateProgress(++$done, $itemCount); |
||||
Console::endProgress(true); |
||||
$controller->stdout('done.' . PHP_EOL, Console::FG_GREEN); |
||||
|
||||
$controller->stdout('Copying asset files... '); |
||||
FileHelper::copyDirectory(__DIR__ . '/../assets/css', $dir . '/css'); |
||||
$controller->stdout('done.' . PHP_EOL, Console::FG_GREEN); |
||||
|
||||
} |
||||
|
||||
protected function renderWithLayout($viewFile, $params) |
||||
{ |
||||
$output = $this->getView()->render($viewFile, $params, $this); |
||||
if ($this->layout !== false) { |
||||
$params['content'] = $output; |
||||
return $this->getView()->renderFile($this->layout, $params, $this); |
||||
} else { |
||||
return $output; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* creates a link to an item |
||||
* @param ClassDoc|InterfaceDoc|TraitDoc $item |
||||
* @param string $title |
||||
* @return string |
||||
*/ |
||||
public function link($item, $title = null) |
||||
{ |
||||
if ($title === null) { |
||||
$title = $item->name; |
||||
} |
||||
return Html::a($title, null, ['href' => $this->generateFileName($item->name)]); |
||||
} |
||||
|
||||
/** |
||||
* @param ClassDoc $class |
||||
* @return string |
||||
*/ |
||||
public function renderInheritance($class) |
||||
{ |
||||
$parents[] = $this->link($class); |
||||
while ($class->parentClass !== null) { |
||||
if(isset($this->context->classes[$class->parentClass])) { |
||||
$class = $this->context->classes[$class->parentClass]; |
||||
$parents[] = $this->link($class); |
||||
} else { |
||||
$parents[] = $class->parentClass; // TODO link to php.net |
||||
break; |
||||
} |
||||
} |
||||
return implode(" »\n",$parents); |
||||
} |
||||
|
||||
/** |
||||
* @param ClassDoc $class |
||||
* @return string |
||||
*/ |
||||
public function renderImplements($class) |
||||
{ |
||||
$interfaces = []; |
||||
foreach($class->interfaces as $interface) { |
||||
if(isset($this->context->interfaces[$interface])) { |
||||
$interfaces[] = $this->link($this->context->interfaces[$interface]); |
||||
} else { |
||||
$interfaces[] = $interface; // TODO link to php.net |
||||
} |
||||
} |
||||
return implode(', ',$interfaces); |
||||
} |
||||
|
||||
/** |
||||
* @param ClassDoc|TraitDoc $class |
||||
* @return string |
||||
*/ |
||||
public function renderTraitUses($class) |
||||
{ |
||||
$traits = []; |
||||
foreach($class->traits as $trait) { |
||||
if(isset($this->context->traits[$trait])) { |
||||
$traits[] = $this->link($this->context->traits[$trait]); |
||||
} else { |
||||
$traits[] = $trait; // TODO link to php.net |
||||
} |
||||
} |
||||
return implode(', ',$traits); |
||||
} |
||||
|
||||
public function renderSubclasses($class) |
||||
{ |
||||
$subclasses = []; |
||||
foreach($class->subclasses as $subclass) { |
||||
if(isset($this->context->classes[$subclass])) { |
||||
$subclasses[] = $this->link($this->context->classes[$subclass]); |
||||
} else { |
||||
$subclasses[] = $subclass; // TODO link to php.net |
||||
} |
||||
} |
||||
return implode(', ',$subclasses); |
||||
} |
||||
|
||||
|
||||
public function generateFileName($itemName) |
||||
{ |
||||
return strtolower(str_replace('\\', '_', $itemName)) . '.html'; |
||||
} |
||||
|
||||
/** |
||||
* Finds the view file corresponding to the specified relative view name. |
||||
* @param string $view a relative view name. The name does NOT start with a slash. |
||||
* @return string the view file path. Note that the file may not exist. |
||||
*/ |
||||
public function findViewFile($view) |
||||
{ |
||||
return Yii::getAlias('@yii/phpdoc/views/' . $view); |
||||
} |
||||
} |
@ -0,0 +1,29 @@
|
||||
{ |
||||
"name": "yiisoft/yii2-phpdoc", |
||||
"description": "PHP Documentation generator for the Yii framework 2.0", |
||||
"keywords": ["yii", "phpdoc", "api", "documentation"], |
||||
"type": "yii2-extension", |
||||
"license": "BSD-3-Clause", |
||||
"support": { |
||||
"issues": "https://github.com/yiisoft/yii2/issues?labels=ext%3Aredis", |
||||
"forum": "http://www.yiiframework.com/forum/", |
||||
"wiki": "http://www.yiiframework.com/wiki/", |
||||
"irc": "irc://irc.freenode.net/yii", |
||||
"source": "https://github.com/yiisoft/yii2" |
||||
}, |
||||
"authors": [ |
||||
{ |
||||
"name": "Carsten Brandt", |
||||
"email": "mail@cebe.cc" |
||||
} |
||||
], |
||||
"minimum-stability": "dev", |
||||
"require": { |
||||
"yiisoft/yii2": "*", |
||||
"phpdocumentor/reflection": "1.0.2" |
||||
}, |
||||
"autoload": { |
||||
"psr-0": { "yii\\redis\\": "" } |
||||
}, |
||||
"target-dir": "yii/redis" |
||||
} |
@ -0,0 +1,40 @@
|
||||
<?php |
||||
|
||||
namespace yii\phpdoc\models; |
||||
|
||||
use yii\base\Object; |
||||
|
||||
class BaseDoc extends Object |
||||
{ |
||||
public $name; |
||||
|
||||
public $since; |
||||
|
||||
public $shortDescription; |
||||
public $description; |
||||
|
||||
public $sourceFile; |
||||
public $startLine; |
||||
public $endLine; |
||||
|
||||
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)); |
||||
} |
||||
} |
@ -0,0 +1,75 @@
|
||||
<?php |
||||
|
||||
namespace yii\phpdoc\models; |
||||
|
||||
/** |
||||
* Class ClassDoc |
||||
*/ |
||||
class ClassDoc extends BaseDoc |
||||
{ |
||||
public $parentClass; |
||||
|
||||
public $isAbstract; |
||||
public $isFinal; |
||||
|
||||
public $interfaces = []; |
||||
public $traits = []; |
||||
|
||||
public $properties = []; |
||||
public $methods = []; |
||||
public $events = []; |
||||
public $constants = []; |
||||
|
||||
// public $protectedPropertyCount=0; |
||||
// public $publicPropertyCount=0; |
||||
// public $protectedMethodCount=0; |
||||
// public $publicMethodCount=0; |
||||
// |
||||
// public $nativePropertyCount=0; |
||||
// public $nativeMethodCount=0; |
||||
// public $nativeEventCount=0; |
||||
|
||||
public $sinceVersion; |
||||
|
||||
public $subclasses = []; |
||||
|
||||
|
||||
/** |
||||
* @param \phpDocumentor\Reflection\ClassReflector $reflector |
||||
* @param Context $context |
||||
* @param array $config |
||||
*/ |
||||
public function __construct($reflector, $context = null, $config = []) |
||||
{ |
||||
// base properties |
||||
$this->name = ltrim($reflector->getName(), '\\'); |
||||
$this->startLine = $reflector->getNode()->getAttribute('startLine'); |
||||
$this->endLine = $reflector->getNode()->getAttribute('endLine'); |
||||
|
||||
$this->parentClass = ltrim($reflector->getParentClass(), '\\'); |
||||
if (empty($this->parentClass)) { |
||||
$this->parentClass = null; |
||||
} |
||||
$this->isAbstract = $reflector->isAbstract(); |
||||
$this->isFinal = $reflector->isFinal(); |
||||
|
||||
foreach($reflector->getInterfaces() as $interface) { |
||||
$this->interfaces[] = ltrim($interface, '\\'); |
||||
} |
||||
foreach($reflector->getTraits() as $trait) { |
||||
$this->traits[] = ltrim($trait, '\\'); |
||||
} |
||||
|
||||
// TODO methods |
||||
|
||||
// TODO properties |
||||
|
||||
// TODO docblock |
||||
|
||||
if ($context !== null) { |
||||
$context->addClass($this); |
||||
} |
||||
|
||||
parent::__construct($config); |
||||
} |
||||
} |
@ -0,0 +1,93 @@
|
||||
<?php |
||||
/** |
||||
* |
||||
* |
||||
* @author Carsten Brandt <mail@cebe.cc> |
||||
*/ |
||||
|
||||
namespace yii\phpdoc\models; |
||||
|
||||
|
||||
use yii\base\Component; |
||||
use yii\base\Exception; |
||||
|
||||
class Context extends Component |
||||
{ |
||||
public $basePath; |
||||
|
||||
public $files = []; |
||||
|
||||
/** |
||||
* @var ClassDoc[] |
||||
*/ |
||||
public $classes = []; |
||||
/** |
||||
* @var InterfaceDoc[] |
||||
*/ |
||||
public $interfaces = []; |
||||
/** |
||||
* @var TraitDoc[] |
||||
*/ |
||||
public $traits = []; |
||||
|
||||
public function addFile($fileName) |
||||
{ |
||||
$file = new File($fileName, $this); |
||||
$this->files[$fileName] = $file; |
||||
} |
||||
|
||||
public function addClass($class) |
||||
{ |
||||
if (isset($this->classes[$class->name])) { |
||||
throw new Exception('Duplicate class definition: ' . $class->name . ' in file ' . $class->fileName); |
||||
} |
||||
$this->classes[$class->name] = $class; |
||||
} |
||||
|
||||
public function addInterface($interface) |
||||
{ |
||||
if (isset($this->interfaces[$interface->name])) { |
||||
throw new Exception('Duplicate interface definition: ' . $interface->name . ' in file ' . $interface->fileName); |
||||
} |
||||
$this->interfaces[$interface->name] = $interface; |
||||
} |
||||
|
||||
public function addTrait($trait) |
||||
{ |
||||
if (isset($this->traits[$trait->name])) { |
||||
throw new Exception('Duplicate trait definition: ' . $trait->name . ' in file ' . $trait->fileName); |
||||
} |
||||
$this->traits[$trait->name] = $trait; |
||||
} |
||||
|
||||
public function updateReferences() |
||||
{ |
||||
// update all subclass references |
||||
foreach($this->classes as $class) { |
||||
$className = $class->name; |
||||
while (isset($this->classes[$class->parentClass])) { |
||||
$class = $this->classes[$class->parentClass]; |
||||
$class->subclasses[] = $className; |
||||
} |
||||
} |
||||
// update interfaces of subclasses |
||||
foreach($this->classes as $class) { |
||||
$this->updateSubclassInferfacesTraits($class); |
||||
} |
||||
// TODO update interface and trait usages |
||||
} |
||||
|
||||
/** |
||||
* Add implemented interfaces and used traits to subclasses |
||||
* @param ClassDoc $class |
||||
*/ |
||||
protected function updateSubclassInferfacesTraits($class) |
||||
{ |
||||
foreach($class->subclasses as $subclass) { |
||||
$subclass = $this->classes[$subclass]; |
||||
$subclass->interfaces = array_unique(array_merge($subclass->interfaces, $class->interfaces)); |
||||
$subclass->traits = array_unique(array_merge($subclass->traits, $class->traits)); |
||||
$this->updateSubclassInferfacesTraits($subclass); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,10 @@
|
||||
<?php |
||||
|
||||
namespace yii\phpdoc\models; |
||||
|
||||
class EventDoc extends BaseDoc |
||||
{ |
||||
public $isInherited; |
||||
public $definedBy; |
||||
public $trigger; |
||||
} |
@ -0,0 +1,48 @@
|
||||
<?php |
||||
|
||||
namespace yii\phpdoc\models; |
||||
|
||||
use phpDocumentor\Reflection\FileReflector; |
||||
use yii\base\Object; |
||||
|
||||
class File extends Object |
||||
{ |
||||
public $name; |
||||
|
||||
public $namespaces = []; |
||||
/** |
||||
* @var ClassDoc[] |
||||
*/ |
||||
public $classes = []; |
||||
/** |
||||
* @var InterfaceDoc[] |
||||
*/ |
||||
public $interfaces = []; |
||||
/** |
||||
* @var TraitDoc[] |
||||
*/ |
||||
public $traits = []; |
||||
|
||||
private $_reflection; |
||||
|
||||
public function __construct($fileName, $context, $config = []) |
||||
{ |
||||
$this->name = $fileName; |
||||
$this->_reflection = new FileReflector($fileName, true); |
||||
$this->_reflection->process(); |
||||
|
||||
foreach($this->_reflection->getClasses() as $class) { |
||||
$class = new ClassDoc($class, $context); |
||||
$class->sourceFile = $fileName; |
||||
$this->classes[] = $class; |
||||
} |
||||
foreach($this->_reflection->getInterfaces() as $interface) { |
||||
$this->interfaces[] = new InterfaceDoc($interface, $context); |
||||
} |
||||
foreach($this->_reflection->getTraits() as $trait) { |
||||
$this->traits[] = new TraitDoc($trait, $context); |
||||
} |
||||
|
||||
parent::__construct($config); |
||||
} |
||||
} |
@ -0,0 +1,10 @@
|
||||
<?php |
||||
|
||||
namespace yii\phpdoc\models; |
||||
|
||||
class FunctionDoc extends BaseDoc |
||||
{ |
||||
public $signature; |
||||
public $input=array(); |
||||
public $output; |
||||
} |
@ -0,0 +1,45 @@
|
||||
<?php |
||||
/** |
||||
* |
||||
* |
||||
* @author Carsten Brandt <mail@cebe.cc> |
||||
*/ |
||||
|
||||
namespace yii\phpdoc\models; |
||||
|
||||
class InterfaceDoc extends BaseDoc |
||||
{ |
||||
public $parentInterfaces = []; |
||||
|
||||
public $implementedBy = []; |
||||
|
||||
public $methods = []; |
||||
|
||||
/** |
||||
* @param \phpDocumentor\Reflection\InterfaceReflector $reflector |
||||
* @param Context $context |
||||
* @param array $config |
||||
*/ |
||||
public function __construct($reflector, $context = null, $config = []) |
||||
{ |
||||
// base properties |
||||
$this->name = ltrim($reflector->getName(), '\\'); |
||||
$this->startLine = $reflector->getNode()->getAttribute('startLine'); |
||||
$this->endLine = $reflector->getNode()->getAttribute('endLine'); |
||||
|
||||
foreach($reflector->getParentInterfaces() as $interface) { |
||||
$this->parentInterfaces[] = ltrim($interface, '\\'); |
||||
} |
||||
|
||||
// TODO methods |
||||
|
||||
// TODO docblock |
||||
|
||||
if ($context !== null) { |
||||
$context->addInterface($this); |
||||
} |
||||
|
||||
parent::__construct($config); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,13 @@
|
||||
<?php |
||||
|
||||
namespace yii\phpdoc\models; |
||||
|
||||
class MethodDoc extends FunctionDoc |
||||
{ |
||||
public $isAbstract; |
||||
public $isFinal; |
||||
public $isProtected; |
||||
public $isStatic; |
||||
public $isInherited; |
||||
public $definedBy; |
||||
} |
@ -0,0 +1,18 @@
|
||||
<?php |
||||
/** |
||||
* |
||||
* |
||||
* @author Carsten Brandt <mail@cebe.cc> |
||||
*/ |
||||
|
||||
namespace yii\phpdoc\models; |
||||
|
||||
class ParamDoc |
||||
{ |
||||
public $name; |
||||
public $description; |
||||
public $type; |
||||
public $isOptional; |
||||
public $defaultValue; |
||||
public $isPassedByReference; |
||||
} |
@ -0,0 +1,23 @@
|
||||
<?php |
||||
/** |
||||
* |
||||
* |
||||
* @author Carsten Brandt <mail@cebe.cc> |
||||
*/ |
||||
|
||||
namespace yii\phpdoc\models; |
||||
|
||||
class PropertyDoc extends BaseDoc |
||||
{ |
||||
public $isProtected; |
||||
public $isStatic; |
||||
public $readOnly; |
||||
public $isInherited; |
||||
public $definedBy; |
||||
|
||||
public $type; |
||||
public $signature; |
||||
|
||||
public $getter; |
||||
public $setter; |
||||
} |
@ -0,0 +1,49 @@
|
||||
<?php |
||||
/** |
||||
* |
||||
* |
||||
* @author Carsten Brandt <mail@cebe.cc> |
||||
*/ |
||||
|
||||
namespace yii\phpdoc\models; |
||||
|
||||
class TraitDoc extends BaseDoc |
||||
{ |
||||
// classes using the trait |
||||
public $usedByClasses = []; |
||||
|
||||
public $traits = []; |
||||
|
||||
public $properties = []; |
||||
public $methods = []; |
||||
|
||||
|
||||
/** |
||||
* @param \phpDocumentor\Reflection\TraitReflector $reflector |
||||
* @param Context $context |
||||
* @param array $config |
||||
*/ |
||||
public function __construct($reflector, $context = null, $config = []) |
||||
{ |
||||
// base properties |
||||
$this->name = ltrim($reflector->getName(), '\\'); |
||||
$this->startLine = $reflector->getNode()->getAttribute('startLine'); |
||||
$this->endLine = $reflector->getNode()->getAttribute('endLine'); |
||||
|
||||
foreach($reflector->getTraits() as $trait) { |
||||
$this->traits[] = ltrim($trait, '\\'); |
||||
} |
||||
|
||||
// TODO methods |
||||
|
||||
// TODO properties |
||||
|
||||
// TODO docblock |
||||
|
||||
if ($context !== null) { |
||||
$context->addTrait($this); |
||||
} |
||||
|
||||
parent::__construct($config); |
||||
} |
||||
} |
@ -0,0 +1,49 @@
|
||||
<?php |
||||
|
||||
use yii\phpdoc\models\ClassDoc; |
||||
use yii\phpdoc\models\InterfaceDoc; |
||||
use yii\phpdoc\models\TraitDoc; |
||||
/** |
||||
* @var ClassDoc|InterfaceDoc|TraitDoc $item |
||||
* @var yii\web\View $this |
||||
*/ |
||||
|
||||
?> |
||||
<h1><?php |
||||
if ($item instanceof InterfaceDoc) { |
||||
echo 'Interface '; |
||||
} elseif ($item instanceof TraitDoc) { |
||||
echo 'Trait '; |
||||
} else { |
||||
echo 'Class '; |
||||
} |
||||
echo $item->name; |
||||
?></h1> |
||||
<div id="nav"> |
||||
<a href="index.html">All Classes</a> |
||||
<?php if(!($item instanceof InterfaceDoc) && !empty($item->properties)): ?> |
||||
| <a href="#properties">Properties</a> |
||||
<?php endif; ?> |
||||
<?php if(!empty($item->methods)): ?> |
||||
| <a href="#methods">Methods</a> |
||||
<?php endif; ?> |
||||
<?php if($item instanceof ClassDoc && !empty($item->events)): ?> |
||||
| <a href="#events">Events</a> |
||||
<?php endif; ?> |
||||
</div> |
||||
|
||||
<?= $this->render('classSummary', ['item' => $item]); ?> |
||||
|
||||
<a name="properties"></a> |
||||
<?php //$this->renderPartial('propertySummary',array('class'=>$item,'protected'=>false)); ?>
|
||||
<?php //$this->renderPartial('propertySummary',array('class'=>$item,'protected'=>true)); ?>
|
||||
|
||||
<a name="methods"></a> |
||||
<?php //$this->renderPartial('methodSummary',array('class'=>$item,'protected'=>false)); ?>
|
||||
<?php //$this->renderPartial('methodSummary',array('class'=>$item,'protected'=>true)); ?>
|
||||
|
||||
<a name="events"></a> |
||||
<?php //$this->renderPartial('eventSummary',array('class'=>$item)); ?>
|
||||
|
||||
<?php //$this->renderPartial('propertyDetails',array('class'=>$item)); ?>
|
||||
<?php //$this->renderPartial('methodDetails',array('class'=>$item)); ?>
|
@ -0,0 +1,60 @@
|
||||
<?php |
||||
|
||||
use yii\phpdoc\models\ClassDoc; |
||||
use yii\phpdoc\models\InterfaceDoc; |
||||
use yii\phpdoc\models\TraitDoc; |
||||
/** |
||||
* @var ClassDoc|InterfaceDoc|TraitDoc $item |
||||
* @var yii\web\View $this |
||||
*/ |
||||
|
||||
?><table class="summaryTable docClass"> |
||||
<colgroup> |
||||
<col class="col-name" /> |
||||
<col class="col-value" /> |
||||
</colgroup> |
||||
<?php if ($item instanceof ClassDoc): ?> |
||||
<tr> |
||||
<th>Inheritance</th> |
||||
<td><?php echo $this->context->renderInheritance($item); ?></td>
|
||||
</tr> |
||||
<?php endif; ?> |
||||
<?php if(!empty($item->interfaces)): ?> |
||||
<tr> |
||||
<th>Implements</th> |
||||
<td><?php echo $this->context->renderImplements($item); ?></td>
|
||||
</tr> |
||||
<?php endif; ?> |
||||
<?php if(!($item instanceof InterfaceDoc) && !empty($item->traits)): ?> |
||||
<tr> |
||||
<th>Uses Traits</th> |
||||
<td><?php echo $this->context->renderTraitUses($item); ?></td>
|
||||
</tr> |
||||
<?php endif; ?> |
||||
<?php if($item instanceof ClassDoc && !empty($item->subclasses)): ?> |
||||
<tr> |
||||
<th>Subclasses</th> |
||||
<td><?php echo $this->context->renderSubclasses($item); ?></td>
|
||||
</tr> |
||||
<?php endif; ?> |
||||
<?php if(!empty($item->since)): ?> |
||||
<tr> |
||||
<th>Since</th> |
||||
<td><?php echo $item->since; ?></td>
|
||||
</tr> |
||||
<?php endif; ?> |
||||
<?php if(!empty($item->version)): ?> |
||||
<tr> |
||||
<th>Version</th> |
||||
<td><?php echo $item->version; ?></td>
|
||||
</tr> |
||||
<?php endif; ?> |
||||
<tr> |
||||
<th>Source Code</th> |
||||
<!-- <td>--><?php //echo $this->renderSourceLink($item->sourcePath); ?><!--</td>-->
|
||||
</tr> |
||||
</table> |
||||
|
||||
<div id="classDescription"> |
||||
<?php echo $item->description; ?> |
||||
</div> |
@ -0,0 +1,30 @@
|
||||
<?php |
||||
|
||||
use yii\phpdoc\models\ClassDoc; |
||||
use yii\phpdoc\models\InterfaceDoc; |
||||
use yii\phpdoc\models\TraitDoc; |
||||
/** |
||||
* @var ClassDoc[]|InterfaceDoc[]|TraitDoc[] $items |
||||
* @var yii\web\View $this |
||||
*/ |
||||
|
||||
?><h1>Class Reference</h1> |
||||
|
||||
<table class="summaryTable docIndex"> |
||||
<colgroup> |
||||
<col class="col-package" /> |
||||
<col class="col-class" /> |
||||
<col class="col-description" /> |
||||
</colgroup> |
||||
<tr> |
||||
<th>Class</th><th>Description</th> |
||||
</tr> |
||||
<?php |
||||
ksort($items); |
||||
foreach($items as $i=>$class): ?> |
||||
<tr> |
||||
<td><?php echo $this->context->link($class, $class->name); ?></td>
|
||||
<td><?php echo $class->shortDescription; ?></td>
|
||||
</tr> |
||||
<?php endforeach; ?> |
||||
</table> |
@ -0,0 +1,64 @@
|
||||
<?php |
||||
|
||||
/** |
||||
* @var yii\web\View $this |
||||
*/ |
||||
|
||||
$this->beginPage(); |
||||
?> |
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
||||
<head> |
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
||||
<meta name="language" content="en" /> |
||||
<link rel="stylesheet" type="text/css" href="css/style.css" /> |
||||
<link rel="stylesheet" type="text/css" href="css/api.css" /> |
||||
<script type="text/javascript" src="js/jquery.js"></script> |
||||
<?php $this->head(); ?> |
||||
<title><?php echo $this->context->pageTitle; ?></title>
|
||||
</head> |
||||
|
||||
<body> |
||||
<?php $this->beginBody(); ?> |
||||
<div id="apiPage"> |
||||
|
||||
<div id="apiHeader"> |
||||
<a href="http://www.yiiframework.com">Yii Framework</a> v<?php echo Yii::getVersion(); ?> Class Reference
|
||||
</div><!-- end of header --> |
||||
|
||||
<div id="content"> |
||||
<?php echo $content; ?> |
||||
</div><!-- end of content --> |
||||
|
||||
<div id="apiFooter"> |
||||
© 2008-2013 by <a href="http://www.yiisoft.com">Yii Software LLC</a><br/> |
||||
All Rights Reserved.<br/> |
||||
</div><!-- end of footer --> |
||||
|
||||
<script type="text/javascript"> |
||||
/*<![CDATA[*/ |
||||
$("a.toggle").toggle(function(){ |
||||
$(this).text($(this).text().replace(/Hide/,'Show')); |
||||
$(this).parents(".summary").find(".inherited").hide(); |
||||
},function(){ |
||||
$(this).text($(this).text().replace(/Show/,'Hide')); |
||||
$(this).parents(".summary").find(".inherited").show(); |
||||
}); |
||||
$(".sourceCode a.show").toggle(function(){ |
||||
$(this).text($(this).text().replace(/show/,'hide')); |
||||
$(this).parents(".sourceCode").find("div.code").show(); |
||||
},function(){ |
||||
$(this).text($(this).text().replace(/hide/,'show')); |
||||
$(this).parents(".sourceCode").find("div.code").hide(); |
||||
}); |
||||
$("a.sourceLink").click(function(){ |
||||
$(this).attr('target','_blank'); |
||||
}); |
||||
/*]]>*/ |
||||
</script> |
||||
|
||||
</div><!-- end of page --> |
||||
<?php $this->endBody(); ?> |
||||
</body> |
||||
</html> |
||||
<?php $this->endPage(); ?> |
Loading…
Reference in new issue