From 63e726234c4c1c5aa65f7cf0b4868d222827d7de Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Sun, 5 Jan 2014 03:19:02 +0100 Subject: [PATCH] early draft of api doc generator issue #62 --- extensions/yii/phpdoc/.gitignore | 2 + extensions/yii/phpdoc/CHANGELOG.md | 7 + extensions/yii/phpdoc/LICENSE.md | 32 ++++ extensions/yii/phpdoc/README.md | 28 ++++ extensions/yii/phpdoc/assets/css/api.css | 105 ++++++++++++ extensions/yii/phpdoc/assets/css/style.css | 32 ++++ .../yii/phpdoc/commands/PhpdocController.php | 89 ++++++++++ extensions/yii/phpdoc/components/BaseRenderer.php | 38 +++++ .../yii/phpdoc/components/OfflineRenderer.php | 182 +++++++++++++++++++++ extensions/yii/phpdoc/composer.json | 29 ++++ extensions/yii/phpdoc/models/BaseDoc.php | 40 +++++ extensions/yii/phpdoc/models/ClassDoc.php | 75 +++++++++ extensions/yii/phpdoc/models/Context.php | 93 +++++++++++ extensions/yii/phpdoc/models/EventDoc.php | 10 ++ extensions/yii/phpdoc/models/File.php | 48 ++++++ extensions/yii/phpdoc/models/FunctionDoc.php | 10 ++ extensions/yii/phpdoc/models/InterfaceDoc.php | 45 +++++ extensions/yii/phpdoc/models/MethodDoc.php | 13 ++ extensions/yii/phpdoc/models/ParamDoc.php | 18 ++ extensions/yii/phpdoc/models/PropertyDoc.php | 23 +++ extensions/yii/phpdoc/models/TraitDoc.php | 49 ++++++ extensions/yii/phpdoc/views/class.php | 49 ++++++ extensions/yii/phpdoc/views/classSummary.php | 60 +++++++ extensions/yii/phpdoc/views/index.php | 30 ++++ extensions/yii/phpdoc/views/layouts/offline.php | 64 ++++++++ 25 files changed, 1171 insertions(+) create mode 100644 extensions/yii/phpdoc/.gitignore create mode 100644 extensions/yii/phpdoc/CHANGELOG.md create mode 100644 extensions/yii/phpdoc/LICENSE.md create mode 100644 extensions/yii/phpdoc/README.md create mode 100644 extensions/yii/phpdoc/assets/css/api.css create mode 100644 extensions/yii/phpdoc/assets/css/style.css create mode 100644 extensions/yii/phpdoc/commands/PhpdocController.php create mode 100644 extensions/yii/phpdoc/components/BaseRenderer.php create mode 100644 extensions/yii/phpdoc/components/OfflineRenderer.php create mode 100644 extensions/yii/phpdoc/composer.json create mode 100644 extensions/yii/phpdoc/models/BaseDoc.php create mode 100644 extensions/yii/phpdoc/models/ClassDoc.php create mode 100644 extensions/yii/phpdoc/models/Context.php create mode 100644 extensions/yii/phpdoc/models/EventDoc.php create mode 100644 extensions/yii/phpdoc/models/File.php create mode 100644 extensions/yii/phpdoc/models/FunctionDoc.php create mode 100644 extensions/yii/phpdoc/models/InterfaceDoc.php create mode 100644 extensions/yii/phpdoc/models/MethodDoc.php create mode 100644 extensions/yii/phpdoc/models/ParamDoc.php create mode 100644 extensions/yii/phpdoc/models/PropertyDoc.php create mode 100644 extensions/yii/phpdoc/models/TraitDoc.php create mode 100644 extensions/yii/phpdoc/views/class.php create mode 100644 extensions/yii/phpdoc/views/classSummary.php create mode 100644 extensions/yii/phpdoc/views/index.php create mode 100644 extensions/yii/phpdoc/views/layouts/offline.php diff --git a/extensions/yii/phpdoc/.gitignore b/extensions/yii/phpdoc/.gitignore new file mode 100644 index 0000000..8b7ef35 --- /dev/null +++ b/extensions/yii/phpdoc/.gitignore @@ -0,0 +1,2 @@ +/vendor +composer.lock diff --git a/extensions/yii/phpdoc/CHANGELOG.md b/extensions/yii/phpdoc/CHANGELOG.md new file mode 100644 index 0000000..b029621 --- /dev/null +++ b/extensions/yii/phpdoc/CHANGELOG.md @@ -0,0 +1,7 @@ +Yii Framework 2 phpdoc extension Change Log +=========================================== + +2.0.0 beta under development +---------------------------- + +- Initial release. diff --git a/extensions/yii/phpdoc/LICENSE.md b/extensions/yii/phpdoc/LICENSE.md new file mode 100644 index 0000000..e98f03d --- /dev/null +++ b/extensions/yii/phpdoc/LICENSE.md @@ -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. diff --git a/extensions/yii/phpdoc/README.md b/extensions/yii/phpdoc/README.md new file mode 100644 index 0000000..f0c8087 --- /dev/null +++ b/extensions/yii/phpdoc/README.md @@ -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 \ No newline at end of file diff --git a/extensions/yii/phpdoc/assets/css/api.css b/extensions/yii/phpdoc/assets/css/api.css new file mode 100644 index 0000000..482c04f --- /dev/null +++ b/extensions/yii/phpdoc/assets/css/api.css @@ -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; +} \ No newline at end of file diff --git a/extensions/yii/phpdoc/assets/css/style.css b/extensions/yii/phpdoc/assets/css/style.css new file mode 100644 index 0000000..1ead51c --- /dev/null +++ b/extensions/yii/phpdoc/assets/css/style.css @@ -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; +} diff --git a/extensions/yii/phpdoc/commands/PhpdocController.php b/extensions/yii/phpdoc/commands/PhpdocController.php new file mode 100644 index 0000000..1bb3e32 --- /dev/null +++ b/extensions/yii/phpdoc/commands/PhpdocController.php @@ -0,0 +1,89 @@ + + * @author Qiang Xue + * @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); + } + +} \ No newline at end of file diff --git a/extensions/yii/phpdoc/components/BaseRenderer.php b/extensions/yii/phpdoc/components/BaseRenderer.php new file mode 100644 index 0000000..86e93b2 --- /dev/null +++ b/extensions/yii/phpdoc/components/BaseRenderer.php @@ -0,0 +1,38 @@ + + */ + +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); + +} \ No newline at end of file diff --git a/extensions/yii/phpdoc/components/OfflineRenderer.php b/extensions/yii/phpdoc/components/OfflineRenderer.php new file mode 100644 index 0000000..1d02de0 --- /dev/null +++ b/extensions/yii/phpdoc/components/OfflineRenderer.php @@ -0,0 +1,182 @@ + + */ + +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); + } +} \ No newline at end of file diff --git a/extensions/yii/phpdoc/composer.json b/extensions/yii/phpdoc/composer.json new file mode 100644 index 0000000..7fa2dde --- /dev/null +++ b/extensions/yii/phpdoc/composer.json @@ -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" +} diff --git a/extensions/yii/phpdoc/models/BaseDoc.php b/extensions/yii/phpdoc/models/BaseDoc.php new file mode 100644 index 0000000..cbdf270 --- /dev/null +++ b/extensions/yii/phpdoc/models/BaseDoc.php @@ -0,0 +1,40 @@ +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)); + } +} \ No newline at end of file diff --git a/extensions/yii/phpdoc/models/ClassDoc.php b/extensions/yii/phpdoc/models/ClassDoc.php new file mode 100644 index 0000000..dd51bb5 --- /dev/null +++ b/extensions/yii/phpdoc/models/ClassDoc.php @@ -0,0 +1,75 @@ +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); + } +} \ No newline at end of file diff --git a/extensions/yii/phpdoc/models/Context.php b/extensions/yii/phpdoc/models/Context.php new file mode 100644 index 0000000..78d455d --- /dev/null +++ b/extensions/yii/phpdoc/models/Context.php @@ -0,0 +1,93 @@ + + */ + +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); + } + } +} \ No newline at end of file diff --git a/extensions/yii/phpdoc/models/EventDoc.php b/extensions/yii/phpdoc/models/EventDoc.php new file mode 100644 index 0000000..2ce7ad1 --- /dev/null +++ b/extensions/yii/phpdoc/models/EventDoc.php @@ -0,0 +1,10 @@ +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); + } +} \ No newline at end of file diff --git a/extensions/yii/phpdoc/models/FunctionDoc.php b/extensions/yii/phpdoc/models/FunctionDoc.php new file mode 100644 index 0000000..add2a00 --- /dev/null +++ b/extensions/yii/phpdoc/models/FunctionDoc.php @@ -0,0 +1,10 @@ + + */ + +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); + } + +} \ No newline at end of file diff --git a/extensions/yii/phpdoc/models/MethodDoc.php b/extensions/yii/phpdoc/models/MethodDoc.php new file mode 100644 index 0000000..be29aea --- /dev/null +++ b/extensions/yii/phpdoc/models/MethodDoc.php @@ -0,0 +1,13 @@ + + */ + +namespace yii\phpdoc\models; + +class ParamDoc +{ + public $name; + public $description; + public $type; + public $isOptional; + public $defaultValue; + public $isPassedByReference; +} \ No newline at end of file diff --git a/extensions/yii/phpdoc/models/PropertyDoc.php b/extensions/yii/phpdoc/models/PropertyDoc.php new file mode 100644 index 0000000..8ac0287 --- /dev/null +++ b/extensions/yii/phpdoc/models/PropertyDoc.php @@ -0,0 +1,23 @@ + + */ + +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; +} \ No newline at end of file diff --git a/extensions/yii/phpdoc/models/TraitDoc.php b/extensions/yii/phpdoc/models/TraitDoc.php new file mode 100644 index 0000000..7fc6e5a --- /dev/null +++ b/extensions/yii/phpdoc/models/TraitDoc.php @@ -0,0 +1,49 @@ + + */ + +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); + } +} \ No newline at end of file diff --git a/extensions/yii/phpdoc/views/class.php b/extensions/yii/phpdoc/views/class.php new file mode 100644 index 0000000..0af8987 --- /dev/null +++ b/extensions/yii/phpdoc/views/class.php @@ -0,0 +1,49 @@ + +

