Skip to content

Commit

Permalink
文档生成工具完善,增加todo list功能,优化API列表
Browse files Browse the repository at this point in the history
  • Loading branch information
breath-co2 committed Mar 26, 2013
1 parent 8f6c129 commit c5f3702
Show file tree
Hide file tree
Showing 12 changed files with 796 additions and 173 deletions.
13 changes: 13 additions & 0 deletions manual/bin/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ page_top = 60
# see http://www.php.net/manual/en/timezones.php
timezone = PRC

# PHP 文档路径
php_manual_base_url = http://cn.php.net/manual/zh/

# PHP 文档搜索URL,lang可设置语言,结尾pattern是搜索词
php_search_base_url = "http://cn.php.net/search.php?show=quickref&lang=zh&pattern="


# 菜单滚动底部响应高度
page_bottom = 100
Expand All @@ -41,6 +47,7 @@ api_include_code = 1
zh-cn[Upgrade] = 升级注意事项
zh-cn[Class List] = 类库参考
zh-cn[Change Log] = 修改日志
zh-cn[Bin Tools Readme] = 命令行工具说明
zh-cn[Back up] = 返回上一级
zh-cn[Overview] = 概览
zh-cn[Untitled Document] = 无标题文档
Expand All @@ -57,7 +64,13 @@ api_include_code = 1
zh-cn[Code Editor] = 代码修改者
zh-cn[Click Open] = 点击展开
zh-cn[Click Close] = 点击关闭
zh-cn[TODO Info] = TODO 内容
zh-cn[TODO List] = TODO 列表
zh-cn[File] = 文件
zh-cn[Type] = 类型
zh-cn[Line] = 行
zh-cn[Show Other NoPublic Items] = 显示其它非Public项目
zh-cn[Hide Other NoPublic Items] = 隐藏其它非Public项目
zh-cn[No Public Items] = 非Public项目
zh-cn[Show private or protected item.] = 显示私有或受保护的项目
zh-cn[Extend from the parent class methods and variables] = 继承自父类的方法和变量
160 changes: 118 additions & 42 deletions manual/bin/lib/docs.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,66 +46,56 @@ public static function parse($comment)

foreach ($comment as $i => $line)
{
// Remove all leading whitespace
$line = preg_replace('/^\s*\* ?/m', '', $line);

// Search this line for a tag
if (preg_match('/^@(\S+)(?:\s*(.+))?$/', $line, $matches))
{
// This is a tag line
unset($comment[$i]);

$name = $matches[1];
$text = isset($matches[2]) ? $matches[2] : '';

switch ($name)
if ($name=='throws')
{
case 'license' :
if (strpos($text, '://') !== false)
{
// Convert the lincense into a link
$text = HTML::anchor($text, null, array('target'=>'_blank', 'rel'=>"nofollow"));
}
break;
case 'link' :
$text = preg_split('/\s+/', $text, 2);
$text = HTML::anchor($text[0], isset($text[1]) ? $text[1] : $text[0]);
break;
case 'copyright' :
if (strpos($text, '(c)') !== false)
{
// Convert the copyright sign
$text = str_replace('(c)', '©', $text);
}
break;
case 'throws' :
if (preg_match('/^(\w+)\W(.*)$/', $text, $matches))
{
$text = HTML::anchor(self::url($matches[1]), $matches[1]) . ' ' . $matches[2];
}
else
{
$text = HTML::anchor(self::url($text), $text);
}
break;
case 'uses' :
if (preg_match('/^([a-z_]+)::([a-z_]+)$/i', $text, $matches))
if (preg_match('/^(\w+)\W(.*)$/', $text, $matches))
{
$class_name = $matches[1];
}
else
{
$class_name = $text;
}

$data = self::rf_tag_by_class($class_name);

if ($data)
{
$data['commit'] = $matches[2]?$matches[2]:'';
$data['text'] = $text;
$text = $data;
}
}
elseif ($name=='uses')
{
if (preg_match('/^([a-z0-9_]+)::(\$)?([a-z0-9_]+)$/i', $text, $matches))
{
$data = self::rf_tag_by_class($matches[1], $matches[3] , $matches[2]?true:false);
if ($data)
{
// Make a class#method API link
$text = HTML::anchor(self::url($matches[1]) . '#' . $matches[2], $text); //->uri(array('class' => $matches[1])).'#'.$matches[2], $text);
$data['text'] = $text;
$text = $data;
}
break;
// Don't show @access lines, they are shown elsewhere
case 'access' :
continue 2;
}
}
elseif ($name=='access')
{
continue;
}

// Add the tag
$tags[$name][] = $text;
}
else
{
// Overwrite the comment line
$comment[$i] = (string)$line;
}
}
Expand Down Expand Up @@ -496,6 +486,92 @@ protected static function _class2url(&$class)
return $dir;
}


