日期:2014-04-17  浏览次数:20530 次

在项目开发中发现对php的文档缺少管理,别人写了一个,功能不多

<?php
/**
* 类名: doc
* 描述: 文档生成类
* 其他: 可以对目录进行过滤,设置好源目录后,请用绝对路径指定生成目录,模式可调,模式
* 1为常规类型,即以 斜线**开头,以*斜线 结束
* 2为扩展类型,凡是 斜线*开头以*斜线 结束的部分都将成为文档的一部分
*/
class doc
{
var $docdirname;
var $docdir;

/**
* 函数名称: doc()
* 函数功能: 构造
* 输入参数: none
* 函数返回值: 返回值说明
* 其它说明: 2004-10-13
*/
function doc()
{
$this->docdirname = "doc/";
}

/**
* 函数名称: createDoc($root,$newdir,$mode="1",$filter=null)
* 函数功能: 创建文档
* 输入参数: $root -------------- 源目录
$newdir ----------- 目标目录
$mode ------------- 模式,1为普通,2为扩展
$filter ------------ 过滤目录
* 函数返回值: 返回值说明
* 其它说明: 2004-10-13
*/
function createDoc($root,$newdir,$mode="1",$filter=null)
{
$getarr = $this->loopDir($root,$filter);
$i = 0;
$this->createFrame($newdir);
foreach($getarr as $key=>$val)
{
if($this->getPhpFiles($val))
{
$content = $this->getContent($val);
$content = $this->getDoc($content,$mode);
$filepath = $this->setFilepath($val,$root,$newdir);
$filedir = $this->getFileDir($filepath);
$this->mkdirs($filedir);
$this->setDoc($filepath,$content);
$data[$i]['url'] = "$filepath";
$data[$i]['name'] = "$val";
$i++;
}
}
if(!empty($data))
{
$this->createMenu($newdir,$data);
$this->redirect($this->docdir);
}
}

/**
* 函数名称: redirect($path)
* 函数功能: 转向
* 输入参数: $path ---------------- 转向路径
* 函数返回值: 返回值说明
* 其它说明: 2004-10-13
*/
function redirect($path)
{
echo "<a href=".$path." target='_blank'>生成文档成功,点击此处查看</a>";
}

/**
* 函数名称: loopDir($root,$filter=null)
* 函数功能: 遍历目录
* 输入参数: $root ------------------- 源目录
$filter ----------------- 过滤
* 函数返回值: array
* 其它说明: 2004-10-13
*/
function loopDir($root,$filter=null)
{
static $getarr=array();
$d = dir($root);
while (false !== ($entry = $d->read()))
{
if ($entry == "." || $entry == "..")
{
continue;
}
if($this->filter($entry,$filter))
{
if(is_dir($root.$entry))
{
$this->loopDir($d->path.$entry."/");
}
else
{
$getarr[] = $d->path.$entry;
}
}
}
$d->close();
Return $getarr;
}

/**
* 函数名称: getPhpFiles($path)
* 函数功能: 提取php文档
* 输入参数: $path ---------------- 文档路径
* 函数返回值: bool
* 其它说明: 2004-10-13
*/
function getPhpFiles($path)
{
$type = preg_replace('/.*\.(.*[^\.].*)/i','\\1',$path);
$type = strtolower($type);
if($type=="php")
{
Return true;
}
else
{
Return false;
}
}

/**
* 函数名称: getContent($path)
* 函