name; +?>

+ + +render('classSummary', ['item' => $item]); ?> + + +renderPartial('propertySummary',array('class'=>$item,'protected'=>false)); ?> +renderPartial('propertySummary',array('class'=>$item,'protected'=>true)); ?> + + +renderPartial('methodSummary',array('class'=>$item,'protected'=>false)); ?> +renderPartial('methodSummary',array('class'=>$item,'protected'=>true)); ?> + + +renderPartial('eventSummary',array('class'=>$item)); ?> + +renderPartial('propertyDetails',array('class'=>$item)); ?> +renderPartial('methodDetails',array('class'=>$item)); ?> diff --git a/extensions/yii/phpdoc/views/classSummary.php b/extensions/yii/phpdoc/views/classSummary.php new file mode 100644 index 0000000..ca84167 --- /dev/null +++ b/extensions/yii/phpdoc/views/classSummary.php @@ -0,0 +1,60 @@ + ++ + + + + + + + + +interfaces)): ?> + + + + + +traits)): ?> + + + + + +subclasses)): ?> + + + + + +since)): ?> + + + + + +version)): ?> + + + + + + + +renderSourceLink($item->sourcePath); ?> + +
Inheritancecontext->renderInheritance($item); ?>
Implementscontext->renderImplements($item); ?>
Uses Traitscontext->renderTraitUses($item); ?>
Subclassescontext->renderSubclasses($item); ?>
Sincesince; ?>
Versionversion; ?>
Source Code
+ +
+description; ?> +
\ No newline at end of file diff --git a/extensions/yii/phpdoc/views/index.php b/extensions/yii/phpdoc/views/index.php new file mode 100644 index 0000000..1e81798 --- /dev/null +++ b/extensions/yii/phpdoc/views/index.php @@ -0,0 +1,30 @@ +

Class Reference

+ + ++ + + + + + + +$class): ?> + + + + + +
ClassDescription
context->link($class, $class->name); ?>shortDescription; ?>
diff --git a/extensions/yii/phpdoc/views/layouts/offline.php b/extensions/yii/phpdoc/views/layouts/offline.php new file mode 100644 index 0000000..809de75 --- /dev/null +++ b/extensions/yii/phpdoc/views/layouts/offline.php @@ -0,0 +1,64 @@ +beginPage(); +?> + + + + + + + + +head(); ?> +<?php echo $this->context->pageTitle; ?> + + + +beginBody(); ?> +
+ +
+Yii Framework v Class Reference +
+ +
+ +
+ +
+© 2008-2013 by Yii Software LLC
+All Rights Reserved.
+
+ + + +
+endBody(); ?> + + +endPage(); ?> \ No newline at end of file