/**
* 获取Tag分析需要用到的数据
*
* @param string $class_name
* @param string $f
* @param boolean $is_poperty
*/
protected static function rf_tag_by_class($class_name, $f = null, $is_poperty = false)
{
try
{
if (class_exists($class_name, true))
{
if ($f)
{
if ($is_poperty)
{
$rf = new _Docs_Property($class_name, $f);
}
else
{
$rf = new _Docs_Method($class_name, $f);
}
$data = $rf->getArrayCopy();

return array
(
'class_name' => $data['class_name'],
'f' => $f,
'is_php_class' => $data['is_php_class'],
);
}
else
{
$rf = new ReflectionClass($class_name);

$f = $rf->getFileName();
if (substr($f, -13)=='ev'.'al()\'d code' && !is_file($f))
{
$parent = $rf;
# 程序生成的代码
while ($parent = $parent->getParentClass())
{
if (substr(strtolower($parent->name), 0, 3)=='ex_')
{
# 扩展类或略
continue;
}

$rf2 = new ReflectionClass($parent->name);
$f = $rf2->getFileName();
if (substr($f, -13)!='ev'.'al()\'d code' && is_file($f))
{
return array
(
'class_name' => $rf2->name,
'is_php_class' => $rf2->getStartLine()?0:1,
);
}

unset($rf2);
}
}
else
{
return array
(
'class_name' => $rf->name,
'is_php_class' => $rf->getStartLine()?0:1,
);
}
}
}
else
{
return false;
}
}
catch (Exception $e)
{
return false;
}
}


public function getArrayCopy()
{
return $this->data;
Expand Down
14 changes: 13 additions & 1 deletion manual/bin/lib/docs_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,24 @@ public function __construct($class)
$parents = array();
while ($parent = $parent->getParentClass())
{
$parents[] = $parent->name;
if (substr(strtolower($parent->name), 0, 3)=='ex_')
{
# 扩展类或略
continue;
}

$rf = new ReflectionClass($parent->name);
$parents[] = array
(
'class_name' => $parent->name,
'is_php_class' => $rf->getStartLine()?0:1,
);
}
$this->data['parents'] = $parents;

$this->data['class_name'] = $this->class->getName();
$this->data['title'] = $description[0];
$this->data['is_php_class'] = $this->class->getStartLine()?0:1;
$this->data['description'] = trim(implode("\n", $description));
$this->data['properties'] = $this->properties();
$this->data['methods'] = $this->methods();
Expand Down
1 change: 1 addition & 0 deletions manual/bin/lib/docs_method.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public function __construct($class, $method)
unset($tags['return']);
}
$this->data['tags'] = $tags;
$this->data['is_php_class'] = $this->method->getStartLine()?0:1;
$this->data['start_line'] = $this->method->getStartLine();
$this->data['end_line'] = $this->method->getEndLine();
$this->data['file_name'] = $this->class->getFileName();
Expand Down
9 changes: 9 additions & 0 deletions manual/bin/lib/docs_roperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ public function __construct($class, $property)
$this->data['class_name'] = $property->class;
$this->data['is_static'] = $property->isStatic();
$this->data['is_public'] = $property->isPublic();
if ($property->class!=$class)
{
$rs = new ReflectionClass($property->class);
$this->data['is_php_class'] = $rs->getStartLine()?0:1;
}
else
{
$this->data['is_php_class'] = false;
}

if ($property->isStatic() && $property->isPublic())
{
Expand Down
Loading

0 comments on commit c5f3702

Please sign in to comment.